Logging#

DecisionAI uses the loguru library for logging. By default, logging is disabled for the decision_ai namespace to avoid cluttering your console output.

Enabling Logging#

There are two ways to enable logging in DecisionAI:

1. Using an Environment Variable#

Set the DECISION_AI_LOG_LEVEL environment variable to your desired log level:

# Linux/MacOS
export DECISION_AI_LOG_LEVEL=DEBUG

# Windows (Command Prompt)
set DECISION_AI_LOG_LEVEL=DEBUG

# Windows (PowerShell)
$env:DECISION_AI_LOG_LEVEL = "DEBUG"

2. Programmatically#

You can also enable logging programmatically in your code:

from decision_ai import logger

# Enable logging for the decision_ai namespace
logger.enable("decision_ai")

# Set specific log level
logger.level("decision_ai", "DEBUG")

Available Log Levels#

Loguru provides the following log levels (in ascending order of severity):

Level

Method

Description

TRACE

logger.trace()

Most detailed debugging information

DEBUG

logger.debug()

Detailed debugging information

INFO

logger.info()

Confirmation that things are working as expected

SUCCESS

logger.success()

Successful operations (unique to Loguru)

WARNING

logger.warning()

Indication that something unexpected happened

ERROR

logger.error()

Error that prevented operation from completing

CRITICAL

logger.critical()

Very serious error that might cause program termination

In addition, the NONE level can be used for the environment variable DECISION_AI_LOG_LEVEL to disable logging.

Example usage:

from decision_ai import logger

logger.enable("decision_ai")

logger.trace("Very detailed debugging information")
logger.debug("Debugging information")
logger.info("Normal information message")
logger.success("Operation completed successfully")
logger.warning("Warning message")
logger.error("Error message")
logger.critical("Critical error message")

Custom Configuration#

Since DecisionAI uses loguru, you can apply any custom configuration supported by the loguru library:

from decision_ai import logger

# Add a file handler
logger.add("decision_ai.log", rotation="10 MB")

# Enable and configure
logger.enable("decision_ai")
logger.level("decision_ai", "DEBUG")

# Use colored output
logger.opt(colors=True).info("This message has <green>colored</green> parts")

# Log with exception information
try:
    1/0
except Exception:
    logger.exception("An error occurred")

Creating Custom Log Levels#

If needed, you can also create custom log levels:

from decision_ai import logger

# Create a custom level
logger.level("IMPORTANT", no=25, color="<yellow>", icon="⚠️")

# Use the custom level
logger.log("IMPORTANT", "This is an important message")

For more advanced configuration options, refer to the loguru documentation.