Commit Graph

33 Commits

Author SHA1 Message Date
Pauli Virtanen
2fb055f43d log: add wp_logt_checked taking WpLogTopic, to decide on debug messages
Make decision on whether to show code location in journal messages based
on whether the WpLogTopic would enable DEBUG level messages.

Add wp_logt_checked API to take WpLogTopic as input to make this
possible, and deprecate wp_log_checked.
2024-05-03 13:46:52 +00:00
Pauli Virtanen
8016ad1cec log: prepend topic to journald logs & add locations on debug levels
Logging messages are usually developed based on the stderr logging,
which shows code location and log topics as context, and especially
higher log level messages can be cryptic or useless without that
context.

This context is not shown in journalctl by default, and so usually is
missing from logs submitted by users. In principle it is available in
journalctl but requires extra work to show it.

Fix by prepending the log topic to the messages, like Pipewire logging
does. Also show code locations if log level is high enough.
2024-05-03 13:46:52 +00:00
George Kiagiadakis
8caf6a6271 log: docs: document the log topic definition macros 2024-03-12 11:55:45 +02:00
George Kiagiadakis
b106b774f8 log: fix WP_LOG_LEVEL_TRACE value in the g-i bindings
See #540
2024-03-09 17:23:32 +02:00
Pauli Virtanen
d8a345a30c log: rename back to wp_log_set_level 2024-01-13 16:33:05 +00:00
Pauli Virtanen
35c10181d7 log: forward log level patterns also to libpipewire
Use pw_log_set_level_string to set log topic levels also for libpipewire
topics.
2024-01-13 16:33:05 +00:00
Pauli Virtanen
c746e18350 log: support topic patterns also in config file log.level
Handle log topic patterns also in wp_log_set_global_level, so that they
can be specified everywhere.
2024-01-13 16:33:05 +00:00
Pauli Virtanen
7c28c226b8 log: allow dynamic log levels for WpLogTopic
Change design of WpLogTopic so that it allows for changing their log
levels at runtime.

Add wp_log_topic_register/unregister functions to track lifetime of the
topics.

Auto-register statically defined log topics.

Make the topic registration threadsafe, in case it is done from
constructors that run in a different thread than main thread.
2024-01-13 16:33:05 +00:00
Pauli Virtanen
4e17edb1ac wp: make wp_log_set_global_level public API
Applications may want to change WP log level at runtime.

Also change it to return error stataus instead of printing warnings on
error.
2023-12-24 17:58:30 +02:00
George Kiagiadakis
83e47ab7c2 tree-wide: refactor active feature checks to use _test_active_features()
Similar to 5fc7e68d10, it's wrong to test
multiple flags with a simple & operation. In some cases we had this wrong.
2023-11-08 12:23:00 +02:00
Stefan Ursella
7ee69a9a47 log: set empty string to not set log_fields
not all functions in glib returns a value for the used log fields
in this case a 'g_return_val_if_fail(..) will only set 4 fields an
set the other field to NULL which leads to a segfault

Jul 22 13:41:37 Cynap-Pro-01121508 systemd-coredump[7247]: Process 496 (wireplumber) of user 4242 dumped core.

                                                           Stack trace of thread 496:
                                                           #0  0x00007f6b2ce58e99 __strlen_avx2 (libc.so.6 + 0x150e99)
                                                           #1  0x00007f6b2cf3ebe5 g_log_writer_journald (libglib-2.0.so.0 + 0x5fbe5)
                                                           #2  0x00007f6b2d0a9316 wp_log_fields_write_to_journal (libwireplumber-0.5.so.0 + 0x2b316)
                                                           #3  0x00007f6b2d0a96f5 wp_log_writer_default (libwireplumber-0.5.so.0 + 0x2b6f5)
                                                           #4  0x00007f6b2cf3cf3e g_log_structured_array (libglib-2.0.so.0 + 0x5df3e)
                                                           #5  0x00007f6b2cf3d0ae g_log_structured_array (libglib-2.0.so.0 + 0x5e0ae)
                                                           #6  0x00007f6b2cf3d4b7 g_logv (libglib-2.0.so.0 + 0x5e4b7)
                                                           #7  0x00007f6b2cf3d7ef g_log (libglib-2.0.so.0 + 0x5e7ef)
                                                           #8  0x00007f6b29efafef get_node_by_id (libwireplumber-module-cb-ipc.so + 0x24fef)
                                                           #9  0x00007f6b29efb032 wp_cb_ipc_get_app_properties (libwireplumber-module-cb-ipc.so + 0x25032)
2023-08-01 08:30:05 +00:00
George Kiagiadakis
d755ec4f20 log: ensure that warnings from pw/spa are printed as warnings
converting a spa log level to a native log level is not trivial, it seems;
when we want to print a message, we should map 2 (WARN) to W, but when we
want to translate WIREPLUMBER_DEBUG=2 to a log level, we should map 2 to N
2023-05-25 18:25:41 +03:00
George Kiagiadakis
ae7bed5655 log: make the level name a plain character in the log_level_info struct 2023-05-19 11:04:56 +03:00
George Kiagiadakis
cbf0d7284a log: make debug level 0 enable fatal errors
We always want to show fatal errors
2023-05-19 10:58:31 +03:00
George Kiagiadakis
3034fc7c79 log: accept 0 as a level and do safety checks on the level string 2023-05-19 10:50:46 +03:00
George Kiagiadakis
4f27d18bd3 log: rename "message" level to "notice" and print criticals with "E"
Syslog calls this level "notice" and I prefer it because we use it
to display significant messages that are not warnings, but they
are not really "standard", as GLib wants them to be. There is nothing
"standard" about log messages in general.

Also, make these notice messages be enabled at debug level 2, together
with warnings. The default log.level is 2 and it is a good idea to show
notices by default too.

Finally, show them in the log with "N" and also change criticals to be
shown with "E", meaning "error"... Then promote G_LOG_LEVEL_ERROR
messages to be shown with "F", meaning "fatal", because in fact these
messages are always fatal and always call abort(). Still, keep the term
"critical" in the functions to make sure that whoever uses them is aware
that this level is only for critical conditions and not suitable to
display any kind of error.
2023-05-18 16:19:49 +03:00
George Kiagiadakis
89c31d8190 log: disable "conn.*" topic by default, like pipewire does
This topic contains traces to debug the pipewire socket protocol.
Adding this pattern allows WIREPLUMBER_DEBUG=5 to show everything
except this trace by default, which is a more reasonable amount
of trace. To enable it, it must be explicitly specified in the
WIREPLUMBER_DEBUG env variable.
2023-05-18 15:53:50 +03:00
George Kiagiadakis
17b893c266 log: always set PIPEWIRE_DEBUG 2023-05-18 13:10:13 +03:00
George Kiagiadakis
b7e4654da4 log: rename log_level_index to level_index_from_flags, for consistency 2023-05-18 13:04:33 +03:00
George Kiagiadakis
dc548a3259 log: improve the initialization process
* initialize all log-related features in a new wp_log_init() function
* remove the ability to change the log patterns later, as the log
  topics are not referenced by the log system and there is no way to
  re-initialize them with different levels (we can still implement this
  in the future, if necessary, though)
* introduce the notion of a "global log level", referenced by all topics,
  and make the topics know if they have a custom level or not, like in
  pipewire; this is necessary to be able to set the level in the config
  file, which is read later by pw_context / WpCore.
2023-05-18 12:50:52 +03:00
George Kiagiadakis
4736d56557 log: implement a log topics system, like pipewire
The intention is to make checks for enabled log topics faster.

Every topic has its own structure that is statically defined in the file
where the logs are printed from. The structure is initialized transparently
when it is first used and it contains all the log level flags for the levels
that this topic should print messages. It is then checked on the wp_log()
macro before printing the message.

Topics from SPA/PipeWire are also handled natively, so messages are printed
directly without checking if the topic is enabled, since the PipeWire and SPA
macros do the checking themselves.

Messages coming from GLib are checked inside the handler.

An internal WpLogFields object is used to manage the state of each log
message, populating all the fields appropriately from the place they
are coming from (wp_log, spa_log, glib log), formatting the message and
then printing it. For printing to the journald, we still use the glib
message handler, converting all the needed fields to GLogField on demand.
That message handler does not do any checks for the topic or the level, so
we can just call it to send the message.
2023-05-16 20:42:28 +03:00
George Kiagiadakis
e908b93f3b log: describe the syslog priority numbers for code clarity 2023-05-16 16:46:43 +03:00
George Kiagiadakis
67f1eb585f log: implement different debug level per topic, like in pipewire 2023-04-25 08:50:13 +03:00
George Kiagiadakis
0fa484ac55 log: map spa ERROR and WARN to GLib's CRITICAL and WARNING respectively
Previously we were mapping SPA ERROR to GLib WARNING and
SPA WARN to GLib MESSAGE, which has been causing some confusion.

After some careful consideration, it makes sense to change that and
leave the GLib MESSAGE level as something to be avoided. With that
change, WIREPLUMBER_DEBUG=M will still enable the MESSAGE level,
but WIREPLUMBER_DEBUG=2 will only enable the WARN level and it will
take WIREPLUMBER_DEBUG=3 to enable both the INFO and MESSAGE levels.
2023-04-25 08:50:13 +03:00
George Kiagiadakis
5412ca972f log: guard against NULL messages
if for any reason the message field is NULL, replace it with the string
"(null)" and keep going... this avoids crashing the journald logger

Fixes #124
2021-12-20 17:54:14 +02:00
Peter Hutterer
5ec2138a72 log: support strings as level selectors in WIREPLUMBER_DEBUG
This allows for WIREPLUMBER_DEBUG="D" which avoids users having to
remember which numerical value the various levels have. The strings to
select are the ones printed by the logger, i.e. UECWMIDT.
2021-11-18 12:17:19 +00:00
Pauli Virtanen
fbb66cc290 wp: implement topics in SPA log interface
Implement SPA log topic API, showing log topics as GLIB_DOMAIN,
and enabling based on WIREPLUMBER_DEBUG.
2021-10-14 23:40:59 +03:00
Wim Taymans
fb28b076a1 Revert "wp: fix spa_log_methods version"
This reverts commit 86eecfc7e1.

The logger now correctly calls the old implementation when the new
method is not implemented.
2021-10-07 10:17:15 +02:00
Pauli Virtanen
86eecfc7e1 wp: fix spa_log_methods version
Wireplumber implements version 0 of spa_log methods. Fixes logging on
current pipewire.
2021-10-04 07:00:28 +00:00
Jason Francis
ed8346e77d docs: Add brief descriptions to all functions
This ensures all of these functions are picked up by g-ir-scanner.
2021-06-02 17:38:34 +00:00
George Kiagiadakis
b812e912d2 docs: fix C API documentation to work nicely with doxygen & sphinx 2021-05-25 14:19:53 +03:00
Raghavendra
d692f06f0d docs: api: Replace hotdoc specific commands with Doxygen specific commands 2021-05-25 14:19:53 +03:00
George Kiagiadakis
257d5cba47 wp: rename debug.{h,c} to log.{h,c}
Also rename the intermediate lua api table WpDebug -> WpLog

Keeps things more consistent with the function names (wp_log*),
with the lua api (Log.*) and with pipewire using log.{h,c} as well.
After all, these functions are for logging...
2021-05-06 15:50:07 +03:00