Git Product home page Git Product logo

logging's Introduction

Latest Stable Version Build Status Coverage Status License

Logging

A simple file-based PSR-3 logging library.

  • provides basic severity level filtering
  • can be used as a singleton
    • also with multiple logs
  • able to serialize arrays and objects (first tries with __toString(), then applies json_encode())
  • supports placeholders (see PSR-3)
  • compatible with all PSR-3 releases from 1 on

Installation

composer require zozlak/logging

Usage

// simplest possible logging
$log = new \zozlak\logging\Log('log_file');
$log->info('message');

// logging to standard out/err
$log = new \zozlak\logging\Log('php://stdout');
$log->info('message');
$log = new \zozlak\logging\Log('php://stderr');
$log->info('message');

// message formatting and filtering
$log = new \zozlak\logging\Log('log_file', \Psr\Log\LogLevel::INFO, "{LEVEL}:{TIMESTAMP}:{FILE}:{LINE}:{MESSAGE}");
$log->info('message');
$log->debug('skipped message');

// singleton example
$log = new \zozlak\logging\Log('log_file');
\zozlak\logging\Logger::addLog($log);
\zozlak\logging\Logger::info('message');

// singleton with multiple logs
$logAll = new \zozlak\logging\Log('log_all');
$logErrors = new \zozlak\logging\Log('log_errors', \Psr\Log\LogLevel::ERROR);
\zozlak\logging\Logger::addLog($logAll, 'all');
\zozlak\logging\Logger::addLog($logErrors, 'error');

\zozlak\logging\Logger::info('message1', [], 'all');
\zozlak\logging\Logger::error('message2', [], 'error');
\zozlak\logging\Logger::error('message3'); // written to the 'error' log

\zozlak\logging\Logger::setDefaultLog('all');
\zozlak\logging\Logger::error('message4'); // written to the 'all' log

logging's People

Contributors

zozlak avatar

Stargazers

 avatar

Watchers

 avatar  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.