phasty / log

此包的最新版本(0.1)没有提供许可证信息。

PHP 日志库

0.1 2014-07-24 08:04 UTC

This package is not auto-updated.

Last update: 2024-09-24 01:25:27 UTC


README

Phasty\Log\File 类提供了将日志写入文件的能力。

如果在生产中需要记录大量数据,可能会很快遇到读取日志的问题。

第一个问题是通常日志文件增长迅速,使用less等工具阅读这样的日志文件变得非常困难,因此导航此文件变得不切实际。

第二个问题是日志行应该包含足够的信息,以便做出解决问题的决策。

当前版本的日志类允许您根据需要按时间分割日志文件:按天、按小时或按分钟。日志文件会静默更改,您只需提供文件路径的掩码即可,如果默认值不是您想要的。默认为

log/%Y/%m/%d/%H/

在2014年3月10日下午3点,文件将在log/2014/03/10/15/目录下。默认文件名是"log",因此完整文件路径为log/2014/03/10/15/log.log。如果您想将不同类型的记录数据分别写入不同的文件,可以在配置时或在运行时更改默认文件名。

每条日志行都根据配置进行格式化,并可以自动在行标题中包含以下信息

Level of logging
PID of process
Exact time (microseconds to if needed)
Used memory

日志消息可以由特殊的分隔符与日志标题分开,默认为"+-"。例如

[D 13762, 20:13.0250, 1048576 ] +-That is debug-level log message
[E 13762, 20:13.0261, 1048576 ] +-That is error-level log message

此外,默认情况下,每条日志行的标题都会根据其日志级别在文件中突出显示

用法

use Phasty\Log\File as log;

log::debug("This is debug message");
log::info("This is info message");
log::notice("This is notice message");
log::success("This is success message");
log::warning("This is warning message");
log::error("This is error message");

配置

config/log.php

<?php
return [
    "spacer" => "+-----",
    "header" => [
        "color"  => "brown",
        "format" => "[^PID, %H:%i:%s.^MCT]"
    ],
    "name" => "queue"
];

使用

use Phasty\Log\File as log;
log::config(require "config/log.php");
log::info("log message");