承接 sugarcraft/candy-log 相关项目开发

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

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

sugarcraft/candy-log

最新稳定版本:v0.2.0

Composer 安装命令:

composer require sugarcraft/candy-log

包简介

PHP port of charmbracelet/log — minimal, colorful leveled logging with structured human-readable output, text/JSON/logfmt formatters, and stdlog adapter.

README 文档

README

candy-log

CI codecov Packagist Version License PHP

CandyLog

PHP port of charmbracelet/log — a minimal, colorful leveled logging library.

Features

  • Leveled loggingDebug, Info, Warn, Error, Fatal levels
  • Colorful human-readable output — terminal-styled by default (TTY detection)
  • Multiple formattersTextFormatter (default), JSONFormatter, LogfmtFormatter
  • Structured key/value pairs — pass arbitrary context with every log call
  • Sub-loggersWith(...) creates a child logger with persistent fields
  • Customizable — prefix, timestamp format, report caller, styles
  • stdlog adapter — wrap in Log\StandardLogAdapter for *log.Logger interface compatibility

Install

composer require sugarcraft/candy-log

Quick Start

use SugarCraft\Log\Logger;
use SugarCraft\Log\Level;

$log = Logger::new();
$log->info('Starting oven', ['degree' => 375]);
$log->warn('Almost ready', ['batch' => 2]);
$log->error('Temperature too low', ['err' => 'underheated']);

Levels

Logger::debug('debug message');
Logger::info('info message');
Logger::warn('warn message');
Logger::error('error message');
Logger::fatal('fatal message'); // calls exit(1)
Logger::print('always prints');

Structured Fields

$log->info('Baking cookies', [
    'flour' => '2 cups',
    'butter' => true,
    'temp' => 375,
]);

// Child logger with persistent fields
$baker = $log->with(['user' => 'chef', 'session' => 'am']);
$baker->info('Batch started'); // also has user + session

Formatters

use SugarCraft\Log\Formatter\TextFormatter;
use SugarCraft\Log\Formatter\JsonFormatter;
use SugarCraft\Log\Formatter\LogfmtFormatter;

$log = Logger::new(formatter: new JsonFormatter());

Styling

Styles are applied automatically in TTY environments. Override via Logger::styles():

use SugarCraft\Sprinkles\Style;
$log = Logger::new();
$styles = $log->styles();
$styles->levels[Level::Error] = Style::new()->foreground('red')->bold();
$log->setStyles($styles);

License

MIT

统计信息

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

GitHub 信息

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

其他信息

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

承接程序开发

PHP开发

VUE

Vue开发

前端开发

小程序开发

公众号开发

系统定制

数据库设计

云部署

网站建设

安全加固