From ee9ac90fa20fd622a6426cea2827c422a625b665 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Gina=20H=C3=A4u=C3=9Fge?= Date: Mon, 11 Dec 2023 10:13:52 +0100 Subject: [PATCH] =?UTF-8?q?=F0=9F=93=9D=20Clarify=20how=20to=20reconfigure?= =?UTF-8?q?=20log=20formatters?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit OctoPrint now uses either simple or colored formatter for the console log output, so document this properly. See #4916 --- docs/configuration/logging_yaml.rst | 22 +++++++++++++++++++++- 1 file changed, 21 insertions(+), 1 deletion(-) diff --git a/docs/configuration/logging_yaml.rst b/docs/configuration/logging_yaml.rst index b0de4ef19..f4f967c2b 100644 --- a/docs/configuration/logging_yaml.rst +++ b/docs/configuration/logging_yaml.rst @@ -61,7 +61,7 @@ used for the ``serial.log`` and the ``console`` handler used for the output to s console: class: logging.StreamHandler level: DEBUG - formatter: simple + formatter: colored stream: ext://sys.stdout # octoprint.log @@ -81,6 +81,12 @@ used for the ``serial.log`` and the ``console`` handler used for the output to s maxBytes: 2097152 # 2 * 1024 * 1024 = 2 MB in bytes filename: /path/to/octoprints/logs/serial.log +.. note:: + + If OctoPrint is instructed to not color its logging output (e.g. via the ``--no-color`` command + line option or the ``NO_COLOR`` environment variable), the ``colored`` formatter will be replaced + with the ``simple`` formatter. + You can find more information on the used logging handlers in the Python documentation on :py:mod:`logging.handlers`. @@ -95,6 +101,20 @@ expressed in YAML as follows: formatters: simple: format: "%(asctime)s - %(name)s - %(levelname)s - %(message)s" + colored: + format: "%(log_color)s%(asctime)s - %(name)s - %(levelname)s - %(message)s%(reset)s" + +As example, if you want to change the format to include the full file and line number in which the logging statement was issued, you +could redefine the formatters as follows: + + +.. code-block:: yaml + + formatters: + simple: + format: "%(asctime)s - %(name)s - %(pathname)s%(filename)s#%(lineno)d - %(levelname)s - %(message)s" + colored: + format: "%(log_color)s%(asctime)s - %(name)s - %(pathname)s%(filename)s#%(lineno)d - %(levelname)s - %(message)s%(reset)s" The possible keys for the logging format can be found in the :ref:`Python documentation on LogRecord attributes `.