Skip to content

Environment Variables

Logly supports environment variables to control initialization and configuration.

LOGLY_AUTOINIT

Controls whether Logly automatically adds a stderr sink on import.

Default Behavior

By default, Logly adds a stderr sink with level="DEBUG" when the module is first imported:

python
from logly import logger
# stderr sink is already active at DEBUG level
logger.info("This prints to stderr immediately")

Disabling Auto-Init

Set LOGLY_AUTOINIT to false, 0, or no to prevent the automatic stderr sink:

bash
export LOGLY_AUTOINIT=false
python
from logly import logger
# No sinks configured - you must add your own
logger.add("app.log", level="INFO")
logger.info("This only goes to app.log")

Values

ValueBehavior
true (default)Auto-add stderr sink
falseNo automatic sink
0No automatic sink
noNo automatic sink

LOGLY_* Configuration Overrides

These environment variables override default configuration values. The LOGLY_ prefix is stripped and the remainder is lowercased.

VariablePurposeExample
LOGLY_LEVELDefault log levelLOGLY_LEVEL=WARNING
LOGLY_FORMATDefault format stringLOGLY_FORMAT="{level} | {message}"
LOGLY_COLORIZEEnable/disable colorsLOGLY_COLORIZE=NO
LOGLY_SERIALIZEEnable/disable JSON outputLOGLY_SERIALIZE=YES
LOGLY_BACKTRACEEnable/disable backtraceLOGLY_BACKTRACE=YES
LOGLY_DIAGNOSEEnable/disable diagnose modeLOGLY_DIAGNOSE=YES

Usage

bash
# Disable colors
export LOGLY_COLORIZE=NO

# Force JSON output
export LOGLY_SERIALIZE=YES

# Set minimum level
export LOGLY_LEVEL=WARNING
python
from logly import logger
# Configuration applied from environment
logger.info("This respects env overrides")

Common Patterns

Development (default):

bash
export LOGLY_AUTOINIT=true

Production (explicit configuration):

python
import os
os.environ["LOGLY_AUTOINIT"] = "false"

from logly import logger

logger.add("logs/app.log", level="INFO", rotation="daily", compression="gzip")
logger.add("logs/errors.log", level="ERROR")

Testing (disable for clean output):

bash
LOGLY_AUTOINIT=false python -m pytest

Docker:

dockerfile
ENV LOGLY_AUTOINIT=false

Released under the MIT License.