Skip to content

Commit

Permalink
logging: remove custom logging in ocrd_network, use explicit logger name
Browse files Browse the repository at this point in the history
  • Loading branch information
kba committed Sep 15, 2023
1 parent 0076bc1 commit 4ee7789
Show file tree
Hide file tree
Showing 7 changed files with 4 additions and 19 deletions.
2 changes: 1 addition & 1 deletion ocrd_network/ocrd_network/deployer.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@

class Deployer:
def __init__(self, config_path: str) -> None:
self.log = getLogger(__name__)
self.log = getLogger('ocrd_network.deployer')
config = validate_and_load_config(config_path)

self.data_mongo: DataMongoDB = DataMongoDB(config['database'])
Expand Down
2 changes: 1 addition & 1 deletion ocrd_network/ocrd_network/processing_server.py
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ def __init__(self, config_path: str, host: str, port: int) -> None:
super().__init__(on_startup=[self.on_startup], on_shutdown=[self.on_shutdown],
title='OCR-D Processing Server',
description='OCR-D processing and processors')
self.log = getLogger(__name__)
self.log = getLogger('ocrd_network.processing_server')
self.log.info(f"Downloading ocrd all tool json")
self.ocrd_all_tool_json = download_ocrd_all_tool_json(
ocrd_all_url="https://ocr-d.de/js/ocrd-all-tool.json"
Expand Down
2 changes: 1 addition & 1 deletion ocrd_network/ocrd_network/processing_worker.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@

class ProcessingWorker:
def __init__(self, rabbitmq_addr, mongodb_addr, processor_name, ocrd_tool: dict, processor_class=None) -> None:
self.log = getLogger(__name__)
self.log = getLogger('ocrd_network.processing_worker')
# TODO: Provide more flexibility for configuring file logging (i.e. via ENV variables)
file_handler = logging.FileHandler(f'/tmp/worker_{processor_name}_{getpid()}.log', mode='a')
logging_format = '%(asctime)s - %(name)s - %(levelname)s - %(message)s'
Expand Down
2 changes: 1 addition & 1 deletion ocrd_network/ocrd_network/processor_server.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ class ProcessorServer(FastAPI):
def __init__(self, mongodb_addr: str, processor_name: str = "", processor_class=None):
if not (processor_name or processor_class):
raise ValueError('Either "processor_name" or "processor_class" must be provided')
self.log = getLogger(__name__)
self.log = getLogger('ocrd_network.processor_server')

self.db_url = mongodb_addr
self.processor_name = processor_name
Expand Down
6 changes: 0 additions & 6 deletions ocrd_network/ocrd_network/rabbitmq_utils/constants.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,6 @@
'RECONNECT_WAIT',
'RECONNECT_TRIES',
'PREFETCH_COUNT',
'LOG_FORMAT',
'LOG_LEVEL'
]

DEFAULT_EXCHANGER_NAME: str = 'ocrd-network-default'
Expand All @@ -32,7 +30,3 @@
# QOS, i.e., how many messages to consume in a single go
# Check here: https://www.rabbitmq.com/consumer-prefetch.html
PREFETCH_COUNT: int = 1

# TODO: Integrate the OCR-D Logger once the logging in OCR-D is improved/optimized
LOG_FORMAT: str = '%(levelname) -10s %(asctime)s %(name) -30s %(funcName) -35s %(lineno) -5d: %(message)s'
LOG_LEVEL: int = logging.WARNING
4 changes: 0 additions & 4 deletions ocrd_network/ocrd_network/rabbitmq_utils/consumer.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@

from .constants import (
DEFAULT_QUEUE,
LOG_LEVEL,
RABBIT_MQ_HOST as HOST,
RABBIT_MQ_PORT as PORT,
RABBIT_MQ_VHOST as VHOST
Expand All @@ -25,9 +24,6 @@ def __init__(self, host: str = HOST, port: int = PORT, vhost: str = VHOST,
if not logger_name:
logger_name = __name__
logger = logging.getLogger(logger_name)
logging.getLogger(logger_name).setLevel(LOG_LEVEL)
# This may mess up the global logger
logging.basicConfig(level=logging.WARNING)
super().__init__(logger=logger, host=host, port=port, vhost=vhost)

self.consumer_tag = None
Expand Down
5 changes: 0 additions & 5 deletions ocrd_network/ocrd_network/rabbitmq_utils/publisher.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,6 @@
from .constants import (
DEFAULT_EXCHANGER_NAME,
DEFAULT_ROUTER,
LOG_FORMAT,
LOG_LEVEL,
RABBIT_MQ_HOST as HOST,
RABBIT_MQ_PORT as PORT,
RABBIT_MQ_VHOST as VHOST
Expand All @@ -30,9 +28,6 @@ def __init__(self, host: str = HOST, port: int = PORT, vhost: str = VHOST,
if logger_name is None:
logger_name = __name__
logger = logging.getLogger(logger_name)
logging.getLogger(logger_name).setLevel(LOG_LEVEL)
# This may mess up the global logger
logging.basicConfig(level=logging.WARNING)
super().__init__(logger=logger, host=host, port=port, vhost=vhost)

self.message_counter = 0
Expand Down

0 comments on commit 4ee7789

Please sign in to comment.