Skip to content

Environment variables to force color/no color of logs not respected #56114

@ashb

Description

@ashb

Hey @ashb! It seems like environment variable overrides and TTY check are not working anymore because colors is never None after this was merged.

Here's the overrides and TTY check I'm talking about:

:param colors: Whether to use colors for non-JSON logs. If `None` is passed, then colors are used
if standard out is a TTY (that is, an interactive session).
It's possible to override this behavior by setting two standard environment variables to any value
except an empty string:
* ``FORCE_COLOR`` activates colors, regardless of where output is going.
* ``NO_COLOR`` disables colors, regardless of where the output is going and regardless the value of
``FORCE_COLOR``. Please note that ``NO_COLOR`` disables all styling, including bold and italics.
:param callsite_parameters: A list parameters about the callsite (line number, function name etc) to
include in the logs.
If ``log_format`` is specified, then anything required to populate that (such as ``%(lineno)d``) will
be automatically included.
:param namespace_log_levels: Levels of extra loggers to configure.
To make this easier to use, this can be a string consisting of pairs of ``<logger>=<level>`` (either
string, or space delimited) which will set the level for that specific logger.
For example::
``sqlalchemy=INFO sqlalchemy.engine=DEBUG``
"""
if "fatal" not in NAME_TO_LEVEL:
NAME_TO_LEVEL["fatal"] = NAME_TO_LEVEL["critical"]
if colors is None:
colors = os.environ.get("NO_COLOR", "") == "" and (
os.environ.get("FORCE_COLOR", "") != ""
or (sys.stdout is not None and hasattr(sys.stdout, "isatty") and sys.stdout.isatty())
)

Originally posted by @ramitkataria in #55824 (comment)

Metadata

Metadata

Assignees

No one assigned

    Type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions