imafaz / easylog
轻量级PHP日志库,允许开发者轻松地以不同级别(如调试、信息、警告、错误和致命)记录消息。
1.0.0
2023-10-28 12:12 UTC
Requires
- php-64bit: >=7.0
README
轻量级PHP日志库,允许开发者轻松地以不同级别(如调试、信息、警告、错误和致命)记录消息。
要求
此库支持PHP版本7.0或更高版本
安装
安装此扩展的首选方式是通过Composer。
要安装Easylog,请按照以下步骤操作
$ composer require imafaz/EasyLog
您也可以使用Git 克隆整个仓库
$ git clone https://github.com/imafaz/EasyLog.git
或者 手动安装它
$ wget https://raw.githubusercontent.com/imafaz/EasyLog/main/src/Logger.php
快速开始
要使用此库与Composer
require __DIR__ . '/vendor/autoload.php'; use EasyLog\Logger;
如果您已经手动安装,请使用它
require_once __DIR__ . '/Logger.php'; use EasyLog\Logger;
用法
创建Logger实例
$logger = new Logger('/path/to/file.log');
使用以下方法以不同级别记录日志消息
// debug message: $logger->debug('This is a debug message.'); // info message: $logger->info('This is an informational message.'); // warning message: $logger->warning('This is a warning message.'); // error message: $logger->error('This is an error message.'); // fatal exception: $logger->fatal('This is a fatal message.');
默认情况下,日志消息将被写入指定的文件。如果您还想在屏幕上打印消息,可以在创建日志实例时将第二个参数作为true传递
$logger = new Logger('/path/to/file.log', true);
您可以在需要时更改logFile或printLog
$logger->printLog = true; $logger->logFile = 'custom.log';
许可证
- 此脚本根据MIT许可证授权。