Skip to content

Commit

Permalink
Feat CCT-965: Include timezone in the logs
Browse files Browse the repository at this point in the history
In `subscription-manager/src/rhsm/logutil.py`i:

* New loggin formater class `RhsmISO8601Formatter` was made
to ensure that time stamp entry is in ISO-8810 format and
that it contains info about milliseconds and time zone.

* Then variable `LOG_FORMATTER` is made and `RhsmISO8601Formatter(LOG_FORMAT)`
is assigned to it. Then distributed to places where `.setFormatter(Formatter(LOG_FORMAT, ...))` occured.

CARD CCT-965
  • Loading branch information
mgrunwal committed Nov 26, 2024
1 parent 04c1bee commit 4c09251
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 2 deletions.
5 changes: 5 additions & 0 deletions note.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
Today:
- detailed iteration of my mailbox -> finished some forgotten undone "formal" tasks (e.g. CITI card activation)
- CCT-965: finding out solution for impossibility to simply have microseconds rounded to millisecons and simultaneously time zone in log timestamp
- CSI retro & prioritization meetings

15 changes: 13 additions & 2 deletions src/rhsm/logutil.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,15 @@
import os
import sys
import rhsm.config
import datetime


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

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


LOGFILE_DIR = "/var/log/rhsm/"
LOGFILE_PATH = os.path.join(LOGFILE_DIR, "rhsm.log")
Expand All @@ -30,6 +39,8 @@
"%(threadName)s @%(filename)s:%(lineno)d - %(message)s"
)

LOG_FORMATTER = RhsmISO8601Formatter(LOG_FORMAT)

_rhsm_log_handler: Optional["RHSMLogHandler"] = None
_subman_debug_handler: Optional["SubmanDebugHandler"] = None
log: Optional[logging.Logger] = None
Expand Down Expand Up @@ -152,15 +163,15 @@ def _get_default_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(LOG_FORMATTER)
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(LOG_FORMATTER)
return _subman_debug_handler


Expand Down

0 comments on commit 4c09251

Please sign in to comment.