contaoblackforest / contao-logger
Contao开源CMS的PSR-3日志桥接器
Requires
- php: >=5.3
- contao-community-alliance/composer-plugin: ~2.0
- contao-community-alliance/dependency-container: ~1.0
- contao/core: >=2.11.11,<4-dev
- monolog/monolog: ~1.5
- psr/log: ~1.0
Requires (Dev)
- contao-community-alliance/build-system: ~1.0@dev
- contao-community-alliance/build-system-logger: @dev
- contao-community-alliance/build-system-repository-git: ~1.0@dev
- contao-community-alliance/build-system-tool-branch-alias-validation: ~1.0
- contao-community-alliance/build-system-tool-travis-configuration-check: ~1.0@dev
- contao-community-alliance/coding-standard: ~1.0@dev
- pdepend/pdepend: 2.0.*
- phploc/phploc: ~2.0
- phpmd/phpmd: ~2.0
- phpunit/phpunit: ~3.7
- sebastian/phpcpd: ~1.4
- squizlabs/php_codesniffer: ~1.0
Replaces
- bit3/contao-logger: 2.0.1
This package is auto-updated.
Last update: 2022-11-23 05:15:20 UTC
README
Contao开源CMS的日志桥接器
该桥接器为 Contao开源CMS 提供PSR-3日志支持。日志通过 依赖注入容器 可用。
默认情况下,日志使用两个处理器。
- 一个contao syslog处理器,将日志条目写入系统日志数据库。
- 以及一个stream处理器,将日志条目写入
system/logs/contao.log
。
默认情况下,它使用 Monolog 作为实现,但它被设计为可以使用任何PSR-3兼容的日志实现替换。
访问和使用日志
global $container; /** @var \Psr\Log\LoggerInterface */ $logger = $container['logger']; $logger->emergency('Some extreme critical message');
日志配置
接收和更改默认日志级别
global $container; // receive default log level $level = $container['logger.default.level']; // change default log level $container['logger.default.level'] = \Psr\Log\LogLevel::WARNING;
定义默认日志处理器
默认日志处理器存储在 $container['logger.default.handlers']
中,包含一系列处理器服务。
global $container; // receive the default log handlers array (its an ArrayObject instance) $handlers = $container['logger.default.handlers']; // remove the contao syslog handler foreach ($handlers as $index => $serviceKey) { if ($serviceKey == 'logger.handler.contao') { unset($handlers[$index]); break; } } // add a custom handler $container['logger.handler.custom'] = function($container) { $factory = $container['logger.factory.handler.stream']; // store in /var/log/critical.log return $factory('/var/log/critical.log', \Psr\Log\LogLevel::CRITICAL); } $handlers->append('logger.handler.custom');
创建您自己的日志
global $container; // register a handler $container['logger.handler.custom'] = function($container) { $factory = $container['logger.factory.handler.stream']; // store in system/logs/critical.log return $factory('critical.log', \Monolog\Logger::CRITICAL); } // register your logger $container['logger.custom'] = function($container) { // using the logger factory $factory = $container['logger.factory']; $logger = $factory('contao', array('logger.handler.custom')); return $logger; }; // receive your logger $logger = $container['logger.custom'];
参考
服务
$container['logger.default.level']
(int
) 默认日志级别,默认: Psr\Log\LogLevel::INFO
$container['logger.default.level.contao']
(int
) 默认日志级别,继承自 $container['logger.default.level']
$container['logger.default.level.buffer']
(int
) 默认日志级别,继承自 $container['logger.default.level']
$container['logger.default.level.chromePhp']
(int
) 默认日志级别,继承自 $container['logger.default.level']
$container['logger.default.level.firePhp']
(int
) 默认日志级别,继承自 $container['logger.default.level']
$container['logger.default.level.rotatingFile']
(int
) 默认日志级别,继承自 $container['logger.default.level']
$container['logger.default.level.mail']
(int
) 默认日志级别,默认: Psr\Log\LogLevel::ERROR
$container['logger.default.level.stream']
(int
) 默认日志级别,继承自 $container['logger.default.level']
$container['logger.default.rotation']
(int
) 日志轮换的天数,默认:28
$container['logger.handler.contao']
(Monolog\Handler\HandlerInterface|Logger\ContaoHandler
) 默认的 contao 系统日志处理程序
$container['logger.handler.stream']
(Monolog\Handler\HandlerInterface|Monolog\Handler\RotatingFileHandler
) 默认的轮换日志文件处理程序(system/logs/contao-Y-m-d.log)
$container['logger.default.handlers']
(ArrayObject
) 默认日志处理程序列表
$container['logger']
(Psr\Log\LoggerInterface|Monolog\Logger
) 默认的日志记录器
工厂
$container['logger.factory.handler.contao']
/** * @param int $level The minimum logging level at which this handler will be triggered * @param bool $bubble Whether the messages that are handled can bubble up the stack or not * @param string $function The function name in the contao syslog (use channel name by default) * @param string $action The action name in the contao syslog (use simplified log level name by default) */ function($level = null, $bubble = true, $function = null, $action = null)
$container['logger.factory.handler.buffer']
/** * @param string|callable|Monolog\Handler\HandlerInterface $handler Service name, callable or handler object. * @param int $bufferSize How many entries should be buffered at most, beyond that the oldest items are removed from the buffer. * @param int $level The minimum logging level at which this handler will be triggered * @param bool $bubble Whether the messages that are handled can bubble up the stack or not * @param bool $flushOnOverflow If true, the buffer is flushed when the max size has been reached, by default oldest entries are discarded */ function function($handler, $bufferSize = 0, $level = null, $bubble = true, $flushOnOverflow = false)
$container['logger.factory.handler.chromePhp']
/** * @param int $level The minimum logging level at which this handler will be triggered * @param bool $bubble Whether the messages that are handled can bubble up the stack or not */ function function($level = null, $bubble = true)
$container['logger.factory.handler.fingersCrossed']
/** * @param string|callable|Monolog\Handler\HandlerInterface $handler Service name, callable or handler object. * @param int|ActivationStrategyInterface $activationStrategy The minimum logging level at which this handler will be triggered * @param int $bufferSize How many entries should be buffered at most, beyond that the oldest items are removed from the buffer. * @param bool $bubble Whether the messages that are handled can bubble up the stack or not * @param bool $stopBuffering Whether the handler should stop buffering after being triggered (default true) */ function function($handler, $activationStrategy = null, $bufferSize = 0, $bubble = true, $stopBuffering = true)
$container['logger.factory.handler.firePhp']
/** * @param int $level The minimum logging level at which this handler will be triggered * @param bool $bubble Whether the messages that are handled can bubble up the stack or not */ function function($level = null, $bubble = true)
$container['logger.factory.handler.group']
/** * @param array $handlers List of services, callbacks or handlers. * @param bool $bubble Whether the messages that are handled can bubble up the stack or not */ function function(array $handlers, $bubble = true)
$container['logger.factory.handler.rotatingFile']
/** * @param string $filename Absolute filename or single name (stored in system/logs/) * @param int $maxFiles The maximal amount of files to keep (0 means unlimited) * @param int $level The minimum logging level at which this handler will be triggered * @param bool $bubble Whether the messages that are handled can bubble up the stack or not */ function function($filename, $maxFiles = null, $level = null, $bubble = true)
$container['logger.factory.handler.mail']
/** * A handler using swift to send entries as emails. * * @param string $to The email recipient address * @param string $subject The email subject * @param string $from The email sender address * @param int $level The minimum logging level at which this handler will be triggered * @param bool $bubble Whether the messages that are handled can bubble up the stack or not */ function function($to = null, $subject = null, $from = null, $level = null, $bubble = true)
$container['logger.factory.handler.stream']
/** * @param string $uri Stream uri * @param int $level The minimum logging level at which this handler will be triggered * @param bool $bubble Whether the messages that are handled can bubble up the stack or not */ function function($uri, $level = null, $bubble = true)
$container['logger.factory']
/** * @param string $name The channel name * @param array $handlers List of services or handlers. */ function function($name, array $handlers = array())