Skip to content

Instantly share code, notes, and snippets.

@bayareawebpro
Last active October 9, 2017 07:16
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save bayareawebpro/a5b0f07d7969499dba972b3cd9842a42 to your computer and use it in GitHub Desktop.
Save bayareawebpro/a5b0f07d7969499dba972b3cd9842a42 to your computer and use it in GitHub Desktop.
<?php namespace App\Logs;
use Monolog\Formatter\LineFormatter;
use Monolog\Handler\FirePHPHandler;
use Monolog\Logger as Log;
use Monolog\Handler\StreamHandler;
//Example:
//Logger::write('info','Auth', 'User Logged In', $request->user()->getLoggerAttributes());
class Logger {
public static function write($level = 'info', $fileName, $message, $data = array()){
try{
$handler = new StreamHandler(storage_path('/logs/'.str_slug($fileName).'.log'), 100);
$handler->setFormatter(new LineFormatter("[%datetime%] %channel%.%level_name%: %message% %context%\n"));
$logger = new Log($fileName);
$logger->pushHandler($handler);
$logger->$level($message,$data);
}catch(\Exception $e){
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment