Log Levels¶
Not all messages are equally important. "Entering function parse_config()" is useful while you debug, "Out of disk space" is something you want to see at 3 AM. 🚨
Every message has a level that says how severe it is. Logust has one method per level:
from logust import logger
logger.trace("Entering parse_config()")
logger.debug("Config file has 12 keys")
logger.info("Server starting")
logger.success("Database connected")
logger.warning("Cache is almost full")
logger.error("Could not send the email")
logger.fail("Health check failed")
logger.critical("Out of disk space")
Run it:
$ python main.py
<font color="#8A8A8A">2026-10-06 12:01:06.894</font> | <font color="#3465A4"><b>DEBUG </b></font> | <font color="#06989A">__main__</font>:<font color="#06989A"><module></font>:<font color="#06989A">4</font> - Config file has 12 keys
<font color="#8A8A8A">2026-10-06 12:01:06.894</font> | <font color="#4E9A06"><b>INFO </b></font> | <font color="#06989A">__main__</font>:<font color="#06989A"><module></font>:<font color="#06989A">5</font> - Server starting
<font color="#8A8A8A">2026-10-06 12:01:06.894</font> | <font color="#8AE234"><b>SUCCESS </b></font> | <font color="#06989A">__main__</font>:<font color="#06989A"><module></font>:<font color="#06989A">6</font> - Database connected
<font color="#8A8A8A">2026-10-06 12:01:06.894</font> | <font color="#C4A000"><b>WARNING </b></font> | <font color="#06989A">__main__</font>:<font color="#06989A"><module></font>:<font color="#06989A">7</font> - Cache is almost full
<font color="#8A8A8A">2026-10-06 12:01:06.894</font> | <font color="#CC0000"><b>ERROR </b></font> | <font color="#06989A">__main__</font>:<font color="#06989A"><module></font>:<font color="#06989A">8</font> - Could not send the email
<font color="#8A8A8A">2026-10-06 12:01:06.894</font> | <font color="#75507B"><b>FAIL </b></font> | <font color="#06989A">__main__</font>:<font color="#06989A"><module></font>:<font color="#06989A">9</font> - Health check failed
<font color="#8A8A8A">2026-10-06 12:01:06.894</font> | <font color="#EF2929"><b>CRITICAL</b></font> | <font color="#06989A">__main__</font>:<font color="#06989A"><module></font>:<font color="#06989A">10</font> - Out of disk space
Seven lines for eight calls. Where is the TRACE message?
The default handler only shows messages from DEBUG up, so trace() was filtered out. That's what levels are for: you decide the minimum level, and everything below it is dropped.
Built-in levels¶
These are the levels Logust comes with, from the least to the most severe:
| Level | Method | Value | Color | Use it for |
|---|---|---|---|---|
TRACE | logger.trace() | 5 | Cyan | Very detailed tracing, like entering and leaving functions |
DEBUG | logger.debug() | 10 | Blue | Information useful while debugging |
INFO | logger.info() | 20 | Green | Normal events: startup, requests, jobs |
SUCCESS | logger.success() | 25 | Bright green | Something worked as expected |
WARNING | logger.warning() | 30 | Yellow | Something unexpected, but the program keeps going |
ERROR | logger.error() | 40 | Red | An operation failed |
FAIL | logger.fail() | 45 | Magenta | A check or a task failed |
CRITICAL | logger.critical() | 50 | Bright red | The program may not be able to continue |
The value is what Logust compares: a message is shown when its value is greater than or equal to the minimum level of a handler.
Info
SUCCESS comes from loguru. FAIL is specific to Logust: it sits between ERROR and CRITICAL.
Tip
Need a level that is not in this list, like NOTICE or AUDIT? You can create your own, see Custom Levels.
Set the minimum level¶
Let's say you only want warnings and errors on the console. Use set_level():
from logust import logger
logger.set_level("WARNING")
logger.debug("Config file has 12 keys")
logger.info("Server starting")
logger.warning("Cache is almost full")
logger.error("Could not send the email")
$ python main.py
<font color="#8A8A8A">2026-10-06 12:01:06.950</font> | <font color="#C4A000"><b>WARNING </b></font> | <font color="#06989A">__main__</font>:<font color="#06989A"><module></font>:<font color="#06989A">7</font> - Cache is almost full
<font color="#8A8A8A">2026-10-06 12:01:06.950</font> | <font color="#CC0000"><b>ERROR </b></font> | <font color="#06989A">__main__</font>:<font color="#06989A"><module></font>:<font color="#06989A">8</font> - Could not send the email
The DEBUG and INFO messages are gone.
Level names are case-insensitive, so "WARNING", "warning" and "Warning" all work. You can also pass a number, like set_level(30), or the name of a custom level you registered. Messages at that number or above are shown.
Use LogLevel¶
If you prefer something your editor can autocomplete (and that a typo can't break), use the LogLevel enum instead of a string:
from logust import LogLevel, logger
logger.set_level(LogLevel.Warning)
logger.info("Server starting")
logger.warning("Cache is almost full")
LogLevel has one member per built-in level: LogLevel.Trace, LogLevel.Debug, LogLevel.Info, LogLevel.Success, LogLevel.Warning, LogLevel.Error, LogLevel.Fail and LogLevel.Critical.
Technical Details
set_level() changes the minimum level of the console handlers: the default handler, and any handler you add for sys.stdout or sys.stderr.
Handlers that write to files or to Python functions keep the level you gave them when you added them. You will see how to choose that per-handler level in Handlers and Sinks.
Check the current level¶
get_level() returns the current console level as a LogLevel, with a name and a numeric value. If the level is not a built-in one (a custom level, or a number like 23), you get the number, an int, instead.
is_level_enabled() tells you if a message at a given level would be logged by at least one handler:
from logust import logger
logger.set_level("INFO")
level = logger.get_level()
print(f"Current level: {level.name} ({level.value})")
print("DEBUG enabled?", logger.is_level_enabled("DEBUG"))
print("INFO enabled?", logger.is_level_enabled("INFO"))
Skip expensive work¶
is_level_enabled() is most useful to avoid work that only matters for a message nobody will see:
from logust import logger
def build_report() -> dict[str, int]:
# Imagine this walks a big data structure
return {"users": 1200, "orders": 3456}
logger.set_level("INFO")
if logger.is_level_enabled("DEBUG"):
logger.debug("Report: {}", build_report())
logger.info("Done")
With the level at INFO, build_report() is never called. Turn the level down to DEBUG and the report shows up.
Tip
For a one-off value there is a shorter way: logger.opt(lazy=True), which only calls your functions when the message is going to be logged. See opt() in the Advanced User Guide.
Log with a level name¶
Sometimes the level is only known at runtime, for example, it comes from a config file. For that, use logger.log() with the level name or its number:
from logust import logger
logger.log("INFO", "Logged with a level name")
logger.log("warning", "Level names are case-insensitive")
logger.log(40, "Logged with a level number")
$ python main.py
<font color="#8A8A8A">2026-10-06 12:01:07.251</font> | <font color="#4E9A06"><b>INFO </b></font> | <font color="#06989A">__main__</font>:<font color="#06989A"><module></font>:<font color="#06989A">3</font> - Logged with a level name
<font color="#8A8A8A">2026-10-06 12:01:07.251</font> | <font color="#C4A000"><b>WARNING </b></font> | <font color="#06989A">__main__</font>:<font color="#06989A"><module></font>:<font color="#06989A">4</font> - Level names are case-insensitive
<font color="#8A8A8A">2026-10-06 12:01:07.251</font> | <font color="#CC0000"><b>ERROR </b></font> | <font color="#06989A">__main__</font>:<font color="#06989A"><module></font>:<font color="#06989A">5</font> - Logged with a level number
logger.log() is also how you log at a custom level.
Turn the console off and on¶
You can switch the console output off completely with disable(), and bring it back with enable():
from logust import logger
logger.info("Before disable()")
logger.disable()
print("Console enabled?", logger.is_enabled())
logger.info("Nobody sees this")
logger.enable(level="WARNING")
logger.info("Below WARNING, not shown")
logger.warning("Console is back")
$ python main.py
<font color="#8A8A8A">2026-10-06 12:01:07.187</font> | <font color="#4E9A06"><b>INFO </b></font> | <font color="#06989A">__main__</font>:<font color="#06989A"><module></font>:<font color="#06989A">3</font> - Before disable()
Console enabled? False
<font color="#8A8A8A">2026-10-06 12:01:07.187</font> | <font color="#C4A000"><b>WARNING </b></font> | <font color="#06989A">__main__</font>:<font color="#06989A"><module></font>:<font color="#06989A">11</font> - Console is back
Here's what happened:
logger.disable()set the console handler aside, so"Nobody sees this"went nowhere.logger.is_enabled()tells you if there is an active console handler.logger.enable(level="WARNING")brought the console handler back, withWARNINGas its minimum level. Withoutlevel, it keeps the level it had.
This is handy in tests, or in a command line tool with a --quiet flag. Handlers that write to files keep working while the console is off.
Technical Details
disable() switches off every console handler: the default one, and the ones you added for sys.stdout or sys.stderr. enable() brings back exactly those handlers, with their own format, filter and ID.
If there is no console handler to bring back (for example after logger.remove()), enable() adds the default handler, at DEBUG unless you pass a level.
enable(level=...) sets the level of the console handlers even when the console is already on, like set_level().
Tip
disable() and enable() also accept a module name, like logger.disable("mylib"), to silence the messages of a single library. That is covered in the Advanced User Guide, in library logging.
Recap¶
- There are eight built-in levels:
TRACE,DEBUG,INFO,SUCCESS,WARNING,ERROR,FAILandCRITICAL, each with its own method. set_level("WARNING"),set_level(LogLevel.Warning)orset_level(30)sets the minimum level of the console. Custom level names work too.get_level()returns the current console level,is_level_enabled()tells you if a level would be logged anywhere.- Use
is_level_enabled()to skip expensive work for messages nobody will see. logger.log(level, message)logs at a level chosen at runtime.disable()andenable()turn the console output off and on.