Configuration reference
All knobs are settable either as get_logger(...) keyword arguments or via environment variables. Code-level arguments always win.
Core options
Argument |
Env var |
Type |
Default |
Description |
|---|---|---|---|---|
|
|
|
|
One of |
|
|
|
|
|
|
|
|
|
Path to a log file. When set, a rotating file handler is added alongside the console handler. |
|
|
|
|
Initial correlation ID set at logger creation. |
|
|
|
|
File rotation threshold. |
|
|
|
|
Number of rotated files to keep. |
|
|
|
See redaction |
Fields whose values are partially masked. |
Output and delivery options
Argument |
Env var |
Type |
Default |
Description |
|---|---|---|---|---|
|
|
|
|
Emit to the console. Set |
|
|
|
|
|
|
|
|
|
Forward records to the stdlib root logger. Leave off unless you want LogCore records handled a second time by root handlers. |
|
|
|
|
Move handler I/O to a background thread so log calls never block on disk or stderr. |
|
|
|
|
Bound on the async queue. When full, new records are dropped rather than blocking the caller; see |
Warning
With async_logging=True, records sit in a queue until a background thread
writes them. Call logcore.shutdown() before a hard exit
(os._exit, SIGKILL grace periods) — the atexit hook does not run in
those cases and buffered records are lost.
Sampling options
Argument |
Env var |
Type |
Default |
Description |
|---|---|---|---|---|
|
— |
|
|
A fully constructed |
|
|
|
— |
Shortcut: equivalent to |
— |
|
|
|
Enable tail-based sampling via env var. |
— |
|
|
|
Max records buffered per correlation_id. |
— |
|
|
|
Comma-separated level names that are never sampled. |
Important
You can pass sampler= or sample_rate=, but not both — that raises ValueError. The env-var path constructs a single Sampler from any combination of the LOGCORE_SAMPLE_* vars.
Boolean parsing for env vars
Env vars expecting booleans accept true, 1, yes, on for true and false, 0, no, off for false (case-insensitive).
Invalid environment values
Since 0.1.7, an unparseable LOGCORE_* value emits a UserWarning and falls back to the default rather than being silently ignored:
UserWarning: Ignoring invalid LOGCORE_SAMPLE_RATE='0.1x': expected a float in
[0.0, 1.0]. Using the default.
This matters most for sampling: a typo previously meant shipping 100% of your logs with nothing to indicate why.
Logger caching and reconfiguration
get_logger(name) returns a cached instance per name. Calling it again with no configuration arguments returns the same cached logger. Calling it with any configuration argument creates a new logger and replaces the cached one — and emits a UserWarning:
UserWarning: Logger 'myapp' already exists and is being replaced with new
configuration. Existing references to the old logger will no longer receive
log records.
If you see this warning, you probably want to either configure the logger once at startup or use a different name for the second instance.
Reading the current correlation ID without a logger
from logcore import get_correlation_id, set_correlation_id
set_correlation_id("req-abc")
print(get_correlation_id()) # 'req-abc'
These work without instantiating a logger — useful for middleware that runs before any logger is created.