opxcore/log-interface

OpxCore 日志接口。

1.0.9 2021-02-04 16:16 UTC

This package is auto-updated.

Last update: 2024-09-05 00:03:18 UTC


README

Build Status Coverage Status Latest Stable Version Total Downloads License

这是 OpxCore 中使用的日志接口,以及构建 PSR-3 日志器的基本。

安装

composer require opxcore/log-interface

日志基本

LogException

OpxCore\Log\Exceptions\LogException::class 是任何日志异常的基础类。它扩展了 Psr\Log\InvalidArgumentException 以实现 PSR-3 兼容性,可以直接使用或作为任何日志异常的父类。

AbstractLogger

OpxCore\Log\AbstractLogger::class 是一个抽象类,实现了 Psr\Log\LoggerInterface 以实现 PSR-3 兼容性。

AbstractLogger 定义了几个在日志器中常用的方法

  • formatMessage(string $level, string $message, array $context = []): string 返回带有日志级别和时间的格式化插值消息。

  • interpolateMessage(string $message, array $context): string 将内容插值到消息中。参见 PSR-3-logger-interface 。如果上下文数组中存在 'exception' 键,并且其值为 Exception::class 的实例之一,则其堆栈跟踪将包含在日志消息中。

  • getTimestamp(): string 返回当前的 ISO8601 格式的日期和时间戳。

  • 日志级别缩写: emergency()alert()critical()error()warning()notice()info()debug()