Colored, single-line log output for command-line tools: a dependency-free coloredlogs.install() replacement
Maintained. Last release 3 weeks ago, commits in 2 of the last 26 weeks. Weaker on commit activity and contributor spread.
pip install ansilogsansilogs
Colored, single-line log output for command-line tools. A small, dependency-free replacement
for coloredlogs.install().
import logging
import ansilogs
ansilogs.install(logging.DEBUG)
logging.getLogger(__name__).warning("careful")
2026-10-19 09:35:12 my-host my_tool.cli[4242] WARNING careful
- One line per record:
<time> <host> <name>[<pid>] <LEVEL> <message>; tracebacks follow uncolored. - The default style dims the time, host and pid, shows the logger name in cyan and the level name
in its severity color (debug output dimmed).
style="coloredlogs"reproduces coloredlogs' look byte for byte. highlight_code=Truealso paints the`backticked`spans of a message (a command to run, an identifier), so they stand out from the sentence around them. The text itself is unchanged. It is off by default, since it recolors part of any message that contains a pair of backticks.- Colors only when stderr is a terminal.
NO_COLOR(non-empty) disables them,FORCE_COLOR(non-empty) forces them. On Windows the console is switched to ANSI processing; if that fails, output is plain. - Records go to whatever
sys.stderris at the time (test capture and live progress displays that redirect stderr keep working).
API
install(level=logging.INFO, colors=None, style="default", highlight_code=False): attach the handler to the root logger (once) and show records fromlevelup.colors=Nonemeanssupports_color();styleis"default"or"coloredlogs"(seeSTYLES);highlight_codepaints the backticked spans of each message.set_level(level): change the shown level (installs the handler if needed).supports_color(stream=None): the color decision used byinstall().ColoredFormatter(colors=True, hostname=None, style="default", highlight_code=False)andStderrHandlerfor custom setups.
Migrating from coloredlogs
-import coloredlogs
-coloredlogs.install(level=logging.DEBUG)
+import ansilogs
+ansilogs.install(logging.DEBUG)
Pass style="coloredlogs" to keep the exact coloredlogs colors. coloredlogs.set_level(level)
becomes . environment variables and custom field/level
styles are not supported.