Skip to content

Commit

Permalink
cmk.message: add logging config
Browse files Browse the repository at this point in the history
Change-Id: I4221b7fa91b8edcd9a6ed6fec57f45aed39496f3
  • Loading branch information
mo-ki committed Oct 24, 2024
1 parent 96a5e9e commit 0a83fa5
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 3 deletions.
8 changes: 5 additions & 3 deletions cmk/piggyback_hub/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@

from cmk.ccc.daemon import daemonize, pid_file_lock

from cmk.messaging import QueueName
from cmk.messaging import QueueName, set_logging_level

from .config import CONFIG_QUEUE, PiggybackHubConfig, save_config_on_message
from .payload import (
Expand Down Expand Up @@ -76,7 +76,7 @@ def _parse_arguments(argv: list[str]) -> Arguments:


def _setup_logging(args: Arguments) -> logging.Logger:
logger = getLogger("cmk.piggyback_hub")
logger = getLogger(__name__)
handler: logging.StreamHandler | WatchedFileHandler = (
logging.StreamHandler(stream=sys.stderr)
if args.foreground
Expand All @@ -85,7 +85,9 @@ def _setup_logging(args: Arguments) -> logging.Logger:
handler.setFormatter(logging.Formatter("%(asctime)s [%(levelname)s] [%(process)d] %(message)s"))
logger.addHandler(handler)

logger.setLevel(VERBOSITY_MAP[min(args.verbosity, 2)])
level = VERBOSITY_MAP[min(args.verbosity, 2)]
logger.setLevel(level)
set_logging_level(level)

return logger

Expand Down
1 change: 1 addition & 0 deletions packages/cmk-messaging/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ py_library(
"cmk/messaging/_config.py",
"cmk/messaging/_connection.py",
"cmk/messaging/_constants.py",
"cmk/messaging/_logging.py",
"cmk/messaging/rabbitmq.py",
],
imports = ["."],
Expand Down
2 changes: 2 additions & 0 deletions packages/cmk-messaging/cmk/messaging/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@
QueueName,
RoutingKey,
)
from ._logging import set_logging_level

__all__ = [
"all_cme_cacert_files",
Expand All @@ -56,6 +57,7 @@
"QueueName",
"rabbitmq",
"RoutingKey",
"set_logging_level",
"site_cert_file",
"site_key_file",
"TLS_PATH_CUSTOMERS",
Expand Down
14 changes: 14 additions & 0 deletions packages/cmk-messaging/cmk/messaging/_logging.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
#!/usr/bin/env python3
# Copyright (C) 2024 Checkmk GmbH - License: GNU General Public License v2
# This file is part of Checkmk (https://checkmk.com). It is subject to the terms and
# conditions defined in the file COPYING, which is part of this source code package.
"""Logging"""

import logging

import pika


def set_logging_level(level: int, /) -> None:
"""Set the logging level for underlying library"""
logging.getLogger(pika.__name__).setLevel(level)

0 comments on commit 0a83fa5

Please sign in to comment.