Commit Graph

1092 Commits

Author SHA1 Message Date
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 472eaf911b "config.h" need not and should not be included in any header
config.h is included in the source file before including the
header that uses it.
2021-06-25 23:53:53 +01:00
João Valverde 7aae691f7d wsutil: Rewrite ws_assert() to minimize dependencies
This includes as little as possible in the assertion header, so
that it can be included globally in every file without pulling
any unwanted definitions. In particular pulling stdlib.h is
avoided because that can have side effects if it wants to
include non-portable extensions.

It is possible to have side-effects from include glib.h too, for
example because of G_LOG_DOMAIN.

These side-effects are usually avoidable with careful ordering
of pre-processor directives but with multiple levels of indirections
it can be hard to track. Better to make it robust to these kinds
of failures in the first place.

Also integrate with our logger for a cohesive experience (but
keep it a private dependency).
2021-06-25 22:06:32 +00: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 129046b518 wsutil: Fix incorrect header include
wsutil should not have any dependency on epan, replace the
extraneous header.
2021-06-25 03:14:22 +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 752b0fc320 Debug: Lower priority to "noisy" for pipe spawn output
Spawn output can include very long multiline extcap arguments.
2021-06-23 17:45:44 +00: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
Dario Lombardo f62138c0d5 Fix some includes. 2021-06-22 19:25:43 +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
João Valverde c216bb85e7 wslog: Reverse order for level priority
Consistently speaking of ascending priority for higher levels
seems slightly more intuitive. Use that instead.
2021-06-21 16:03:29 +00:00
João Valverde b23d2f8519 wslog: Cleanup the filter/match logic 2021-06-21 16:03:29 +00:00
João Valverde 3256e45b4e wslog: Critical and error are always active.
The intention was that "error" and "critical" are *always*
active (always...). Do that.
2021-06-21 16:03:29 +00:00
João Valverde 256f5f6e30 wslog: "Warning" can also be set as fatal 2021-06-21 16:03:29 +00:00
Pascal Quantin 3ea51dba87 NGAP: fix dissection of multiple NGAP messages in the same HTTP2 packet
Also add dissection for more containers
2021-06-21 13:33:55 +00:00
João Valverde 7dea683bf1 wslog: Shorten ws_log_message_is_active() name 2021-06-21 00:07:21 +00:00
Guy Harris 72b2cf6672 ws_assert: remove a stray semicolon at the end of an inline function. 2021-06-19 03:04:49 +00:00
João Valverde b4eddd32c1 wslog: Set registered name earlier 2021-06-19 02:07:34 +01:00
João Valverde dddb33e398 wslog: Be more obvious in the log that the domain is unset
Currently we are not filtering the unset (NULL) domain, on
the assumption that every log call should belong to a defined
domain.

However there are still many places in the codebase where this isn't
true and the fact that the null/default domain name is omitted from
the output and never filtered is probably surprising and user-unfriendly.
Users might understandably assume the filtering is buggy.

Give an indication, such as (none)-MESSAGE, to make this more
obvious.
2021-06-19 02:07:34 +01:00
João Valverde 7f17d18012 wslog: Fix domain filtering
Fixes 051a74378d.
2021-06-19 01:17:05 +01:00
João Valverde a6738d72a0 wslog: Add support for inverted debug matches
The --log-debug and --log-noisy now accepts a '!' to invert the
match and disable the debug (noisy respectively) log level for
the listed domains.

Note this is different from --log-domains, that option
enables/disables the entire log domain itself, regardless of log
level.
2021-06-18 10:43:39 +01:00
João Valverde 051a74378d wslog: Use NULL for empty/default domain 2021-06-18 10:43:39 +01:00
João Valverde c5b3842639 wslog: Add more documentation 2021-06-17 12:00:10 +01:00
João Valverde ff9acff6f2 Replace usage of GLogLevel flags everywhere
ws_log_domains.h needs to be included before wslog.h to be used
to define WS_LOG_DOMAIN. Also the definition for enum ws_log_level
needs to be exported for other APIs so move that to ws_log_domains.h
and rename the file to ws_log_defs.h to reflect the new scope.
2021-06-17 12:00:10 +01:00
João Valverde 02e34357bc wslog: Add a noisy debug level
This is intended to replace logging in dissectors that has a
debug level with #ifdef DEBUG_foo and an extra level guarded
by a #ifdef DEBUG_EXTRA_foo.

But generally it can be used as another level of granularity
for debugging output, to avoid flooding the log with too
much information with typical usage.

Rename the filter functions without the unnecessary 'str'
suffix.
2021-06-17 12:00:09 +01:00
João Valverde ac50926d6f wslog: Add a new log-debug option
Option --log-debug or WIRESHARK_LOG_DEBUG is a list
of domains that are set to a "debug" log level. This
takes precedence over the normal log level and domain
filter options.
2021-06-17 12:00:09 +01:00
João Valverde 01001485b9 wslog: Add a new log-fatal option
Enviroment variable WIRESHARK_LOG_FATAL and command line
option --log-fatal set the fatal log level. Messages with
fatal or highr priority cause the program to abort. By
default the fatal level is "error", but it can be set to
"critical" or "warning" with this option.
2021-06-17 12:00:09 +01:00
João Valverde 36c32de869 wslog: Add support for inverted domain matches
Domain filter expressions starting with '!' invert the match.
Only domains that do not match become active. Note that '!'
must be the first character in the filter and applies to the
whole expression.
2021-06-17 12:00:09 +01:00
João Valverde 05ed76d4c0 wslog: Use plain format with "message" level
Try out a simpler format with the default log level.

Don't display process and file/function information with "message"
level (experimental).
2021-06-17 12:00:09 +01:00
João Valverde 39df3ae3c0 Replace g_log() calls with ws_log() 2021-06-16 12:50:27 +00:00
Guy Harris 25a254823f wsutil: add a header that defines some "round to power of 2" macros.
Add macros to round to multiples of 2, 4, 8, 16, and 32.

Use them instead of independently defined macros.

(We don't define a general "round to a power of 2" macro to avoid the
risk of somebody passing something other than a power of 2 to it.)
2021-06-16 02:01:23 -07:00
João Valverde 2c6d897b58 wslog: Add ws_logv_full() 2021-06-15 18:51:40 +01:00
João Valverde e37b2ae637 wslog: Remove unused macro 2021-06-15 18:51:40 +01:00
João Valverde 477e7f7300 wslog: Do not filter default domain 2021-06-15 18:51:40 +01:00
João Valverde bec7b0c609 wslog: Fixup color support 2021-06-15 18:51:38 +01:00
João Valverde ac4a0c056b wslog: Use g_date_time_format() 2021-06-15 18:28:02 +01:00
João Valverde 41fd46310f wslog: Change log format to display everything
Revert from alternating between function name and file name,
show both instead.
2021-06-14 22:05:35 +00:00
João Valverde 95396973e7 wslog: Add basic color support
This is just a basic framework to improve on, if desired.
2021-06-14 22:05:35 +00:00
João Valverde 69a217b95b wslog: Use buffered I/O
Use standard buffered I/O instead of printing to a string.
This is more efficient, cleaner and allows custom output per stream.
2021-06-14 22:05:35 +00:00
João Valverde 59eff63794 wslog: Rename default log level 2021-06-14 22:05:35 +00:00
João Valverde 42c6c4781f wslog: Add a diagnostic message. 2021-06-14 22:05:35 +00:00