summaryrefslogtreecommitdiffstats
path: root/lib/zlog_targets.c (follow)
Commit message (Collapse)AuthorAgeFilesLines
* lib: make a few log symbols accessibleDavid Lamparter2021-06-181-1/+0
| | | | | | Might've made a few things too many `static` there. Signed-off-by: David Lamparter <equinox@diac24.net>
* lib: include `\n` in zlog_msg_text()David Lamparter2021-06-181-12/+8
| | | | | | | 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>
* lib: use fbuf for zlog_msg_ts()David Lamparter2021-06-181-4/+10
| | | | Signed-off-by: David Lamparter <equinox@diac24.net>
* lib: fix possible assert() fail in zlog_fd()David Lamparter2021-04-211-26/+34
| | | | | | | | | | | | | | | | | If the last message in a batched logging operation isn't printed due to priority, this skips the code that flushes prepared messages through writev() and can trigger the assert() at the end of zlog_fd(). Since any logmsg above info priority triggers a buffer flush, running into this situation requires a log file target configured for info priority, at least 1 message of info priority buffered, a debug message buffered after that, and then a buffer flush (explicit or due to buffer full). I haven't seen this chain of events happen in the wild, but it needs fixing anyway. Signed-off-by: David Lamparter <equinox@diac24.net>
* *: require semicolon after DEFINE_MTYPE & coDavid Lamparter2021-03-171-6/+6
| | | | | | | | | | | | | | | | | Back when I put this together in 2015, ISO C11 was still reasonably new and we couldn't require it just yet. Without ISO C11, there is no "good" way (only bad hacks) to require a semicolon after a macro that ends with a function definition. And if you added one anyway, you'd get "spurious semicolon" warnings on some compilers... With C11, `_Static_assert()` at the end of a macro will make it so that the semicolon is properly required, consumed, and not warned about. Consistently requiring semicolons after "file-level" macros matches Linux kernel coding style and helps some editors against mis-syntax'ing these macros. Signed-off-by: David Lamparter <equinox@diac24.net>
* lib: fix possible null dereference in zlogQuentin Young2020-09-081-2/+3
| | | | | | | | | | In some cases one or both of the zlog targets in use here can be null, we need to check for that. Interestingly it appears we don't crash even when this is the case. Undefined behavior ftw Signed-off-by: Quentin Young <qlyoung@nvidia.com>
* lib/log: re-add log filteringDavid Lamparter2020-04-011-2/+2
| | | | | | | | This is most of the old code bolted on top of the new "backend" infrastructure. It just wraps around zlog_fd() with the string search. Originally-by: Stephen Worley <sworley@cumulusnetworks.com> Signed-off-by: David Lamparter <equinox@diac24.net>
* lib: mark some allocations as "active at exit"David Lamparter2020-04-011-4/+12
| | | | | | | | | In some cases we really don't want to clean up things even when exiting (i.e. to keep the logging subsystem going.) This adds a flag on MGROUPs to indicate that. [v2: add "(active at exit)" marker text to debug memstats-at-exit] Signed-off-by: David Lamparter <equinox@diac24.net>
* lib: rewrite zlog lock-free & TLS-bufferedDavid Lamparter2020-04-011-0/+566
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>