GithubHelp home page GithubHelp logo

ricebna / monolog-utils Goto Github PK

View Code? Open in Web Editor NEW

This project forked from macbre/monolog-utils

0.0 0.0 0.0 6 KB

Addiitonal formatters and processors for Monolog

Home Page: https://packagist.org/packages/macbre/monolog-utils

License: MIT License

PHP 100.00%

monolog-utils's Introduction

monolog-utils

Addiitonal formatters and processors for Monolog

ExceptionProcessor

Allows you to pass an Exception instance as a part of $context - it will be automically expanded to log exception class, message, code and a backtrace

try {
	// do something
}
catch (NastyException $ex) {
	$logger->error('Something bad happended', [
		'exception' => $ex
	]);
}

exception field will be expanded to something similar to:

{
	"@context": {
		"exception": {
			"class": "NastyException",
			"message": "Things went wrong",
			"code": 42,
			"trace": [
				"/home/macbre/app/Foo.class.php:979",
				"/home/macbre/app/App.class.php:29",
				"/home/macbre/app/index.php:18"
			]
		}
	}
}

RequestIdProcessor

Automatically generates a unique, per request ID that is sent with every message log as request_id field in $extra.

JsonFormatter

JSON log formatter for elastic / Kibana.

An example entry:

$logger->error('Foo Bar', [
	'size' => 42
]);
{
	"@timestamp": "2015-12-12T12:28:03.010299+01:00",
	"@message": "Foo Bar",
	"@context": {
		"size": 42
	},
	"@fields": {
		"request_id": "566c04c2f22693.59900054"
	},
	"severity": "error",
	"program": "my.app",
	"@source_host": "my.server.net"
}

Example

$logger = new Monolog\Logger('my.app');

$logger->pushProcessor(new Macbre\Logger\Processors\ExceptionProcessor());
$logger->pushProcessor(new Macbre\Logger\Processors\RequestIdProcessor());

// Syslog and JSON formatter for elastic / Kibana
$syslog = new Monolog\Handler\SyslogUdpHandler('127.0.0.1', 514, LOG_USER, Monolog\Logger::INFO);
$syslog->setFormatter(new Macbre\Logger\Formatters\JsonFormatter());
$logger->pushHandler($syslog);

// and now let's use the logger...
$logger->error('Foo Bar', [
	'exception' => new Exception('An error', 123),
	'size' => 42
]);

monolog-utils's People

Contributors

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