承接 webfiori/log 相关项目开发

从需求分析到上线部署,全程专人跟进,保证项目质量与交付效率

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

webfiori/log

Composer 安装命令:

composer require webfiori/log

包简介

A lightweight structured logging library for PHP.

README 文档

README

A lightweight structured logging library for PHP with daily file rotation and level filtering.

Supported PHP Versions

This library requires PHP 8.1 or higher.

Build Status

Features

  • Logger interface — swap implementations without changing application code
  • FileLogger — daily-rotated log files with structured format
  • Static facade (LoggerFacade) for quick usage without DI
  • Level filtering — set minimum level (debug, info, warning, error, critical)
  • Structured context — attach key-value metadata to log entries
  • Zero dependencies — requires only PHP 8.1+

Installation

composer require webfiori/log

Usage

Basic Logging

use WebFiori\Log\FileLogger;
use WebFiori\Log\LogLevel;

$logger = new FileLogger('/var/log/myapp', LogLevel::INFO);

$logger->info('User logged in', ['user_id' => 42, 'ip' => '192.168.1.1']);
$logger->error('Payment failed', ['order_id' => 123, 'reason' => 'timeout']);
$logger->debug('This will be filtered out'); // below INFO threshold

Output (/var/log/myapp/app-2026-05-29.log):

[2026-05-29 01:00:00] [INFO] User logged in {"user_id":42,"ip":"192.168.1.1"}
[2026-05-29 01:00:00] [ERROR] Payment failed {"order_id":123,"reason":"timeout"}

Static Facade

use WebFiori\Log\LoggerFacade;

LoggerFacade::info('Application started');
LoggerFacade::error('Something went wrong', ['exception' => $e->getMessage()]);

Custom Logger Implementation

use WebFiori\Log\Logger;

class DatabaseLogger implements Logger {
    public function debug(string $message, array $context = []): void { /* ... */ }
    public function info(string $message, array $context = []): void { /* ... */ }
    public function warning(string $message, array $context = []): void { /* ... */ }
    public function error(string $message, array $context = []): void { /* ... */ }
    public function critical(string $message, array $context = []): void { /* ... */ }
    public function log(string $level, string $message, array $context = []): void { /* ... */ }
}

LoggerFacade::setInstance(new DatabaseLogger());

API

Logger (interface)

Method Description
debug(string $message, array $context = []) Log debug message
info(string $message, array $context = []) Log informational message
warning(string $message, array $context = []) Log warning message
error(string $message, array $context = []) Log error message
critical(string $message, array $context = []) Log critical message
log(string $level, string $message, array $context = []) Log at specified level

FileLogger

Method Description
__construct(string $logDir, string $minLevel = 'debug') Create logger with directory and minimum level
getLogDir(): string Returns the log directory path
getMinLevel(): string Returns the current minimum level
setMinLevel(string $level): void Change the minimum level at runtime

LogLevel

Constant Value
LogLevel::DEBUG 'debug'
LogLevel::INFO 'info'
LogLevel::WARNING 'warning'
LogLevel::ERROR 'error'
LogLevel::CRITICAL 'critical'

LoggerFacade

Method Description
getInstance(): Logger Get the default logger
setInstance(Logger $logger): void Replace the default logger
reset(): void Destroy the default instance
All Logger methods Delegates to the default instance

License

MIT

统计信息

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

GitHub 信息

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

其他信息

  • 授权协议: MIT
  • 更新时间: 2026-05-29

承接程序开发

PHP开发

VUE

Vue开发

前端开发

小程序开发

公众号开发

系统定制

数据库设计

云部署

网站建设

安全加固