Learn how to setup logs in your Python application.
Open the Vigilant dashboard and generate an API key.
Initialize the Vigilant SDK in your Python application. Vigilant automatically captures print statements.
from vigilant import init_vigilant
init_vigilant(
name="backend",
token="tk_1234567890" # Use your API key from the dashboard
)
The Vigilant SDK provides several functions to log messages directly. You can use these functions to add custom attributes to the log messages.
from vigilant import log_info, log_debug, log_warn, log_error, log_trace
# Log a custom message at different log levels
log_info("Log an info message")
log_debug("Log a debug message")
log_warn("Log a warning message")
log_error("Log an error message")
log_trace("Log a trace message")
# Log with a custom attribute
log_info("Log an info message", {"user": "123"})
log_debug("Log a debug message", {"user": "123"})
log_warn("Log a warning message", {"user": "123"})
log_error("Log an error message", {"user": "123"})
log_trace("Log a trace message", {"user": "123"})
You can wrap parts of your code in a callback to add custom attributes to all log messages in the callstack.
from vigilant import add_attributes, log_info, log_debug, log_warn, log_error, log_trace
# All logs in the callback will have the user attribute set to 123
add_attributes({"user": "123"}, lambda: (
log_info("Log an info message"),
log_debug("Log a debug message"),
log_warn("Log a warning message"),
log_error("Log an error message"),
log_trace("Log a trace message")
))
The Vigilant SDK exposes a few setup options when you initialize it.
from vigilant import init_vigilant
init_vigilant(
# Disable all functionality
noop=True,
# Disable automatic capture of logs, only direct logs are captured
autocapture=False,
# Disable logging to the console
passthrough=False,
# Add global attributes to all logs
attributes={"env": "prod"},
)