Logging Configuration Tutorial
Comprehensive logging is integrated across all protocol layers in V2X FlexStack to aid in protocol debugging, packet tracing, and security validation.
Python Logging Setup
Basic Logging
The simplest way to configure logging in Python is via logging.basicConfig:
import logging
# Set root logger level to INFO or DEBUG
logging.basicConfig(
level=logging.INFO,
format="%(asctime)s [%(levelname)s] (%(name)s) %(message)s"
)
Logger Names
Each component logs under its own logger name:
Logger name |
Component |
|---|---|
|
GeoNetworking router: packet handling, location table, forwarding, Beacons |
|
BTP router: port registration and header processing |
|
Signing and verification (ETSI TS 103 097) |
|
PKI client: enrolment, authorization, trust lists, transport |
|
CA basic service: CAM generation and reception |
|
DEN service |
|
VRU Awareness basic service |
|
Local Dynamic Map |
|
gpsd location service |
File-Based Configuration (logging.ini)
To configure each logger separately, use a configuration file:
[loggers]
keys=root,geonet,ca_basic_service
[handlers]
keys=consoleHandler,fileHandler
[formatters]
keys=standardFormatter
[logger_root]
level=INFO
handlers=consoleHandler
[logger_geonet]
level=DEBUG
handlers=fileHandler
qualname=geonet
propagate=0
[logger_ca_basic_service]
level=INFO
handlers=consoleHandler
qualname=ca_basic_service
propagate=0
[handler_consoleHandler]
class=StreamHandler
level=DEBUG
formatter=standardFormatter
args=(sys.stdout,)
[handler_fileHandler]
class=FileHandler
level=DEBUG
formatter=standardFormatter
args=('v2x_node.log', 'a')
[formatter_standardFormatter]
format=%(asctime)s - %(name)s - %(levelname)s - %(message)s
Load this configuration at application startup:
import logging.config
logging.config.fileConfig('logging.ini')