Git Product home page Git Product logo

php-context-logger's Introduction

Context Logger

Build Status Latest Stable Version Total Downloads Latest Unstable Version License

A PSR-3 compliant logger decorator which allows context metadata to be built up.

Installation

$ composer require tomphp/context-logger

Usage

<?php

use Monolog\Logger;
use Monolog\Handler\StreamHandler;
use TomPHP\ContextLogger;

$monolog = new Logger('name');
$monolog->pushHandler(new StreamHandler('path/to/your.log', Logger::WARNING));

$log = new ContextLogger($monolog);

$log->addContext('correlation_id', uniqid());

$log->error('There was an error');

Setting the Context

An original context can be set by providing an array as the second argument to the constructor:

$log = new ContextLogger($monolog, ['correlation_id' => uniqid()]);

The context can be added to or modified by the addContext(string $name, $value) method.

The context can also be added to/modified by providing an array to the $context parameter of any of the PSR-3 LoggerInterface methods.

Removing Context

You can remove a item from the context by using the removeContext(string $name) method.

php-context-logger's People

Contributors

tomphp avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar

php-context-logger's Issues

PSR-7?

I think you mean PSR-3 :P

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.