.. _logging_tutorial: ===================================== 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``: .. code-block:: python 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: .. list-table:: :widths: 35 65 :header-rows: 1 * - Logger name - Component * - ``geonet`` - GeoNetworking router: packet handling, location table, forwarding, Beacons * - ``btp`` - BTP router: port registration and header processing * - ``security`` - Signing and verification (ETSI TS 103 097) * - ``pki`` and ``flexstack.security.pki_client.*`` - PKI client: enrolment, authorization, trust lists, transport * - ``ca_basic_service`` - CA basic service: CAM generation and reception * - ``denm_service`` - DEN service * - ``vru_basic_service`` - VRU Awareness basic service * - ``local_dynamic_map`` - Local Dynamic Map * - ``GPSDLocationService`` - gpsd location service File-Based Configuration (`logging.ini`) ---------------------------------------- To configure each logger separately, use a configuration file: .. code-block:: ini [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: .. code-block:: python import logging.config logging.config.fileConfig('logging.ini')