定制 xy2z/aclog 二次开发

按需修改功能、优化性能、对接业务系统,提供一站式技术支持

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

xy2z/aclog

Composer 安装命令:

composer require xy2z/aclog

包简介

Simple PHP file-logger with zero-dependencies

README 文档

README

AcLog is a simple, zero-dependency PHP package to log activity to files.

AcLog can be used to easily log actions such as cronjobs, emails, user activity, details about errors, etc.

🧡 Sponsored by Datsi.app - Your personal database.

Requirements

  • PHP 8.0+

Install

Add this to your existing project:

composer require xy2z/aclog

Basic Usage

use xy2z\AcLog\AcLog;

$aclog = new AcLog(__DIR__ . '/logs');
$aclog->log($var); // can be any type: object, array, string, int, etc.
$aclog->log($var, $foo, $bar, $etc); // as many arguments you want.

Set Options

$aclog = new AcLog(
    log_dir: __DIR__ . '/logs',
    log_date_format: false,
    include_trace: false,
    output_method: AcLog::VAR_DUMP,
    line_breaks_between_header: 4,
    // etc.
);

For more options see the constructor method of the AcLog.php file.

Static Class

It is also possible to use it as a static class, if you prefer.

use xy2z\AcLog\AcLogStatic;

AcLogStatic::setup(__DIR__ . '/logs');
AcLogStatic::log($var);

If you want to set options in the static class, you need to set them as an array.

AcLogStatic::setup([
    'log_dir' => __DIR__ . '/logs',
    'log_date_format' => false,
    'include_trace' => false,
    'output_method' => AcLog::VAR_DUMP,
    'line_breaks_between_header' => 4,
    // etc.
]);

Other than that, it should behave exactly the same as the AcLog class, and all public methods and properties are also available.

Static Alias

If you want a shorter name for the static class, you can alias it.

use xy2z\AcLog\AcLogStatic as acl;

acl::setup(__DIR__ . '/logs');
acl::log($var);

Log Callbacks

You can add callbacks that will be appended to each log() call, examples for this can be user information, request headers, etc. You can add as many callbacks you want.

$aclog = new AcLog($this->logdir);

$aclog->add_log_append_callback(function () {
    return 'callback-1.';
});

$aclog->add_log_append_callback(array('MyClass', 'myCallbackMethod'));

Tips

  • Consider to zip (7zip is best) the log files after a few days - it will save ALOT of diskspace.

Developing

Pull Requests are welcome, just make sure your code is tested, analysed and fixed - see below.

Remember to make tests for both classes: AcLog and AcLogStatic.

# Fix Coding Standards (php-cs-fixer)
composer fix

# Analyse code (phpstan)
composer analyse

# Test code (phpunit)
composer test

Todo

  • badges
  • Later: Method for getting options values
  • examples dir?

统计信息

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

GitHub 信息

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

其他信息

  • 授权协议: MIT
  • 更新时间: 2022-01-04

承接程序开发

PHP开发

VUE

Vue开发

前端开发

小程序开发

公众号开发

系统定制

数据库设计

云部署

网站建设

安全加固