Skip to main content

Module log

Module log 

Source
Expand description

日志系统 — 对齐 PHP think-logger

§设计

  • 基于 sz-orm-loggerStructuredLogger 提供日志收集
  • 同时通过 tracing 宏输出(与 SZ-ORM-Tracing 协同,未来接入 OpenTelemetry)
  • 全局单例 LogFacade,通过 LogFacade::init() 初始化、LogFacade::instance() 获取
  • 支持多通道(file/console),对齐 PHP config/log.phpchannels 配置

§PHP 对齐

// PHP think-logger
Log::info('hello');
Log::error('error occurred', ['exception' => $e]);
Log::channel('file')->info('file log');
// SZ-Rust 等价
use sz_rust_core::log::LogFacade;
LogFacade::instance().unwrap().info("hello");
LogFacade::instance().unwrap().error("error occurred");

Structs§

ChannelRef
命名通道引用
LogConfig
Log 中间件配置
LogEntry
LogFacade
日志 facade — 持有默认 StructuredLogger 和命名通道
LoggerFactory
Factory that creates loggers with different configurations.
RequestId
请求 ID(注入到 request extensions,供下游 handler 和日志使用)
StructuredLogger

Enums§

LogLevel

Traits§

Logger

Functions§

format_request_log
格式化请求日志消息
generate_request_id
生成新的 RequestId
log_level_for_status
根据响应状态码返回日志级别
log_middleware
Log 中间件 — 请求/响应日志
log_middleware_with_config
带配置的 Log 中间件
parse_level
从字符串解析日志级别