Commit graph

27 commits

Author SHA1 Message Date
David Lamparter 5f16c640c2 lib: allow recirculating/relaying log messages
This is primarily intended for ldpd with its split-process architecture.
The LDE/LDPE subprocesses currently lose the extended zlog
functionality.

The zlog_live target already encapsulates all necessary bits for vtysh.
Reuse it for a relay function to be used in the main ldpd process.

Signed-off-by: David Lamparter <equinox@opensourcerouting.org>
2024-03-10 12:42:02 +01:00
Mark Stapp 2889d0e7a6 lib: add log immediate-mode to running config output
The immediate-mode config wasn't in the running config output;
add it.

Signed-off-by: Mark Stapp <mjs@labn.net>
2024-01-24 13:00:41 -05:00
David Lamparter acddc0ed3c *: auto-convert to SPDX License IDs
Done with a combination of regex'ing and banging my head against a wall.

Signed-off-by: David Lamparter <equinox@opensourcerouting.org>
2023-02-09 14:09:11 +01:00
David Lamparter c695bdbedb lib: apply more printf attributes
... missed some functions in the earlier commits :(

Signed-off-by: David Lamparter <equinox@opensourcerouting.org>
2023-02-01 03:00:18 +01:00
Donald Sharp f89c0aed63 *: Fix spelling of wether
Signed-off-by: Donald Sharp <sharpd@nvidia.com>
2022-04-02 07:46:19 -04:00
David Lamparter df45017f48 lib: add accessor for raw timestamp in zlog
Signed-off-by: David Lamparter <equinox@opensourcerouting.org>
2022-02-28 13:25:47 +01:00
David Lamparter ef990bd94b lib: add debug uid XXXXX-XXXXX backtrace
Looks much prettier if `libunwind` is available, but works with glibc or
libexecinfo's `backtrace()` too.

Signed-off-by: David Lamparter <equinox@opensourcerouting.org>
2021-11-10 12:36:50 +01:00
David Lamparter c6610ea98f lib: make a few log symbols accessible
Might've made a few things too many `static` there.

Signed-off-by: David Lamparter <equinox@diac24.net>
2021-06-18 21:05:21 +02:00
David Lamparter 5c58f5d336 lib: save instance number in zlog
Signed-off-by: David Lamparter <equinox@diac24.net>
2021-06-18 21:05:21 +02:00
David Lamparter 78598fd019 lib: cache PID & TID in zlog code
glibc removed its pid cache a while back, and grabbing this from TLS is
faster than repeatedly calling the kernel...

Also use `intmax_t` which is more appropriate for both PID & TID.

Signed-off-by: David Lamparter <equinox@diac24.net>
2021-06-18 21:05:21 +02:00
David Lamparter 8b94cb4388 lib: include \n in zlog_msg_text()
Since the file targets append one anyway, save them some extra work.
syslog can use `%.*s` since it's "forced" printf by API anyway.

Signed-off-by: David Lamparter <equinox@diac24.net>
2021-06-18 21:05:21 +02:00
David Lamparter 243ff228a9 lib: add RFC3164 logging timestamps
This is old-style syslog, used among other things for /dev/log.

Signed-off-by: David Lamparter <equinox@diac24.net>
2021-06-18 21:05:21 +02:00
David Lamparter f6caaa6524 lib: use fbuf for zlog_msg_ts()
Signed-off-by: David Lamparter <equinox@diac24.net>
2021-06-18 21:05:21 +02:00
David Lamparter e3daa82c18 lib: record output argument positions in zlog
printfrr() recently acquired the capability to record start/end of
formatting outputs.  Make use of this in the zlog code so logging
targets have access to this information.

(This also records how long the `[XXXXX-XXXXX][EC 9999999]` prefix was
so log targets can choose to skip over it.)

Signed-off-by: David Lamparter <equinox@diac24.net>
2021-06-18 20:56:53 +02:00
Mark Stapp f71e1ff6a9
Merge pull request #8545 from opensourcerouting/assert-our-own
*: make our own assert() actually work
2021-05-03 11:17:36 -04:00
David Lamparter 6a0eb6885b *: drop zassert.h
It's not actually working properly...

Signed-off-by: David Lamparter <equinox@opensourcerouting.org>
2021-04-23 12:06:35 +02:00
Mark Stapp 42ddefe816 libs: add api to enable immediate output of zlog
The log module buffers outgoing messages by default; add an
api to turn that off, and emit messages immediately.

Signed-off-by: Mark Stapp <mjs@voltanet.io>
2021-04-20 12:48:06 -04:00
David Lamparter a3c6749860 lib: add [XXXXX-XXXXX] log prefix & config
This logs the unique ID prefix from the xref that each log message call
has, and adds on/off knobs for both EC and unique ID printing.

Signed-off-by: David Lamparter <equinox@diac24.net>
2021-03-22 12:50:27 +01:00
David Lamparter 0e3967d766 lib: remove flog() macro
It was only used in one place.

Signed-off-by: David Lamparter <equinox@diac24.net>
2021-03-22 12:50:27 +01:00
David Lamparter 960b9a5383 *: require semicolon after DEFINE_<typesafe...>
Again, see previous commits.

Signed-off-by: David Lamparter <equinox@diac24.net>
2021-03-17 06:18:39 +01:00
David Lamparter 8451921b70 *: require semicolon after DEFINE_HOOK & co.
See previous commit.

Signed-off-by: David Lamparter <equinox@diac24.net>
2021-03-17 06:18:17 +01:00
David Lamparter 2621bb8b8d lib/xref: record log message format args
Apparently you can do `#__VA_ARGS__` and it actually does something
sensible, so here we go recording the format parameters for log messages
into the xref.

This allows some more checking in xrelfo.py, e.g. hints to use `%pFX`
and co.

Signed-off-by: David Lamparter <equinox@diac24.net>
2021-02-23 16:56:58 +01:00
Emanuele Di Pascale c364a0962b lib: fix c++ usage of zlog
Since some recent commit, building c++ code attempting to use zlog_debug
(or any other level) would fail with the following complaint:

lib/zlog.h:91:3: sorry, unimplemented: non-trivial designated
initializers not supported
   };
   ^
lib/zlog.h:105:26: note: in expansion of macro ‘_zlog_ref’
 #define zlog_debug(...)  _zlog_ref(LOG_DEBUG, __VA_ARGS__)

This is due to out-of-order initialization of the xrefdata struct
fields. Setting them all in the order in which they are defined
fixes the issue.

Signed-off-by: Emanuele Di Pascale <emanuele@voltanet.io>
2021-02-22 10:38:42 +01:00
David Lamparter 131879fb92 lib/xref: add xrefs on zlog_* calls
This allows extracting a list of all log messages including their ECs
and autogenerated unique IDs for them.

Signed-off-by: David Lamparter <equinox@diac24.net>
2021-02-01 17:28:09 +01:00
David Lamparter c2527ed21b lib/zlog: fix printfrr format attribute
Signed-off-by: David Lamparter <equinox@opensourcerouting.org>
2020-04-27 09:52:41 +02:00
Renato Westphal 17e38209a5 lib, zebra: add missing extern "C" {} blocks to new header files
Signed-off-by: Renato Westphal <renato@opensourcerouting.org>
2020-04-22 23:49:22 -03:00
David Lamparter 0bdeb5e58d lib: rewrite zlog lock-free & TLS-buffered
This is a full rewrite of the "back end" logging code.  It now uses a
lock-free list to iterate over logging targets, and the targets
themselves are as lock-free as possible.  (syslog() may have a hidden
internal mutex in the C library;  the file/fd targets use a single
write() call which should ensure atomicity kernel-side.)

Note that some functionality is lost in this patch:
- Solaris printstack() backtraces are ditched (unlikely to come back)
- the `log-filter` machinery is gone (re-added in followup commit)
- `terminal monitor` is temporarily stubbed out.  The old code had a
  race condition with VTYs going away.  It'll likely come back rewritten
  and with vtysh support.
- The `zebra_ext_log` hook is gone.  Instead, it's now much easier to
  add a "proper" logging target.

v2: TLS buffer to get some actual performance

Signed-off-by: David Lamparter <equinox@diac24.net>
2020-04-01 06:53:26 +02:00