Skip to content

Commit

Permalink
Add "FORCE_COLOR" and "NO_COLOR" to the "logger" docs
Browse files Browse the repository at this point in the history
  • Loading branch information
Delgan committed Feb 20, 2025
1 parent adafe9e commit c22a981
Showing 1 changed file with 20 additions and 7 deletions.
27 changes: 20 additions & 7 deletions loguru/_logger.py
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,15 @@
.. _formatting directives: https://docs.python.org/3/library/string.html#format-string-syntax
.. _reentrant: https://en.wikipedia.org/wiki/Reentrancy_(computing)
.. _ANSI codes: https://en.wikipedia.org/wiki/ANSI_escape_code
.. |NO_COLOR| replace:: ``NO_COLOR``
.. _NO_COLOR: https://no-color.org/
.. |FORCE_COLOR| replace:: ``FORCE_COLOR``
.. _FORCE_COLOR: https://force-color.org/
"""

import builtins
Expand Down Expand Up @@ -663,13 +672,17 @@ def add(
.. rubric:: The color markups
To add colors to your logs, you just have to enclose your format string with the appropriate
tags (e.g. ``<red>some message</red>``). These tags are automatically removed if the sink
doesn't support ansi codes. For convenience, you can use ``</>`` to close the last opening
tag without repeating its name (e.g. ``<red>another message</>``).
The special tag ``<level>`` (abbreviated with ``<lvl>``) is transformed according to
the configured color of the logged message level.
When the sink supports it, the logs can be colored by using markups in the format string.
By default (when ``colorize`` is not specified), these are automatically converted or
removed depending on the sink's support for `ANSI codes`_. Loguru also honors the
|NO_COLOR|_ and |FORCE_COLOR|_ environment variables (the former taking precedence over the
latter).
To add colors, you just have to enclose your format string with the appropriate tags
(e.g. ``<red>some message</red>``). For convenience, you can use ``</>`` to close the last
opening tag without repeating its name (e.g. ``<red>another message</>``). The special tag
``<level>`` (abbreviated with ``<lvl>``) is transformed according to the configured color
of the logged message level.
Tags which are not recognized will raise an exception during parsing, to inform you about
possible misuse. If you wish to display a markup tag literally, you can escape it by
Expand Down

0 comments on commit c22a981

Please sign in to comment.