desthercz/logger 问题修复 & 功能扩展

解决BUG、新增功能、兼容多环境部署,快速响应你的开发需求

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

desthercz/logger

最新稳定版本:v0.12.0

Composer 安装命令:

composer require desthercz/logger

包简介

Logging package for Laravel 5+

README 文档

README

#Logger

Logger complements or replaces standard Laravel logging. It logs to local files and optionally provides email alerts.

###Installation

Register the service provider:
DestherCZ\Logger\LoggerServiceProvider::class,

Add facade reference:
'Logger' => DestherCZ\Logger\LoggerFacade::class,

Configuration

Publish the configuration file with: php artisan vendor:publish --provider=DestherCZ\Logger\LoggerServiceProvider.

  • 'laravel' => true, captures Laravel log facade messages
  • 'folder' => 'custom' sets the default subfolder for custom logs
  • 'daily' => [] list of log files to be handled as daily logs
  • 'max_daily' => 7 maximum number of daily log files to keep
  • 'email.send' => false turns sending of error emails on/off
  • 'email.level' => 'ERROR' sets the level at which email notifications are sent
  • 'email.recipient' => 'recipient@example.com', sets the email recipient

Usage

Use the facade to write to custom log files. By default files are stored in storage/logs/custom:

Logger::info('auth', 'User login from 1.2.3.4');
Logger::warning('audit', 'A record was updated');
Logger::error('exceptions', 'Fatal exception: ');  

If you wish to store a logfile in a subfolder, use dot notation:

Logger::info('audit.auth', 'User login from 1.2.3.4'); // Logs to `storage/logs/custom/audit/auth.log`

A requestInfo() method is available to provide context for the message, including IP address, request type/URL, Auth::user()->id and input data

Logger::warning('audit', 'An unusual request', Logger::requestInfo());

Fatal errors occurring during the logging process, are stored in storage/logs/fatal-logger-errors.log. For example, a message will be logged here when the system is unable to send an error notification.

Hook into Laravel exceptions:

Make sure the logger.laravel configuration option is set to true, and update your error handler:

// app/Exceptions/Handler.php
use Logger;

public function report(Exception $e)
{
    $class = (new \ReflectionClass($e))->getShortName();
    Logger::error('exceptions', "Exception {$class} | {$e->getMessage()}", Logger::requestInfo());
    return parent::report($e);
}

Email alerts

Emails are only triggered if email sending is turned on, app.debug is false and the relevant error level meets the requirement. The Laravel mail system must be configured for emails to function.

Database handler

  • Add the table using php artisan logger:migration and php artisan migrate
  • Use the config file to set which channels should be logged to the database
  • You may now query the database using the Eloquent model DbEntry

Changelog

  • v0.6: Enable daily log files by configuration
    • Upgrade: add new config file entries: 'daily' => [], 'max_daily' => 7,
  • v0.5: Enable configuration of base folder and dot notation for subfolders
    • Upgrade: add new config file entry: 'folder' => 'custom',
  • v0.4: Add database handler.
    • Upgrade: add new config file entries. To log entries to the database, add and run the migration, then update config file settings accordingly.
  • v0.3: Remove Papertrail handler, use config file instead of .env, require PHP7.
    • Upgrade: publish and update the config file, make sure Papertrail handler is not required.

统计信息

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

GitHub 信息

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

其他信息

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