承接 moddix/wp-logger 相关项目开发

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

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

moddix/wp-logger

最新稳定版本:1.0.0

Composer 安装命令:

composer require moddix/wp-logger

包简介

Simple WP Logger

README 文档

README

A simple logging library for WordPress projects using the Bedrock structure. This library allows you to log messages to a specified log file, streams and others, like in same on Monolog.

Library register set_error_handler, set_exception_handler and register_shutdown_function to log errors, exceptions and fatal errors.

Installation

Install the latest version with

composer require moddix/wp-logger

Usage

  1. Create a file in the mu-plugins directory of your Bedrock project (e.g., wp-logger.php) and include the following code:
use Moddix\WpLogger\Configurator;
use Moddix\WpLogger\WpLogger;
use Monolog\Handler\StreamHandler;
use Monolog\Level;
use Monolog\Formatter\JsonFormatter;

// Create a Configurator instance
$configurator = new Configurator();

// Example: Set handler to output logs to stdout in JSON format
$handler = new StreamHandler('php://stdout', Level::Debug);
$handler->setFormatter(new JsonFormatter(JsonFormatter::BATCH_MODE_NEWLINES, true));

// push the handler to the configurator
$configurator->pushHandler($handler);

// Example: Add a processor to add extra data to each log record
$configurator->pushProcessor(function ($record) {
    $record->extra['dummy'] = 'Hello world!';

    return $record;
});

// Example: Add a subscriber to log wp_die events, see HookSubscribersInterface for more options
$configurator->addSubscriberClasses([
    Moddix\WpLogger\HookSubscribers\WpDieSubscriber::class,
]);

// Boot the logger with the configurator
WpLogger::boot($configurator);
  1. Use the facade to log messages in your WordPress code:
\Moddix\WpLogger\Log::info('This is an info message.');
\Moddix\WpLogger\Log::warning('This is a warning message.');
\Moddix\WpLogger\Log::error('This is an error message.');

\Moddix\WpLogger\Log::debug('This is a debug message with context.', ['key' => 'value']);

\Moddix\WpLogger\Log::log('info', 'This is a log message with dynamic level.', ['key' => 'value']);

统计信息

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

GitHub 信息

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

其他信息

  • 授权协议: MIT
  • 更新时间: 2025-10-15