承接 devnav2902/utilitylog 相关项目开发

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

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

devnav2902/utilitylog

最新稳定版本:1.0.1

Composer 安装命令:

composer require devnav2902/utilitylog

包简介

Write a custom message in log

README 文档

README

This package help you write a custom log message, customize based on LineFormatter - Monolog

Installation

Install the latest version with command:

composer require devnav2902/utilitylog

Basic Usage

UtilityLog::writeLog('error', 'Foo');
UtilityLog::writeLog('info', 'Bar');

// in try-catch block
try {
     throw new \Exception('Something happened!');
} catch (\Throwable $th) {
     UtilityLog::writeLog('error', 'Error in try-catch block', $th);
}

// contextual information
UtilityLog::writeLog('info', 'User {id} failed to login.', null, ['id' => $user->id]);

Documentation

Usage Instructions

This package use LineFormatter (Monolog), so you can set a custom format like this:

"[%channel%][%level_name%] %datetime%\n%message% %extra%\n\n"

You can modify in config file, here is default config:

<?php

return [
    'customize_formatter' => "[%channel%][%level_name%] %datetime%\n%message% %extra%\n\n",
    'date_format' => 'Y-m-d H:i:s',
    'message_json_option' => JSON_PRETTY_PRINT,
    'allow_inline_linebreaks' => true,
    'ignore_empty_context_and_extra' => true,
    'include_stacktraces' => false
];

This use for params of LineFormatter:

class CustomizeFormatter
{
    /**
     * Customize the given logger instance.
     */
    public function __invoke(Logger $logger): void
    {
        foreach ($logger->getHandlers() as $handler) {
            $lineFormatter = new LineFormatter(
                config('utilitylog.customize_formatter'),
                config('utilitylog.date_format'),
                config('utilitylog.allow_inline_linebreaks'),
                config('utilitylog.ignore_empty_context_and_extra'),
                config('utilitylog.include_stacktraces')
            );
            
            $handler->setFormatter($lineFormatter);
        }
    }
}

✍️ If you want to change default of config, you can use a command:

php artisan vendor:publish --tag=utilitylog-config

This will copy file from package to your laravel project folder config\utilitylog.php.

✍️ You can view log file in storage\logs by go to url: /view-log or /view-log?date=Y-m-d with Y-m-d is date format, example: 2024-05-01, this will open file: laravel-2024-05-01.log.

You can customize view by publish view use this command:

php artisan vendor:publish --tag=utilitylog-views

About

Requirements

This package works with PHP 8.1 or above.

License

Utilitylog is licensed under the MIT License - see the LICENSE file for details

统计信息

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

GitHub 信息

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

其他信息

  • 授权协议: MIT
  • 更新时间: 2024-05-01