Skip to content

configure_logging

Set up Alice's two-handler logging scheme.

configure_logging

configure_logging(log_file: Optional[str] = None) -> None

Set up Alice's two-handler logging scheme.

Attaches a stream handler (INFO and above) and a file handler (DEBUG and above) to the alice root logger. Calling this function more than once is safe: if the alice logger already has handlers the function returns immediately without adding duplicates.

The stream handler emits plain messages with no timestamp or level tag, so INFO output is readable on a console without noise. The file handler adds a timestamp and a fixed-width level tag for easy grepping:

2026-04-28 12:14:35 [INFO ] sweep 1 / 10: E = -1.234567890123, |ΔE| = 1.2345e-08
2026-04-28 12:14:35 [DEBUG]   site  3 / 15  local E = -1.234567890123

Parameters:

Name Type Description Default
log_file Optional[str]

Path to the log file. If None, the value of the ALICE_LOGGING environment variable is used. If that variable is also unset, the file defaults to .logging/alice_YYYY-MM-DD_HH-MM-SS.log relative to the current working directory. The parent directory is created automatically if absent.

None

Examples

import alice

# Default: write to .logging/alice_YYYY-MM-DD_HH-MM-SS.log
alice.configure_logging()

# Explicit log file path
alice.configure_logging("my_run.log")

# Via environment variable
import os
os.environ["ALICE_LOGGING"] = "/scratch/my_run.log"
alice.configure_logging()

Log Format

The stream handler (console) uses plain %(message)s with no timestamp, keeping INFO output readable. The file handler uses:

2026-05-01 12:14:35 [INFO ] sweep 1 / 10: E = -1.234567890123, |ΔE| = 1.2345e-08
2026-05-01 12:14:35 [DEBUG]   site  3 / 15  local E = -1.234567890123