A logging signal in practice
Getting familiar with the logging signal theory is great; now it's time to put it into practice. Before using OpenTelemetry logging in the grocery store, let's take a minute to move the configuration code into the common.py
module:
common.py
import logging from opentelemetry.sdk._logs.export import ConsoleLogExporter, BatchLogProcessor from opentelemetry.sdk._logs import ( LogEmitterProvider, OTLPHandler, set_log_emitter_provider, ) def configure_logger(name, version): provider = LogEmitterProvider(resource=Resource.create()) set_log_emitter_provider(provider) exporter = ConsoleLogExporter() provider.add_log_processor(BatchLogProcessor(exporter)) logger = logging.getLogger(name) logger.setLevel(logging.DEBUG) ...