2017 © Pedro Peláez
 

library channel-log

Support Laravel Log data to separate channel log files with config

image

nickfan/channel-log

Support Laravel Log data to separate channel log files with config

  • Friday, March 16, 2018
  • by nickfan
  • Repository
  • 1 Watchers
  • 8 Stars
  • 847 Installations
  • PHP
  • 0 Dependents
  • 0 Suggesters
  • 1 Forks
  • 0 Open issues
  • 2 Versions
  • 46 % Grown

The README.md

ChannelLog

README in Chinese | 中文说明, (*1)

Intro

Support Laravel Log data to separate channel log files with config., (*2)

this project base on ShQ's answer for laravel 5.2 custom log file for different tasks, (*3)

Install

  • install composer package
composer require "nickfan/channel-log:dev-master"
  • Edit config/app.php file, (*4)

    providers group add:, (*5)

    Nickfan\ChannelLog\ChannelLogServiceProvider::class,
    

    aliases group add:, (*6)

'ChannelLog' => Nickfan\ChannelLog\Facades\ChannelLog::class,
  • publish config file:
php artisan vendor:publish --provider="Nickfan\ChannelLog\ChannelLogServiceProvider"

Setup

return [
    'default' => [
        'path' => 'logs/default.log',
        'level' => \Monolog\Logger::DEBUG
    ],
//    'event' => [
//        'path' => 'logs/event.log',
//        'level' => \Monolog\Logger::INFO
//    ],
    'custom'=>[  // Channel Label Name
        'name'=>'custom',           // (optional) Channel Label Name
        'log'=>'daily',             // log mode support: console (only in stdout); single (single file); daily (daily files); syslog (syslog); errorlog (php errorlog);
        'console'=>true,            // output to stdout(console) at the sametime.
        'path'=>'logs/custom.log', // Log file path,relative path will convert to relative with storage_path(yourpath)
        'level' => \Monolog\Logger::DEBUG, // Log Level
        'log_syslog_name'=>'channel_log',   // syslog mode log entry name
        'log_max_files'=>5,                 // max files keep in daily log mode
        'formatter'=>\Nickfan\ChannelLog\ChannelLogJsonFormatter::class,           // (optional) Record Formatter Class Name
    ],
];


Custom Configurator

in a channel settings your could set your custom configurator by set a key name: configurator, (*7)

the Configurator Class Must implements Nickfan\ChannelLog\ChannelLogConfigurator interface, (*8)

you could write your own configurator reference Nickfan\ChannelLog\ChannelLogDefaultConfigurator the default configurator class, (*9)

config example:, (*10)

return [
    'myconsole' => [  // Channel Label Name
        'path' => 'logs/default.log', // Log file path,relative path will convert to relative with storage_path(yourpath)
        'level' => \Monolog\Logger::DEBUG // Log Level
        // set the configurator class name
        'configurator' => \App\Support\ChannelLogMyConsoleConfigurator::class
    ],

];

Laravel Usage


// Log to 'default' channel ChannelLog::channel('default')->info('my test message {mykey1}',['mykey1'=>'myval1','aaa'=>'abc']); // Log to 'event' channel ChannelLog::channel('event')->error('my event message {mykey2}',['mykey2'=>'myval2','qqq'=>'qwe']); // Log to 'mycustom' channel in daily log mode ,with filepath '/tmp/mycustom-2017-10-24.log' ChannelLog::daily('/tmp/mycustom.log')->debug('my custom message {mykey2}',['mykey2'=>'myval2','qqq'=>'qwe']); // Log to 'newdirect' channel in single log mode ,with filepath '/tmp/newdirect.log' , also log to console(stdout) ChannelLog::direct([ 'name'=>'newdirect',// Channel Label Name 'console'=>true, // output to console(stdout) 'path'=>'/tmp/newdirect.log', // log filepath ])->debug('new direct message {mykey2}',['mykey2'=>'myval2','qqq'=>'qwe']);

Standalone Usage

use Nickfan\ChannelLog\ChannelLogWriterStandAlone;

$projectRoot = dirname(__DIR__);
$channelLogWriter = new ChannelLogWriterStandAlone(
  [
      'default'=>[
          'log' => 'single',
          'console'=> false,
          'path'=>$projectRoot.'/logs/default.log',
          'level'=>\Monolog\Logger::INFO,
      ],
      'event' => [
          'log' => 'daily',
          'console'=> true,
          'path' => $projectRoot.'/logs/event.log',
          'level' => \Monolog\Logger::DEBUG,
      ],
  ]
);

$channelLogWriter->channel('default')->info('my test message {mykey1}',['mykey1'=>'myval1','aaa'=>'abc']);


$result2 = $channelLogWriter->channel('event')->error('my event message {mykey2}',['mykey2'=>'myval2','qqq'=>'qwe']);


$result3 = $channelLogWriter->daily($projectRoot.'/logs/mycustom.log')->debug('my custom message {mykey2}',['mykey2'=>'myval2','qqq'=>'qwe']);


$result4 = $channelLogWriter->direct($projectRoot.'/logs/mydirect.log')->debug('my direct message {mykey2}',['mykey2'=>'myval2','qqq'=>'qwe']);


$result5 = $channelLogWriter->direct([
            'name'=>'newdirect',
            'console'=>true,
            'path'=>$projectRoot.'/logs/newdirect.log',
            ])->debug('new direct message {mykey2}',['mykey2'=>'myval2','qqq'=>'qwe']);

more detail usage reference monolog offical site https://github.com/Seldaek/monolog, (*11)

Support on Beerpay

Hey dude! Help me out for a couple of :beers:!, (*12)

Beerpay Beerpay, (*13)

The Versions

16/03 2018

dev-develop

dev-develop

Support Laravel Log data to separate channel log files with config

  Sources   Download

The Requires

 

The Development Requires

by nick fan

02/11 2017

dev-master

9999999-dev

Support Laravel Log data to separate channel log files with config

  Sources   Download

The Requires

 

The Development Requires

by nick fan