GithubHelp home page GithubHelp logo

isabella232 / log-14 Goto Github PK

View Code? Open in Web Editor NEW

This project forked from cakephp/log

0.0 0.0 0.0 16.69 MB

[READ-ONLY] Logging library with support for multiple different streams. This repo is a split of the main code that can be found in https://github.com/cakephp/cakephp

License: Other

PHP 100.00%

log-14's Introduction

Total Downloads License

CakePHP Logging Library

The Log library provides a Log service locator for interfacing with multiple logging backends using a simple interface. With the Log class it is possible to send a single message to multiple logging backends at the same time or just a subset of them based on the log level or context.

By default, you can use Files or Syslog as logging backends, but you can use any object implementing Psr\Log\LoggerInterface as an engine for the Log class.

Usage

You can define as many or as few loggers as your application needs. Loggers should be configured using Cake\Core\Log. An example would be:

use Cake\Cache\Cache;

use Cake\Log\Log;

// Short classname
Log::config('local', [
    'className' => 'FileLog',
    'levels' => ['notice', 'info', 'debug'],
    'file' => '/path/to/file.log',
]);

// Fully namespaced name.
Log::config('production', [
    'className' => \Cake\Log\Engine\SyslogLog::class,
    'levels' => ['warning', 'error', 'critical', 'alert', 'emergency'],
]);

It is also possible to create loggers by providing a closure.

Log::config('special', function () {
	// Return any PSR-3 compatible logger
	return new MyPSR3CompatibleLogger();
});

Or by injecting an instance directly:

Log::config('special', new MyPSR3CompatibleLogger());

You can then use the Log class to pass messages to the logging backends:

Log::write('debug', 'Something did not work');

Only the logging engines subscribed to the log level you are writing to will get the message passed. In the example above, only the 'local' engine will get the log message.

Filtering messages with scopes

The Log library supports another level of message filtering. By using scopes, you can limit the logging engines that receive a particular message.

// Configure /logs/payments.log to receive all levels, but only
// those with `payments` scope.
Log::config('payments', [
    'className' => 'FileLog',
    'levels' => ['error', 'info', 'warning'],
    'scopes' => ['payments'],
    'file' => '/logs/payments.log',
]);

Log::warning('this gets written only to payments.log', ['scope' => ['payments']]);

Documentation

Please make sure you check the official documentation

log-14's People

Contributors

admad avatar markstory avatar lorenzo avatar dereuromark avatar ravage84 avatar ad7six avatar bcrowe avatar josegonzalez avatar othercorey avatar mtak3 avatar mehdi-fathi avatar antograssiot avatar jzdunek avatar bravo-kernel avatar bgehrels avatar wyrihaximus avatar tuffz avatar jrbasso avatar tenkoma avatar renan avatar theaxiom avatar

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.