diff --git a/common.php b/common.php index 1122aed35..39923fcaa 100644 --- a/common.php +++ b/common.php @@ -42,6 +42,10 @@ $di->register(new \TorrentPier\ServiceProviders\ConfigServiceProvider, [ 'config.file.local.main' => __DIR__ . '/library/config.local.php', ]); +$di->register(new \TorrentPier\ServiceProviders\LogServiceProvider(), [ + 'config.log.handlers' => $di->config->log->handlers +]); + $di->register(new \TorrentPier\ServiceProviders\DbServiceProvider, [ 'config.db' => $di->config->db->toArray() ]); diff --git a/composer.json b/composer.json index 852468a90..345cb59a0 100644 --- a/composer.json +++ b/composer.json @@ -41,7 +41,8 @@ "zendframework/zend-loader": "^2.5", "zendframework/zend-mail": "^2.5", "zendframework/zend-session": "^2.5", - "zendframework/zend-version": "^2.5" + "zendframework/zend-version": "^2.5", + "monolog/monolog": "^1.18" }, "autoload": { "psr-4": { diff --git a/library/config.php b/library/config.php index 71b8026d0..ba8063d1d 100644 --- a/library/config.php +++ b/library/config.php @@ -62,6 +62,18 @@ $config = [ ] ], + // Log + 'log' => [ + 'handlers' => [ + function () { + return new \Monolog\Handler\StreamHandler( + __DIR__.'/../internal_data/log/app.log', + \Monolog\Logger::DEBUG + ); + } + ] + ], + // Aliases // TODO: удалить 'db_alias' => [ diff --git a/src/Log.php b/src/Log.php new file mode 100644 index 000000000..8e5b23c16 --- /dev/null +++ b/src/Log.php @@ -0,0 +1,147 @@ +log); + } + + return static::$logger; + } + + /** + * Adds a log record at an arbitrary level. + * + * @param mixed $level + * @param string $message + * @param array $context + * @return bool + */ + public static function log($level, $message, array $context = array()) + { + return static::getLogger()->log($level, $message, $context); + } + + /** + * Adds a log record at the DEBUG level. + * + * @param string $message + * @param array $context + * @return bool + */ + public static function debug($message, array $context = array()) + { + return static::getLogger()->debug($message, $context); + } + + /** + * Adds a log record at the INFO level. + * + * @param string $message + * @param array $context + * @return bool + */ + public static function info($message, array $context = array()) + { + return static::getLogger()->info($message, $context); + } + + /** + * Adds a log record at the NOTICE level. + * + * @param string $message + * @param array $context + * @return bool + */ + public static function notice($message, array $context = array()) + { + return static::getLogger()->notice($message, $context); + } + + /** + * Adds a log record at the WARNING level. + * + * @param string $message + * @param array $context + * @return bool + */ + public static function warning($message, array $context = array()) + { + return static::getLogger()->warning($message, $context); + } + + /** + * Adds a log record at the ERROR level. + * + * @param string $message + * @param array $context + * @return bool + */ + public static function error($message, array $context = array()) + { + return static::getLogger()->error($message, $context); + } + + /** + * Adds a log record at the CRITICAL level. + * + * @param string $message + * @param array $context + * @return bool + */ + public static function critical($message, array $context = array()) + { + return static::getLogger()->critical($message, $context); + } + + /** + * Adds a log record at the ALERT level. + * + * @param string $message + * @param array $context + * @return bool + */ + public static function alert($message, array $context = array()) + { + return static::getLogger()->alert($message, $context); + } + + /** + * Adds a log record at the EMERGENCY level. + * + * @param string $message + * @param array $context + * @return bool + */ + public static function emergency($message, array $context = array()) + { + return static::getLogger()->emergency($message, $context); + } +} diff --git a/src/ServiceProviders/LogServiceProvider.php b/src/ServiceProviders/LogServiceProvider.php new file mode 100644 index 000000000..bbc894d1b --- /dev/null +++ b/src/ServiceProviders/LogServiceProvider.php @@ -0,0 +1,36 @@ +pushHandler(call_user_func($logHandler)); + } + + return $logger; + }; + } +} diff --git a/styleguide.php b/styleguide.php index 951a010a2..eac200d3e 100644 --- a/styleguide.php +++ b/styleguide.php @@ -30,6 +30,12 @@ $db = $di->db; // }); //}); +///** @var \Monolog\Logger $log */ +//$log = $di->log; +//$log->debug('test debug information'); + +\TorrentPier\Log::info('You will see the style guide'); + $query = function(\Zend\Db\Sql\Select $select) { $select->columns(['id' => 'user_id', 'name' => 'username']); $select->join(['t' => BB_TOPICS], 't.topic_poster = u.user_id', ['title' => 'topic_title']);