Skip to content
This repository
Browse code

Merge pull request #117 from tkoomzaaskz/docs_extend_custom_format

new section: customizing logger output format
  • Loading branch information...
commit 0f3dc95c4a0ed7d17bec237d07af3da6c0c1071a 2 parents e5bf7ba + 2fec027
Jordi Boggiano authored September 11, 2012

Showing 1 changed file with 35 additions and 0 deletions. Show diff stats Hide diff stats

  1. 35  doc/usage.md
35  doc/usage.md
Source Rendered
@@ -121,3 +121,38 @@ $securityLogger = new Logger('security');
121 121
 $securityLogger->pushHandler($stream);
122 122
 $securityLogger->pushHandler($firephp);
123 123
 ```
  124
+
  125
+Customizing log format
  126
+----------------------
  127
+
  128
+In Monolog it's easy to customize the format of the logs written into files,
  129
+sockets, mails, databases and other handlers. Most of the handlers use the
  130
+
  131
+```php
  132
+$record['formatted']
  133
+```
  134
+
  135
+value to be automatically put into the log device. This value depends on the
  136
+formatter settings. You can choose between predefined formatter classes or
  137
+write your own (e.g. a multiline text file for human-readable output).
  138
+
  139
+To configure a predefined formatter class, just set it as the handler's field:
  140
+
  141
+```php
  142
+// the default date format is "Y-m-d H:i:s"
  143
+$dateFormat = "Y n j, g:i a";
  144
+// the default output format is "[%datetime%] %channel%.%level_name%: %message% %context% %extra%\n"
  145
+$output = "%datetime% > %level_name% > %message% %context% %extra%\n"
  146
+// finally, create a formatter
  147
+$formatter = new LineFormatter($output, $dateFormat);
  148
+
  149
+// Create a handler
  150
+$stream = new StreamHandler(__DIR__.'/my_app.log', Logger::DEBUG);
  151
+$stream->setFormatter($formatter);
  152
+// bind it to a logger object
  153
+$securityLogger = new Logger('security');
  154
+$securityLogger->pushHandler($stream);
  155
+```
  156
+
  157
+You may also reuse the same formatter between multiple handlers and share those
  158
+handlers between multiple loggers.

0 notes on commit 0f3dc95

Please sign in to comment.
Something went wrong with that request. Please try again.