Overview

Namespaces

  • CzProject
    • Logger

Classes

  • CzProject\Logger\CliLogger
  • CzProject\Logger\FileLogger
  • CzProject\Logger\MemoryLogger
  • CzProject\Logger\MultiLogger
  • CzProject\Logger\OutputLogger

Interfaces

  • CzProject\Logger\ILogger
  • Overview
  • Namespace
  • Class
 1:  2:  3:  4:  5:  6:  7:  8:  9: 10: 11: 12: 13: 14: 15: 16: 17: 18: 19: 20: 21: 22: 23: 24: 25: 26: 27: 28: 29: 30: 31: 32: 33: 34: 35: 36: 37: 38: 39: 40: 41: 42: 43: 44: 45: 46: 47: 48: 49: 50: 51: 52: 53: 54: 55: 56: 57: 58: 59: 60: 
<?php

    namespace CzProject\Logger;


    class CliLogger implements ILogger
    {
        /** @var int */
        private $level;

        /** @var bool */
        private $colored;

        /** @var array */
        protected static $colors = array(
            ILogger::SUCCESS => '0;32',
            ILogger::ERROR => '0;31',
            ILogger::EXCEPTION => '0;31',
            ILogger::CRITICAL => '0;31',
            ILogger::WARNING => '0;33',
            ILogger::DEBUG => '1;30',
        );


        /**
         * @param  int
         */
        public function __construct($level = ILogger::INFO, $colored = NULL)
        {
            $this->level = $level;
            $this->colored = $colored !== NULL ? $colored : self::detectColoredOutput();
        }


        public function log($msg, $level = ILogger::INFO)
        {
            if ($level >= $this->level) {
                if ($this->colored && isset(self::$colors[$level])) {
                    echo "\033[", self::$colors[$level], 'm', $msg, "\033[0m\n";

                } else {
                    echo $msg, "\n";
                }
            }
        }


        /**
         * @return  bool
         */
        public static function detectColoredOutput()
        {
            // Code from Tracy (from Nette Framework)
            // see https://github.com/nette/tracy/blob/master/src/Tracy/Dumper.php#L315-L317
            return (getenv('ConEmuANSI') === 'ON'
                || getenv('ANSICON') !== FALSE
                || (defined('STDOUT') && function_exists('posix_isatty') && posix_isatty(STDOUT)));
        }
    }
czproject/logger master API documentation API documentation generated by ApiGen