1
0
mirror of https://github.com/Seldaek/monolog.git synced 2025-08-06 13:16:39 +02:00
This commit is contained in:
Pablo Belloc
2012-02-26 11:58:10 -03:00
parent d752f435b5
commit ff287b9d10
2 changed files with 2 additions and 50 deletions

View File

@@ -45,7 +45,7 @@ Handlers
- _NativeMailHandler_: Sends emails using PHP's mail() function. - _NativeMailHandler_: Sends emails using PHP's mail() function.
- _SwiftMailerHandler_: Sends emails using a SwiftMailer instance. - _SwiftMailerHandler_: Sends emails using a SwiftMailer instance.
- _SyslogHandler_: Logs records to the syslog. - _SyslogHandler_: Logs records to the syslog.
- _SocketHandler_: Logs records to [sockets](http://php.net/fsockopen), use this for UNIX and TCP sockets. See an [example](https://github.com/pablolb/monolog/blob/master/doc/sockets.md). - _SocketHandler_: Logs records to [sockets](http://php.net/fsockopen), use this for UNIX and TCP sockets. See an [example](https://github.com/Seldaek/monolog/blob/master/doc/sockets.md).
Wrappers / Special Handlers Wrappers / Special Handlers
--------------------------- ---------------------------

View File

@@ -14,13 +14,13 @@ This example e persistent connections:
use Monolog\Logger; use Monolog\Logger;
use Monolog\Handler\SocketHandler; use Monolog\Handler\SocketHandler;
use Monolog\Handler\SocketHandler\Socket;
// Create the logger // Create the logger
$logger = new Logger('my_logger'); $logger = new Logger('my_logger');
// Create the handler // Create the handler
$handler = new SocketHandler('unix:///var/log/httpd_app_log.socket'); $handler = new SocketHandler('unix:///var/log/httpd_app_log.socket');
$handler->setPersistent(true);
// Now add the handler // Now add the handler
$logger->pushHandler($handler, Logger::DEBUG); $logger->pushHandler($handler, Logger::DEBUG);
@@ -34,51 +34,3 @@ In this example, using syslog-ng, you should see the log on the log server:
cweb1 [2012-02-26 00:12:03] my_logger.INFO: My logger is now ready [] [] cweb1 [2012-02-26 00:12:03] my_logger.INFO: My logger is now ready [] []
Symfony2 Example
----------------
In Symfony2, first we have to create the handler service in our services.xml (or similar):
```xml
<!-- Configure our socket -->
<service id="logging.socket"
class="Monolog\Handler\SocketHandler\PersistentSocket"
public="false">
<argument>%logging.socket.connection_string%</argument>
<call method="setTimeout">
<argument>2</argument>
</call>
<call method="setConnectionTimeout">
<argument>2</argument>
</call>
</service>
<!-- Create our handler and inject the socket -->
<service id="logging.socket_handler" class="Monolog\Handler\SocketHandler">
<argument></argument>
<call method="setSocket">
<argument type="service" id="logging.socket"/>
</call>
</service>
```
And then, change our config.yml (or similar):
```yaml
parameters:
logging.socket.connection_string: 'unix:///var/log/httpd_app_log.socket'
monolog:
handlers:
main:
type: stream
path: %kernel.logs_dir%/%kernel.environment%.log
level: debug
firephp:
type: firephp
level: info
custom:
type: service
id: logging.socket_handler
```