From f9f3c3f9fa4cb330d4e39a1f685c824df172db28 Mon Sep 17 00:00:00 2001 From: Ryan Weaver Date: Sun, 7 Dec 2014 10:41:21 -0500 Subject: [PATCH 1/3] Making the channel handler more useful by showing it on the prod environment --- cookbook/logging/channels_handlers.rst | 66 ++++++++++++++++---------- 1 file changed, 40 insertions(+), 26 deletions(-) diff --git a/cookbook/logging/channels_handlers.rst b/cookbook/logging/channels_handlers.rst index 69c4e5002b0..f859c985308 100644 --- a/cookbook/logging/channels_handlers.rst +++ b/cookbook/logging/channels_handlers.rst @@ -4,37 +4,47 @@ How to Log Messages to different Files ====================================== -The Symfony Standard Edition contains a bunch of channels for logging: ``doctrine``, -``event``, ``security`` and ``request``. Each channel corresponds to a logger -service (``monolog.logger.XXX``) in the container and is injected to the -concerned service. The purpose of channels is to be able to organize different -types of log messages. +The Symfony Framework organizes log messages into channels. By default, there +are several channels, including ``doctrine``, ``event``, ``security``, ``request`` +and more. The channel is printed in the log message and can also be used +to direct different channels to different places/files. By default, Symfony logs every message into a single file (regardless of the channel). +.. note:: + + Each channel corresponds to a logger service (``monolog.logger.XXX``) + in the container (use the ``container:debug`` command to see a full list) + and those are injected into different services. + +.. _logging-channel-handler: + Switching a Channel to a different Handler ------------------------------------------ -Now, suppose you want to log the ``doctrine`` channel to a different file. - -To do so, just create a new handler and configure it like this: +Now, suppose you want to log the ``security`` channel to a different file +in the ``prod`` environment. To do this, just create a new handler and configure +it to log only messages from the ``security`` channel: .. configuration-block:: .. code-block:: yaml - # app/config/config.yml + # app/config/config_prod.yml monolog: handlers: - main: + security: + # log all messages (since debug is the lowest level) + level: debug type: stream - path: /var/log/symfony.log - channels: ["!doctrine"] - doctrine: - type: stream - path: /var/log/doctrine.log - channels: [doctrine] + path: "%kernel.logs_dir%/security.log" + channels: [security] + + # an example of *not* logging security channel messages + main: + # ... + # channels: ["!security"] .. code-block:: xml @@ -48,16 +58,18 @@ To do so, just create a new handler and configure it like this: http://symfony.com/schema/dic/monolog/monolog-1.0.xsd" > - + - !doctrine + security - + + @@ -67,19 +79,21 @@ To do so, just create a new handler and configure it like this: // app/config/config.php $container->loadFromExtension('monolog', array( 'handlers' => array( - 'main' => array( + 'security' => array( 'type' => 'stream', - 'path' => '/var/log/symfony.log', + 'path' => '%kernel.logs_dir%/security.log', 'channels' => array( - '!doctrine', + 'security', ), ), - 'doctrine' => array( + 'main' => array( 'type' => 'stream', - 'path' => '/var/log/doctrine.log', + 'path' => '%kernel.logs_dir%/security.log', + /* 'channels' => array( - 'doctrine', + '!security', ), + */ ), ), )); From 78323d844806ef7a3992ece99cb81ed7b3fbad9a Mon Sep 17 00:00:00 2001 From: Ryan Weaver Date: Fri, 16 Jan 2015 12:53:26 -0500 Subject: [PATCH 2/3] Changing back to config.yml and fixing some code block mistakes thanks to Wouter --- cookbook/logging/channels_handlers.rst | 20 ++++++++------------ 1 file changed, 8 insertions(+), 12 deletions(-) diff --git a/cookbook/logging/channels_handlers.rst b/cookbook/logging/channels_handlers.rst index f859c985308..db9a92298c5 100644 --- a/cookbook/logging/channels_handlers.rst +++ b/cookbook/logging/channels_handlers.rst @@ -23,15 +23,15 @@ the channel). Switching a Channel to a different Handler ------------------------------------------ -Now, suppose you want to log the ``security`` channel to a different file -in the ``prod`` environment. To do this, just create a new handler and configure -it to log only messages from the ``security`` channel: +Now, suppose you want to log the ``security`` channel to a different file. +To do this, just create a new handler and configure it to log only messages +from the ``security`` channel: .. configuration-block:: .. code-block:: yaml - # app/config/config_prod.yml + # app/config/config.yml monolog: handlers: security: @@ -41,7 +41,7 @@ it to log only messages from the ``security`` channel: path: "%kernel.logs_dir%/security.log" channels: [security] - # an example of *not* logging security channel messages + # an example of *not* logging security channel messages for this handler main: # ... # channels: ["!security"] @@ -64,12 +64,11 @@ it to log only messages from the ``security`` channel: - - !security - --> @@ -87,13 +86,10 @@ it to log only messages from the ``security`` channel: ), ), 'main' => array( - 'type' => 'stream', - 'path' => '%kernel.logs_dir%/security.log', - /* + // ... 'channels' => array( '!security', ), - */ ), ), )); From bc79b21cf91637a9f26918c69be6b2a9e75b45ca Mon Sep 17 00:00:00 2001 From: Ryan Weaver Date: Mon, 25 May 2015 19:22:07 -0400 Subject: [PATCH 3/3] Adding one more note about why we're in config.yml --- cookbook/logging/channels_handlers.rst | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/cookbook/logging/channels_handlers.rst b/cookbook/logging/channels_handlers.rst index db9a92298c5..88ce8ed3d33 100644 --- a/cookbook/logging/channels_handlers.rst +++ b/cookbook/logging/channels_handlers.rst @@ -25,7 +25,8 @@ Switching a Channel to a different Handler Now, suppose you want to log the ``security`` channel to a different file. To do this, just create a new handler and configure it to log only messages -from the ``security`` channel: +from the ``security`` channel. You might add this in ``config.yml`` to log +in all environments, or just ``config_prod.yml`` to happen only in ``prod``: .. configuration-block::