Giter Site home page Giter Site logo

epiclog's Introduction

EpicLog

Advanced Monolog Configuration Management for Laravel projects.

Overview

If you prefer your logs to be separated into many different files based on log-level, then this package is for you.

The log facade Log:: by default, sends all log messages into a single file in the storage/logs directory.

After installing this package, the method Log::info() will now write those log messages to storage/logs/info.log and likewise Log::error() would write to storage/logs/error.log.

We create a log file in storage/logs for each log level as specified by RFC 5424.

Other cool features

Custom Log Files - You can create custom log files and easily write to them, so you can log very specific messages and not have them mixed in with the generic messages logged by the Log facade.

Send logs to stderr, stdout - There are simple configuration flags which will allow you to send all error level and above logs to stderr, and send all log levels to stdout.

Installation

Installation differs slightly, depending on your framework (Laravel or Lumen). Begin by adding this to your composer.json

"johnfischelli/epiclog": "dev-master"

Run composer update

Continue with the following steps, depending on your framework.

Laravel

  1. Add the Service Provider and Facade

    Open up your config/app.php file and make the following changes:

    • Add EpicLog\EpicLogServiceProvider::class to the providers array
    • Add 'EpicLog' => EpicLog\EpicLogFacade::class to the aliases array
  2. Publish

    php artisan vendor:publish

  3. Configure

    Open config/epiclog.php and set whatever configuration options you like.

Lumen

  1. Add the Service Provider and Facade

    Open up your bootstrap/app.php file and add the following lines of code:

    // Add to Providers section
    $app->register(EpicLog\EpicLogServiceProvider::class);
    
    // Add after Providers section
    if (!class_exists('EpicLog')) {
        class_alias(EpicLog\EpicLogFacade::class, 'EpicLog');
    }
  1. Publish

    Manually copy the EpicLog config file epiclog.php from the vendor source to your Lumen config directory.

    Additionally, because Lumen uses .env file for storing configuration, you will need to manually load the EpicLog config. Add the following to bootstrap/app.php anywhere after $app is created. For example:

    $app = new Laravel\Lumen\Application(
        realpath(__DIR__.'/../')
    );

    // ADD THIS
    $app->instance('path.config', app()->basePath() . DIRECTORY_SEPARATOR . 'config');
    $app->configure('epiclog');
  1. Configure

    Open config/epiclog.php and set whatever configuration options you like.

Configuration

####separate_logs_by_level

If this flag is true, we alter the Laravel default Monolog config so that each log level is written to its own file. If it is false, the default Laravel Monolog config is untouched.


####rotate_log_by_level

If this flag is true, we'll setup a RotatingFileHandler instead of a default StreamHandler for each of our logs.

NOTE: This only applies if the separate_logs_by_level parameter is also true. This also, only applies to the logs separated by level.


####rotate_log_by_level_num_days

Specify the number of days of logs to keep for the log level files.

NOTE: If rotate_log_by_level is false, it doesn't matter what you put here - all logs will be kept indefinitely.


####push_errors_to_stderr

Set this flag to true, if you'd like to push error level and above logs to stderr. This can be especially useful if you run a docker environment.


####push_logs_to_stdout

Set this flag to true, if you'd like to push all logs to stdout. This is especially useful if you run a docker environment.

--

####logs

You can configure custom log files here. We're expecting an array of arrays. Here is an example:

	'logs' => [
		[
			'name' => 'myCustomLog',
			'location' => storage_path("logs/myCustomLog.log"),			'level' => 'error',
			'rotate' => true,
			'num_days' => 3,
			'bubbles' => true
		],
		[...]
	]

The name parameter is really the only required field in this custom log array. All the other values will be filled in with defaults if not provided. Here are the defaults:

	[
		'location' => storage_path("logs/epiclog.log"),
		'level' => 'debug',
     	'rotate' => false, 
		'num_days' => 5,
		'bubbles' => false
	]

The 'bubbles' parameter determines whether or not records handled by this logger will propogate to other handlers.

Writing to Custom Logs

In order to write to that custom Log file, we can't use the Log facade, so we provide an Epiclog facade. Since you gave this log the name of 'myCustomLog' it can be accessed like so: Epiclog::myCustomLog('data to log');

epiclog's People

Contributors

johnfischelli avatar maclonghorn avatar mabon avatar

Watchers

 avatar ayip avatar

Forkers

mabon

epiclog's Issues

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.