Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP

Loading…

new section: customizing logger output format #117

Merged
merged 1 commit into from

2 participants

@tkoomzaaskz

Hi Jordi!

I suggest adding a new section in the usage docs file . It covers the topic of formatting log output. It's quite an easy mechanism, but it takes a while to scan src classes, since it's not mentioned in the actual docs.

I hope you'll find my work useful. Cheers!

@Seldaek Seldaek merged commit 0f3dc95 into Seldaek:master
@Seldaek
Owner

Looks good thanks

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Commits on Sep 10, 2012
  1. @tkoomzaaskz
This page is out of date. Refresh to see the latest.
Showing with 35 additions and 0 deletions.
  1. +35 −0 doc/usage.md
View
35 doc/usage.md
@@ -121,3 +121,38 @@ $securityLogger = new Logger('security');
$securityLogger->pushHandler($stream);
$securityLogger->pushHandler($firephp);
```
+
+Customizing log format
+----------------------
+
+In Monolog it's easy to customize the format of the logs written into files,
+sockets, mails, databases and other handlers. Most of the handlers use the
+
+```php
+$record['formatted']
+```
+
+value to be automatically put into the log device. This value depends on the
+formatter settings. You can choose between predefined formatter classes or
+write your own (e.g. a multiline text file for human-readable output).
+
+To configure a predefined formatter class, just set it as the handler's field:
+
+```php
+// the default date format is "Y-m-d H:i:s"
+$dateFormat = "Y n j, g:i a";
+// the default output format is "[%datetime%] %channel%.%level_name%: %message% %context% %extra%\n"
+$output = "%datetime% > %level_name% > %message% %context% %extra%\n"
+// finally, create a formatter
+$formatter = new LineFormatter($output, $dateFormat);
+
+// Create a handler
+$stream = new StreamHandler(__DIR__.'/my_app.log', Logger::DEBUG);
+$stream->setFormatter($formatter);
+// bind it to a logger object
+$securityLogger = new Logger('security');
+$securityLogger->pushHandler($stream);
+```
+
+You may also reuse the same formatter between multiple handlers and share those
+handlers between multiple loggers.
Something went wrong with that request. Please try again.