From 31fd0dbbd677a5c4a0625d0d034eab03431bcc81 Mon Sep 17 00:00:00 2001 From: Javier Eguiluz Date: Thu, 2 Apr 2015 17:25:46 +0200 Subject: [PATCH 1/3] Added a note about the rotating_file monolog handler --- cookbook/logging/monolog.rst | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/cookbook/logging/monolog.rst b/cookbook/logging/monolog.rst index 6093fa85589..5f8bcd0cc97 100644 --- a/cookbook/logging/monolog.rst +++ b/cookbook/logging/monolog.rst @@ -236,6 +236,21 @@ only for a specific handler. generate hundreds of log lines. Consider using tools like the `logrotate`_ Linux command to rotate log files before they become a problem. + In case you cannot use a dedicated tool for rotating log files, consider using + the special ``rotating_file`` handler defined by Monolog. This handler creates + a new log file every day and can also remove old files automatically. To use + it, just set the ``type`` option of your handler to ``rotating_file``: + + .. code-block:: yaml + + # app/config/config_dev.yml + monolog: + handlers: + main: + type: rotating_file # <-- this value is usually 'stream' + path: %kernel.logs_dir%/%kernel.environment%.log + level: debug + A processor is simply a callable receiving the record as its first argument. Processors are configured using the ``monolog.processor`` DIC tag. See the :ref:`reference about it `. From 7345c17107f2a1b4610caffac277167e5f36e1a4 Mon Sep 17 00:00:00 2001 From: Javier Eguiluz Date: Sun, 5 Apr 2015 15:47:22 +0200 Subject: [PATCH 2/3] Added XML and PHP configuration samples --- cookbook/logging/monolog.rst | 49 +++++++++++++++++++++++++++++------- 1 file changed, 40 insertions(+), 9 deletions(-) diff --git a/cookbook/logging/monolog.rst b/cookbook/logging/monolog.rst index 5f8bcd0cc97..b464e6d976e 100644 --- a/cookbook/logging/monolog.rst +++ b/cookbook/logging/monolog.rst @@ -241,15 +241,46 @@ only for a specific handler. a new log file every day and can also remove old files automatically. To use it, just set the ``type`` option of your handler to ``rotating_file``: - .. code-block:: yaml - - # app/config/config_dev.yml - monolog: - handlers: - main: - type: rotating_file # <-- this value is usually 'stream' - path: %kernel.logs_dir%/%kernel.environment%.log - level: debug + .. configuration-block:: + + .. code-block:: yaml + + # app/config/config_dev.yml + monolog: + handlers: + main: + type: rotating_file + path: %kernel.logs_dir%/%kernel.environment%.log + level: debug + + .. code-block:: xml + + + + + + + + + + + .. code-block:: php + + // app/config/config_dev.php + $container->loadFromExtension('monolog', array( + 'handlers' => array( + 'main' => array( + 'type' => 'rotating_file', + 'path' => '%kernel.logs_dir%/%kernel.environment%.log', + 'level' => 'debug', + ), + ), + )); A processor is simply a callable receiving the record as its first argument. Processors are configured using the ``monolog.processor`` DIC tag. See the From db1e79868f48a013e9c0c2e22277e30ac8dec246 Mon Sep 17 00:00:00 2001 From: Javier Eguiluz Date: Mon, 25 May 2015 10:31:52 +0200 Subject: [PATCH 3/3] Created a new section for rotating log files and explained the max_files configuration option --- cookbook/logging/monolog.rst | 116 +++++++++++++++++++---------------- 1 file changed, 63 insertions(+), 53 deletions(-) diff --git a/cookbook/logging/monolog.rst b/cookbook/logging/monolog.rst index b464e6d976e..7b05f9f9e79 100644 --- a/cookbook/logging/monolog.rst +++ b/cookbook/logging/monolog.rst @@ -222,6 +222,69 @@ easily. Your formatter must implement ), )); +How to Rotate your Log Files +---------------------------- + +Beware that log file sizes can grow very rapidly, leading to disk space exhaustion. +This is specially true in the ``dev`` environment, where a simple request can +generate hundreds of log lines. Consider using tools like the `logrotate`_ +Linux command to rotate log files before they become a problem. + +In case you cannot use a dedicated tool for rotating log files, consider using +the special ``rotating_file`` handler defined by Monolog. This handler creates +a new log file every day and can also remove old files automatically. To use +it, just set the ``type`` option of your handler to ``rotating_file``: + +.. configuration-block:: + + .. code-block:: yaml + + # app/config/config_dev.yml + monolog: + handlers: + main: + type: rotating_file + path: %kernel.logs_dir%/%kernel.environment%.log + level: debug + # max number of log files to keep + # defaults to zero, which means infinite files + max_files: 10 + + .. code-block:: xml + + + + + + + + max_files="10" + /> + + + + .. code-block:: php + + // app/config/config_dev.php + $container->loadFromExtension('monolog', array( + 'handlers' => array( + 'main' => array( + 'type' => 'rotating_file', + 'path' => '%kernel.logs_dir%/%kernel.environment%.log', + 'level' => 'debug', + // max number of log files to keep + // defaults to zero, which means infinite files + 'max_files' => 10, + ), + ), + )); + Adding some extra Data in the Log Messages ------------------------------------------ @@ -229,59 +292,6 @@ Monolog allows you to process the record before logging it to add some extra data. A processor can be applied for the whole handler stack or only for a specific handler. -.. tip:: - - Beware that log file sizes can grow very rapidly, leading to disk space exhaustion. - This is specially true in the ``dev`` environment, where a simple request can - generate hundreds of log lines. Consider using tools like the `logrotate`_ - Linux command to rotate log files before they become a problem. - - In case you cannot use a dedicated tool for rotating log files, consider using - the special ``rotating_file`` handler defined by Monolog. This handler creates - a new log file every day and can also remove old files automatically. To use - it, just set the ``type`` option of your handler to ``rotating_file``: - - .. configuration-block:: - - .. code-block:: yaml - - # app/config/config_dev.yml - monolog: - handlers: - main: - type: rotating_file - path: %kernel.logs_dir%/%kernel.environment%.log - level: debug - - .. code-block:: xml - - - - - - - - - - - .. code-block:: php - - // app/config/config_dev.php - $container->loadFromExtension('monolog', array( - 'handlers' => array( - 'main' => array( - 'type' => 'rotating_file', - 'path' => '%kernel.logs_dir%/%kernel.environment%.log', - 'level' => 'debug', - ), - ), - )); - A processor is simply a callable receiving the record as its first argument. Processors are configured using the ``monolog.processor`` DIC tag. See the :ref:`reference about it `.