Browse files

Merge pull request #117 from tkoomzaaskz/docs_extend_custom_format

new section: customizing logger output format
  • Loading branch information...
Seldaek committed Sep 11, 2012
2 parents e5bf7ba + 2fec027 commit 0f3dc95c4a0ed7d17bec237d07af3da6c0c1071a
Showing with 35 additions and 0 deletions.
  1. +35 −0 doc/
@@ -121,3 +121,38 @@ $securityLogger = new Logger('security');
+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
+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:
+// 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);
+// bind it to a logger object
+$securityLogger = new Logger('security');
+You may also reuse the same formatter between multiple handlers and share those
+handlers between multiple loggers.

0 comments on commit 0f3dc95

Please sign in to comment.