承接 bufferpunk/logmachine 相关项目开发

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

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

bufferpunk/logmachine

Composer 安装命令:

composer require bufferpunk/logmachine

包简介

Logmachine is a collaborative and visually elegant logging tool designed to make logging smarter and more efficient for distributed development teams. It offers a fully pluggable architecture that supports features like color-coded output for better readability, automatic JSON parsing, structured lo

README 文档

README

A powerful structured logging package for PHP applications. It provides colored console output, structured log formatting, and optional log forwarding via HTTP or WebSockets to a remote LogMachine server.

Why LogMachine?

If you’ve used plain error_log() or even Monolog, you know logs can quickly become hard to scan, messy to parse, and painful to centralize. LogMachine solves this with:

Feature Why it matters
Color-coded CLI logs Spot warnings and errors instantly in your terminal.
Structured JSON output Easy to pipe into ELK, Loki, or any log processor.
Remote forwarding Ship logs to your log server without extra setup.
Automatic context enrichment No more boilerplate for user and module.
PSR-friendly Works standalone or integrates with Monolog.
Small footprint No heavy dependencies — drop it in and go.

CLI Output Example (colored):

[2025-08-08 14:32:00 UTC] [DEBUG] Debug message
➢ Log provided by: username@room
[2025-08-08 14:32:01 UTC] [INFO]  User logged in  {"user":"jdoe"}
➢ Log provided by: username@room
[2025-08-08 14:32:02 UTC] [WARNING] API rate limit approaching
➢ Log provided by: username@room
[2025-08-08 14:32:03 UTC] [ERROR]  	Database connection failed  {"host":"localhost"}
➢ Log provided by: username@room

Compatibility

This package is compatible with PHP v8.3.6 and above

📦 Installation

Install via Composer:

composer require bufferpunk/logmachine

or

composer require bufferpunk/logmachine dev-main

or

composer require bufferpunk/logmachine dev-main --ignore-platform-req=ext-mbstring

: Additional steps (Important)
  • create config directory
mkdir config
  • create a config file
touch config/logmachine.php
  • copy paste this to your logmachine.php file, then save:
<?php

return [

    'log_file' => __DIR__ . '/logs/all_logs.log',
    'error_file' => __DIR__ . '/logs/error_logs.log',
    'transport_error_file' => __DIR__ . '/logs/transport-error.log',

    /*
    |--------------------------------------------------------------------------
    | Local Logger Settings
    |--------------------------------------------------------------------------
    | Control how logs are displayed locally in your app (console/file).
    | - "color" => true enables colored log output
    | - "emoji" => true adds emojis per log level
    */
    'local' => [
        'color' => true,
        'emoji' => true,
    ],

    /*
    |--------------------------------------------------------------------------
    | Central Logging Settings
    |--------------------------------------------------------------------------
    | Configure remote log forwarding.
    |
    | - "http_enabled": Set to true to enable HTTP log transport
    | - "url": Central logging server URL (required if http_enabled is true)
    | - "room": Logical room/channel for your logs.
    |   If omitted, LogMachine will auto-generate a unique name.
    | - "user": You can uncomment this section and add your user name
    | - "module": You can edit this to the name of the project yo working on,
    |   The name or your org or anything meaningful.
    | - "headers": Optional extra headers (e.g. auth token)
    | - "timeout" / "connect_timeout": Network timeouts in seconds
    | - "verify_ssl": Whether to validate SSL certificates
    */
    'central' => [
        'url'             => 'https://logmachine.org', // default
		'default_format' => true, // you can change this to false

        /** HTTP transport **/
        'http_enabled' => false, // set to true to send logs via HTTP POST

        /** WebSocket / Socket.IO transport **/
        'websocket_enabled' => false, // set to true to stream logs over Socket.IO
        'socketio_path' => 'api/socket.io', // Socket.IO server path (default)

        'room'            => null,    // can edit: You can add your room name here.
        //'user' => 'Test-user', // can edit: change to your user name (optional but a plus)
        //'module' => 'logmachine-php', // can edit: your module (optional but a plus)
		/**
			don't add your api key here; instead, add it to a .env file with the name
			lm_auth_token, or if you do, add this file to a .gitignore file.
		**/
		'auth' => 'your-optional-token',
        'headers' => [], // extra headers for the WebSocket handshake / HTTP requests
        'timeout'         => 30,
        'connect_timeout' => 10,
        'verify_ssl'      => true,
        'user_agent'      => 'LogMachine-Client/1.0',
    ],

];

🚀 Basic Usage

<?php

require __DIR__ . '/vendor/autoload.php';

use Bufferpunk\Logmachine\LogMachine;

// Load config (example: config/logmachine.php)
$config = require __DIR__ . '/config/logmachine.php';

// Create logger instance
$logger = LogMachine::create($config);

// Log messages
$logger->debug('Debug message');
$logger->info('User logged in', ['user' => 'jdoe']);
$logger->warning('API rate limit approaching');
$logger->error('Database connection failed', ['host' => 'localhost']);
$logger->success('Operation completed successfully!');

Configuration

You can pass the following configuration array when creating the Logger. LogMachine::create($config):

Option Type Default Description
channel string logmachine Logger channel name
level int DEBUG Minimum log level to output (Monolog levels supported)
log_file string null Path to general log file
error_file string null Path to error-only log file
transport_error_file string null Path for transport error logs (e.g., HTTP failures)
http_retries int 2 Retries for failed HTTP requests
http_retry_delay int 1 second Delay between HTTP retries
central array null Remote log forwarding config (see below)
enable_websocket bool false Enable WebSocket transport (not yet implemented)

Log Levels

LogMachine supports these log levels

Level Description
Debug Detailed debug info
Info General application events
Notice Normal but significant conditions
Warning Warnings that require attention
Error Runtime errors
Critical Critical conditions
Alert Immediate action required
Emergency System unusable
  • Additionally, ColorLogger provides extra methods like:

    $logger->success("Task completed!");

📡 Remote Forwarding (Central Logging)

To forward logs to a central log server, configure the central key:

'central' => [
    'room'   => 'my_app_room',   // optional, see note below
    'user'   => 'rezzcode',      // optional
    'module' => 'backend_api',   // optional
],

Note

If no transport is provided, logs are written locally only.

Room Naming Rule

If room is not provided, LogMachine will automatically generate one:

<user>_<module><random_number>

Example: rezzcode_backend23

  • This ensures every client has a unique room name, even if they skip configuration.

stracture

logmachine-php/
├── LICENSE
├── README.md
├── compos_install.sh
├── composer.json
├── src
│   ├── ColorLogger.php
│   ├── Formatters
│   │   ├── ColoredLineFormatter.php
│   │   └── PlainLineFormatter.php
│   ├── LogMachine.php
│   ├── Traits
│   │   └── ColorfulLoggerTrait.php
│   └── Transports
│       ├── HttpTransport.php
│       └── WebSocketTransport.php
├── public/
│   └── index.php (demo/test endpoint)
├── config/
│   └── logmachine.php
└── test

bufferpunk/logmachine 适用场景与选型建议

bufferpunk/logmachine 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 1 次下载、GitHub Stars 达 1, 最近一次更新时间为 2026 年 04 月 02 日, 在 PHP 生态内属于活跃度较高的组件。

我们在过去多个企业项目中使用过 bufferpunk/logmachine 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。

围绕 bufferpunk/logmachine 我们能提供哪些服务?
定制开发 / 二次开发

基于 bufferpunk/logmachine 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。

BUG 修复 & 性能优化

线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。

项目外包 & 长期维护

承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。

yvsm@zunyunkeji.com QQ:316430983 微信:yvsm316 西安尊云信息科技 · 专注 PHP / Go / 分布式系统研发

统计信息

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

GitHub 信息

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

其他信息

  • 授权协议: MIT
  • 更新时间: 2026-04-02