themosis/log 问题修复 & 功能扩展

解决BUG、新增功能、兼容多环境部署,快速响应你的开发需求

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

themosis/log

Composer 安装命令:

composer require themosis/log

包简介

The Themosis log component.

README 文档

README

Themosis Log

The Themosis log component is a lightweight logging library for PHP.

The component is only promoting the PSR-3 interface and provides a simple repository interface and concrete in-memory implementation to manage PSR-3 compatible loggers.

By default, the library is not installing any logger implementation but is suggesting the usage of the popular Monolog package.

Feel free to install any PSR-3 compatible logger alongside the library.

Installation

Examples below are leveraging the usage of the Monolog library.

Install the package using Composer and add you preferred logging library implementation:

composer require themosis/log monolog/monolog

The above code is going to install the themosis/log package as well as the monolog/monolog one.

Usage

Register a logger

You can register a logger using the in-memory repository. Each logger must have a unique channel name.

use Themosis\Components\Log\Channel;
use Themosis\Components\Log\InMemoryLoggers;

// Create a logger instance using any PSR-3 library
$channel = new Channel('APP');
$logger = new Monolog\Logger($channel);

// Register the logger in the registry
$loggers = new InMemoryLoggers();
$loggers->add($channel, $logger);

The channel class provided a unique identifier for the associated logger.

A logger can not be overwritten in the repository and will throw a LoggerAlreadyExists exception if you try to do so.

Retrieve a logger

You can get back a registered logger by passing the channel identifier like so:

$applicationLogger = $loggers->get(new Channel('APP'));

// Log something using the PSR-3 retrieved logger...
$applicationLogger->info('An applicaton event just occured...');

The repository will throw a LoggerNotFound exception if the logger is not registered and you're trying to retrieve it.

If you intend to always expect a logger to be returned from the repository even if not registered, you can simply create your own repository by using the Themosis\Components\Log\Loggers interface.

统计信息

  • 总下载量: 4
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 1
  • 点击次数: 0
  • 依赖项目数: 0
  • 推荐数: 1

GitHub 信息

  • Stars: 1
  • Watchers: 1
  • Forks: 0
  • 开发语言: PHP

其他信息

  • 授权协议: GPL-3.0-or-later
  • 更新时间: 2024-06-23