Loading demo_dev_mode.py +1 −1 Original line number Diff line number Diff line Loading @@ -18,7 +18,7 @@ if os.environ.get("DEBUG"): handler.formatter = StructuredFormatter( structured_formatter_config=StructuredFormatterConfig( dumps_fn=make_friendly_dump_fn( # Enable colours only if the handler pointed to a teletype. # Enable colours only if the handler is pointed to a teletype. colours=isinstance(handler, logging.StreamHandler) and handler.stream.isatty() ), ) Loading docs/usage.rst +15 −8 Original line number Diff line number Diff line Loading @@ -253,7 +253,7 @@ You can modify the current context with `add_context <logstruct.add_context>`, ` {..., "message": "no context"} Modifications only apply to the current scope. Once the scope ends, all modifications are lost. modifications are rolled back. .. testcode:: Loading @@ -271,6 +271,9 @@ modifications are lost. Configuration ------------- Configuration, including `logging.config.fileConfig` and `logging.config.dictConfig`, works just like it does in the standard library, allowing to set up stdlib logging and ``logstruct`` in one go. .. _logger_config: Logger configuration Loading @@ -280,20 +283,22 @@ There is no configuration specific to `StructuredLogger`. Since each `Structured with a `logging.Logger` with the same name, that logger should be configured as in the `official docs <https://docs.python.org/3/library/logging.config.html#module-logging.config>`_. `logging.config.fileConfig` and `logging.config.dictConfig` configuration works just like it does in the standard library. .. _formatter_usage: .. _formatter_configuration: Formatter configuration ^^^^^^^^^^^^^^^^^^^^^^^ A `StructuredFormatter` is configured using `StructuredFormatterConfig`. A `StructuredFormatter` is configured using `StructuredFormatterConfig`. It can be either supplied directly via the ``structured_formatter_config`` argument to `StructuredFormatter` or loaded from data. Logstruct provides two default configs: `logstruct.CONFIG_FORMATTED_MESSAGE` and `logstruct.CONFIG_RAW_MESSAGE`, which can be used directly or copied to derive custom configuration. `StructuredFormatterConfig` reference ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ .. list-table:: `StructuredFormatterConfig` attributes :header-rows: 1 Loading @@ -309,7 +314,7 @@ Logstruct provides two default configs: `logstruct.CONFIG_FORMATTED_MESSAGE` and * - `uses_time <StructuredFormatterConfig.uses_time>` - ``True`` - Determines if the current time should be assigned to ``LogRecord.asctime``. - Determines if current time should be assigned to ``LogRecord.asctime``. * - `log_fields <StructuredFormatterConfig.log_fields>` - `DEFAULT_LOG_FIELDS` Loading Loading @@ -386,8 +391,10 @@ attribute is missing or evaluates to False. {"task": null} Highly customised configuration example ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ .. _highly-customised-configuration-example: `StructuredFormatterConfig` example ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ The following example defines completely custom configuration, featuring: Loading Loading
demo_dev_mode.py +1 −1 Original line number Diff line number Diff line Loading @@ -18,7 +18,7 @@ if os.environ.get("DEBUG"): handler.formatter = StructuredFormatter( structured_formatter_config=StructuredFormatterConfig( dumps_fn=make_friendly_dump_fn( # Enable colours only if the handler pointed to a teletype. # Enable colours only if the handler is pointed to a teletype. colours=isinstance(handler, logging.StreamHandler) and handler.stream.isatty() ), ) Loading
docs/usage.rst +15 −8 Original line number Diff line number Diff line Loading @@ -253,7 +253,7 @@ You can modify the current context with `add_context <logstruct.add_context>`, ` {..., "message": "no context"} Modifications only apply to the current scope. Once the scope ends, all modifications are lost. modifications are rolled back. .. testcode:: Loading @@ -271,6 +271,9 @@ modifications are lost. Configuration ------------- Configuration, including `logging.config.fileConfig` and `logging.config.dictConfig`, works just like it does in the standard library, allowing to set up stdlib logging and ``logstruct`` in one go. .. _logger_config: Logger configuration Loading @@ -280,20 +283,22 @@ There is no configuration specific to `StructuredLogger`. Since each `Structured with a `logging.Logger` with the same name, that logger should be configured as in the `official docs <https://docs.python.org/3/library/logging.config.html#module-logging.config>`_. `logging.config.fileConfig` and `logging.config.dictConfig` configuration works just like it does in the standard library. .. _formatter_usage: .. _formatter_configuration: Formatter configuration ^^^^^^^^^^^^^^^^^^^^^^^ A `StructuredFormatter` is configured using `StructuredFormatterConfig`. A `StructuredFormatter` is configured using `StructuredFormatterConfig`. It can be either supplied directly via the ``structured_formatter_config`` argument to `StructuredFormatter` or loaded from data. Logstruct provides two default configs: `logstruct.CONFIG_FORMATTED_MESSAGE` and `logstruct.CONFIG_RAW_MESSAGE`, which can be used directly or copied to derive custom configuration. `StructuredFormatterConfig` reference ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ .. list-table:: `StructuredFormatterConfig` attributes :header-rows: 1 Loading @@ -309,7 +314,7 @@ Logstruct provides two default configs: `logstruct.CONFIG_FORMATTED_MESSAGE` and * - `uses_time <StructuredFormatterConfig.uses_time>` - ``True`` - Determines if the current time should be assigned to ``LogRecord.asctime``. - Determines if current time should be assigned to ``LogRecord.asctime``. * - `log_fields <StructuredFormatterConfig.log_fields>` - `DEFAULT_LOG_FIELDS` Loading Loading @@ -386,8 +391,10 @@ attribute is missing or evaluates to False. {"task": null} Highly customised configuration example ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ .. _highly-customised-configuration-example: `StructuredFormatterConfig` example ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ The following example defines completely custom configuration, featuring: Loading