Skip to content

log FEATURE timestamp and optional Location on stderr log entries - #1832

Merged
michalvasko merged 1 commit into
CESNET:develfrom
niklas-moser:log-timestamp-location
Oct 23, 2026
Merged

michalvasko merged 1 commit into
CESNET:develfrom
niklas-moser:log-timestamp-location

Conversation

@niklas-moser

@niklas-moser niklas-moser commented Oct 21, 2026 •

Copy link
Copy Markdown
Contributor

np2log() prints "[INF]: NP: " to stderr, with no timestamp and nothing identifying the emitting element. O-RAN WG11 (R004 clause 8.4.2 Table 8-2, referring to the O-RAN Security Requirements Specification) requires every security log entry to carry its date and time and a Location field holding the address of the element that emitted it. Deployments currently prepend a timestamp outside the server, typically by forking date(1) once per line, which still leaves the Location field missing.

After review, there is no compile-time option any more:

  • Every stderr log entry starts with its timestamp, taken with np_gettimespec(1) and formatted with ly_time_ts2str().
  • If the NETCONF_LOG_LOCATION environment variable is set and not empty, the entry also carries [Location=<value>]. Otherwise no location is printed.
[2026-08-19T02:28:24.123456789+02:00] [INF]: NP: Session 80: thread 1 event new RPC.
[2026-08-19T02:28:24.123456789+02:00] [INF] [Location=10.148.135.52]: NP: Session 80: thread 1 event new RPC.

The message is expanded with vasprintf() first instead of being spliced into a format string. syslog is left alone. The environment variable is documented in the README.

Built with no warnings against libyang 6.4.13, libnetconf2 4.6.4 and sysrepo 5.2.28. make format-check passes with uncrustify 0.77.1. All tests pass except test_sub_ntf_advanced, which fails the same way on the base commit (Module "ietf-netconf" feature "writable-running" not enabled in sysrepo).

🤖 Generated with Claude Code

@niklas-moser
niklas-moser force-pushed the log-timestamp-location branch from 051a379 to d0f9478 Compare October 21, 2026 10:02

@michalvasko michalvasko left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Depending on what we agree on exactly, it would be best not to use any new compilation macros and enable customization by other means. Also, the new env variable needs to be documented in the README.

Comment thread src/log.c Outdated
Comment thread src/log.c Outdated
@niklas-moser niklas-moser changed the title log FEATURE optional ISO 8601 timestamp and Location field on log entries log FEATURE timestamp and optional Location on stderr log entries Oct 21, 2026
@niklas-moser
niklas-moser force-pushed the log-timestamp-location branch from d0f9478 to b9776ed Compare October 21, 2026 14:48
@niklas-moser

Copy link
Copy Markdown
Contributor Author

Agree with the changes and updated the PR. Now working without a macro compilation time extension and changing default behaviour only for the timestamp in the logs.

Comment thread src/log.c Outdated
np2log() prints no timestamp and nothing identifying the emitting
element, so deployments prepend one outside the server, typically by
forking date(1) once per line. O-RAN WG11 requires both on every
security log entry.

Every stderr log entry now starts with its date and time. If the
NETCONF_LOG_LOCATION environment variable is set, the entry also
carries "[Location=<value>]":

  [2026-08-19T02:28:24.123456789+02:00][INF][Location=10.148.135.52]: NP: Session 80: thread 1 event new RPC.

The message is expanded with vasprintf() first instead of being spliced
into a format string. syslog is left alone.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@niklas-moser
niklas-moser force-pushed the log-timestamp-location branch from b9776ed to ff79c20 Compare October 22, 2026 10:33
@michalvasko
michalvasko merged commit 31b3520 into CESNET:devel Oct 23, 2026
7 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants