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

NAS-133335 / 25.04 / Add timestamp to structured log data #15292

Merged
merged 1 commit into from
Dec 31, 2024
Merged
Show file tree
Hide file tree
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
2 changes: 2 additions & 0 deletions src/middlewared/middlewared/logger.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
from collections import deque
from json import dumps
from dataclasses import dataclass
from .utils.time_utils import utc_now

# markdown debug is also considered useless
logging.getLogger('MARKDOWN').setLevel(logging.INFO)
Expand Down Expand Up @@ -151,6 +152,7 @@ def format(self, record: logging.LogRecord) -> str:

if structured_data:
structured_data['type'] = 'PYTHON_EXCEPTION'
structured_data['time'] = utc_now().strftime('%Y-%m-%d %H:%M:%S.%f')
json_data = dumps({'TNLOG': structured_data})
msg += f' @cee:{json_data}'

Expand Down
1 change: 1 addition & 0 deletions tests/unit/test_logger.py
Original file line number Diff line number Diff line change
Expand Up @@ -207,4 +207,5 @@ def test__syslog_exception_parameterization(working_syslog, test_message):
exc = log_line.split('@cee:')[1]
data = json.loads(exc)
assert data['TNLOG']['type'] == 'PYTHON_EXCEPTION'
assert 'time' in data['TNLOG']
assert 'FileNotFoundError' in data['TNLOG']['exception']
Loading