Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feat CCT-965: Include timezone in the logs #3475

Merged
merged 1 commit into from
Dec 2, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 14 additions & 2 deletions src/rhsm/logutil.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,15 @@

from typing import Optional, Tuple, Union, List

import datetime
import logging
import logging.handlers
import logging.config
import os
import sys
import rhsm.config


LOGFILE_DIR = "/var/log/rhsm/"
LOGFILE_PATH = os.path.join(LOGFILE_DIR, "rhsm.log")
USER_LOGFILE_DIR = os.path.join(
Expand Down Expand Up @@ -145,22 +147,32 @@ def __init__(self, name) -> None:
self.addFilter(PyWarningsLoggingFilter(name="py.warnings"))


class RhsmISO8601Formatter(logging.Formatter):
"""Ensure date & time to be in ISO8601 format and containing info about milliseconds and time zone"""

def __init__(self):
super().__init__(fmt=LOG_FORMAT)

def formatTime(self, record, datefmt=None):
return datetime.datetime.fromtimestamp(record.created).astimezone().isoformat(timespec="milliseconds")


def _get_default_rhsm_log_handler() -> (
Tuple[Union[logging.handlers.RotatingFileHandler, logging.StreamHandler], Optional[str]]
):
global _rhsm_log_handler
error: Optional[Exception] = None
if not _rhsm_log_handler:
_rhsm_log_handler, error = RHSMLogHandler(LOGFILE_PATH, USER_LOGFILE_PATH)
_rhsm_log_handler.setFormatter(logging.Formatter(LOG_FORMAT))
_rhsm_log_handler.setFormatter(RhsmISO8601Formatter())
return _rhsm_log_handler, error


def _get_default_subman_debug_handler() -> Union[None, "SubmanDebugHandler"]:
global _subman_debug_handler
if not _subman_debug_handler:
_subman_debug_handler = SubmanDebugHandler()
_subman_debug_handler.setFormatter(logging.Formatter(LOG_FORMAT))
_subman_debug_handler.setFormatter(RhsmISO8601Formatter())
return _subman_debug_handler


Expand Down