Commit Graph

87 Commits

Author SHA1 Message Date
João Valverde 3949d289d1 Add log init message to main() 2022-10-08 15:33:47 +00:00
João Valverde 46d018627b wslog: Improve display for UTF-8 strings
Print the valid substring as UTF-8, not ASCII+hex.
2022-10-08 10:18:08 +00:00
João Valverde 51320ae59b wsutil: Improve UTF-8 APIs for debugging
In particular add an UTF-8 specific wslog API that should
make it easier to interpret invalid encodings.
2022-10-05 19:34:47 +01:00
João Valverde 0239242fb1 wslog: Improve help output 2022-10-04 11:16:42 +01:00
João Valverde 481d3cb804 wslog: Do not leak memory 2022-10-04 10:56:40 +01:00
João Valverde 16e2aa42ee wslog: Activate message if domain is fatal
Without requiring extra options like --log-level or --log-domains.
2022-09-28 19:33:33 +00:00
João Valverde b7d15d0767 wslog: Add option to make a list of domains fatal
Add a command line option --log-fatal-domains= and environment variable
WIRESHARK_LOG_FATAL_DOMAINS that aborts the programs if a domain in
the list is logged to.

Negative matches for fatal log domains not implemented for now,
pending a relevant use-case.
2022-09-28 17:14:44 +01:00
João Valverde ad66a854a0 wslog: Print to stderr with a null error handler
For some programs (e.g: unit tests) we want to init the logging
subsystem but having to pass an error output handler is overkill
and annoying.

In that case with a NULL handler printing to stderr by default is
almost certainly the best thing to do.
2022-09-28 14:56:16 +00:00
Gerald Combs 74ec0f0816 Qt+extcap: Make our capture error dialog less noisy.
Strip the timestamps and function names from extcap errors before
displaying them in a dialog. This keeps us from spewing

```
Error by extcap pipe: ** (falcodump:24913) 15:08:20.263535 [falcodump
WARNING] extcap/falcodump.cpp:593 -- main(): cloudtrail plugin error:
failed to list objects: ExpiredToken: The provided token has expired.
status code: 400, request id: M2PYJOT4JGVAA6B9, host id:
+4V8Q+DGV+80Jd3fdc7tODyVdTRvepNgCD9zuvXeL7kzvp2oikaoi9CLMW+UKt/
aR1G2UXIqyQ8=
```

at the user.

Check for warning messages and set our dialog type accordingly.
2022-09-08 10:20:48 -07:00
John Thacker 2dd07bc5b9 glib: Bump required version to 2.50
All the currently supported distributions have at least 2.50.
Remove a version check.
2022-04-22 12:55:37 +00:00
João Valverde 18a2a6827f wslog: Refactor ws_log_set_fatal() for consistency 2022-03-26 00:15:50 +00:00
João Valverde 7afb52c479 ws_assert: refactor assertions 2022-01-05 13:31:53 +00:00
João Valverde 1dfba751e5 wslog: Replace ws_assert() 2022-01-05 13:31:52 +00:00
João Valverde f7b904f328 wslog: Convert to C99/POSIX types 2022-01-05 13:31:52 +00:00
João Valverde 3f27a830fc wslog: Use a wider type for line 2022-01-05 13:31:52 +00:00
João Valverde 60533a55ff wslog: Add WS_DEBUG_HERE() macro
Add a LOG_LEVEL_ECHO that is always active and always non-fatal.

Use that to implement a WS_DEBUG_HERE() macro for quick print outs
during debugging sessions.
2021-12-29 15:21:46 +00:00
João Valverde 81de22e81a wslog: 'struct timespec' is C11, use that 2021-12-15 15:00:59 +00:00
João Valverde fe30cf2f8a wsutil: Add portability wrapper for clock_gettime(CLOCK_REALTIME) 2021-12-15 15:00:59 +00:00
João Valverde e877460a9e Revert "The function timespec_get() is C17 so assume we have it"
This reverts commit 8b15d0e641.
2021-12-15 15:00:59 +00:00
João Valverde cf3cb3a695 wslog: Avoid logging any output to stdout
For historical reasons our logging inherited from GLib the logging of
some levels to stdout. Namely levels "info" and "debug" (to which we
added "noisy").

However this practice is discouraged because it mixes debug output
with application output for CLI tools and breaks many common usage
scenarios, like using tshark in pipes.

This change flips the logic on wslog to make logging to stderr the
default behavior.

Extcap subprocess have a hidden dependency on stdout so add that.

Some GUI users may also have a dependency on stdout. Because
GUI tools are unlikely to depend on stdout for programatic output
add another exception for wireshark GUI, to preserve backward
compatibility.
2021-12-14 12:05:41 +00:00
João Valverde 8b15d0e641 The function timespec_get() is C17 so assume we have it 2021-12-14 11:23:05 +00:00
João Valverde cace66d45d The macro 'va_copy' is C99, use that 2021-12-12 11:56:17 +00:00
João Valverde 53cded5062 wslog: Add backward compatibility with 'console.log.level'
This adds some custom logic to check if we were given
the obsolete 'console.log.level' setting from the CLI
arguments, that specified the log level using a bitmask
copied from GLib. If we find that map the bitmask to a
wslog log level.

In any case the option is not removed from the argv (unlike
other wslog arguments like --log-level, etc.).

Adds deprecation warning for 'console.log.level' printed to
the console.

Related to #17763.
2021-12-11 00:19:09 +00:00
João Valverde b6130cd970 extcap: Register log handler conditionally
This matches the original implementation and allows displaying
logs to the console, including debug information, when running
an extcap from the CLI for testing and development purposes.

This should make extcap logging bug-for-bug compatible with the
behavior before dc7f0b88bb.
2021-12-06 18:51:42 +00:00
João Valverde 25c7a1abc8 wslog: Use stdout for debug messages
Imitate the GLib logic for selecting the console output stream
according to the log level. Levels MESSAGE and above go to
stderr. INFO and below go to stdout, unless stderr is chosen
using ws_log_console_writer_set_use_stderr().

It turns out some old extcap code was subtly dependending
on this behavior.
2021-12-06 18:51:42 +00:00
João Valverde e921b804d0 Fix logging with extcaps
Extcaps require a log file when invoked in child mode. It also has
a specific flag to enable debugging, other that the wslog options.

Fix the logging to:
  1. Enable debug log level if --debug is used.
  2. Do not emit messages to the stderr if debug is enabled.

This brings extcap logging to the same feature level it had before
wslog replaced GLib logging.
2021-12-03 12:30:53 +00:00
João Valverde c92e4ff7c6 wslog: Remove (part of) a special case for the default level
Instead of removing extra log information in the log handler
for the default log level, do it in the ws_message() macro.

This means ws_log_full() will work as expected.
2021-11-15 09:22:06 +00:00
João Valverde 5680d1ae0b wsutil: Improve bytes_to_str_max() API
Have these functions accept a zero max length to mean "display
the whole byte array". Change the max length parameter to receive a
number of bytes to print, not the length of the output character
string.

Adjust the macros bytes_to_str() and bytes_to_string_punct() to
produce the same output. Add more tests. Rename the functions to
bytes_to_str_maxlen() and bytes_to_str_punct_maxlen() because this is
an API break.
2021-11-09 20:57:05 +00:00
Gerald Combs 6ae87c7cf1 wslog: Add a NULL check.
Fixes Coverity CID 1485996.
2021-11-09 09:22:53 -08:00
João Valverde e6a1225611 wslog: Alias --log-domain to --log-domains
I keep mistyping this if there is only one domain and it's annoying.
2021-09-30 13:08:32 +00:00
João Valverde a34a234cf2 wslog: Add ws_log_buffer()
Use the new API with dot11decrypt debug.
2021-09-18 10:59:10 +01:00
João Valverde 0693674494 wslog: Add function to log directly without filtering
Used to write custom logging functions.
2021-07-29 20:17:44 +01:00
João Valverde 6ab67e2aa6 wslog: Minor fixes and cleanups 2021-07-25 18:21:31 +00:00
João Valverde 6498f1fce5 wslog: Fix representation of null domain
Map "" to "(none)", besides NULL.
2021-07-09 23:43:49 +01:00
João Valverde de59975fc1 wslog: fixup copyright 2021-07-09 18:25:02 +01:00
João Valverde cb61645941 wslog: Fix comment 2021-07-09 18:24:39 +01:00
João Valverde 4124986a9c wslog: Prefer more modern time APIs
Functions clock_gettime() and timespec_get() cover all the platforms
we support with sub-second resolution in a a portable manner. Fallback
to using time().

Pass a struct timespec to the log writer callback for maximum
flexibility.
2021-06-29 14:19:55 +00:00
Guy Harris c125236e57 wslog: don't assume how big struct timeval's tv_usec is.
At least according to the Single UNIX Standard, it merely has to be big
enough to hold a value in the range [-1, 1000000], and there must be
*an* environment in which it's no *larger* than a long.

Just cast it to long, and continue to print the result of dividing it by
1000 with %03ld.
2021-06-28 07:59:33 +00:00
João Valverde 3fc5eb3f1f wslog: Replace g_date_time_format()
Calling GLib functions inside the log writer is not safe,
it might infinitely recurse or abort if g_date_time_* logs
warnings because we registered our log handler for GLib itself.
2021-06-28 00:09:30 +01:00
João Valverde ceedd7b334 wslog: Update API documentation and improve code formatting 2021-06-26 00:44:23 +01:00
João Valverde c6a920686c wslog: Check environment initialization for errors
Initialiaze the cmdarg error stream earlier.

Dumpcap also needs to know earlier if it is running in capture
child mode.
2021-06-26 00:18:26 +01:00
João Valverde c2c256f0d8 wslog: Fatal messages should always be active 2021-06-26 00:18:26 +01:00
João Valverde 53704fb971 wsutil: Rewrite ws_log() to minimize dependencies
Minimizing the dependencies on other wsutil and GLib functions
reduces the chance that we will have a weird recursion pattern
in wslog and makes the code easier to analyze.
2021-06-25 22:06:32 +00:00
João Valverde cd05ec7232 wslog: Register log handler with GLib
This avoids having to manage two different implementations.
For example with this change GLib functions will terminate
if Wireshark's fatal log level is set to a matching level
and the --log-file option will also output messages from
GLib itself.
2021-06-24 02:31:42 +01:00
João Valverde a370024ca9 wslog: Fix initialization with invalid environment
We can't write to stderr outside of the default writer context.
Wireshark and tshark will block if we do that and dumpcap is
running as capture child.
2021-06-24 02:26:28 +01:00
João Valverde eb3417e38f wslog: Slight color and format change
This changes color use to be the very similar with GLib to
maintain familiarity. The only difference is that Message
and Info use a different color than Debug.

Also use the more familiar format of <domain> <level> instead
of <level> <domain>.
2021-06-24 00:06:19 +01:00
João Valverde 7bc3a5629e wslog: Fix crash using a custom log file
Add missing va_copy() call.
2021-06-23 17:09:24 +00:00
João Valverde 2080661e88 wslog: Documentation fixups 2021-06-21 22:39:54 +01:00
João Valverde 585ddc9283 wslog: Format and color amendments 2021-06-21 22:25:47 +01:00
João Valverde 759bb234d0 wslog: Check if we are initialized and add missing inits
Instead of receiving the program name from GLib, pass it explicitly
to ws_log_init() instead  and use that to initialize the GLib program
name.

ws_log_parse_args() will now exit the program when it encounters an
argument error if exit_failure >= 0.
2021-06-21 16:03:29 +00:00