Skip to content
Snippets Groups Projects
Commit 9ca120f2 authored by Simon McVittie's avatar Simon McVittie
Browse files

capture-libs: Add a --level-prefix option


This will allow the output of capsule-capture-libs (and in principle
other tools) to be piped to a log handler such as `logger --prio-prefix`,
`systemd-cat --level-prefix=true` or `srt-logger --parse-level-prefix`
which will filter or format the messages according to their severity.

As currently implemented, fatal errors are emitted as LOG_ERR, warnings
are LOG_WARNING, and all debug messages are LOG_DEBUG. A facility such
as LOG_USER is not included: this is optional for logger(1), and not
allowed for systemd-cat(1) and srt-logger.

steamrt/tasks#444

Signed-off-by: default avatarSimon McVittie <smcv@collabora.com>
parent 02f9c850
No related branches found
No related tags found
No related merge requests found
...@@ -111,6 +111,7 @@ enum ...@@ -111,6 +111,7 @@ enum
OPTION_COMPARE_BY, OPTION_COMPARE_BY,
OPTION_CONTAINER, OPTION_CONTAINER,
OPTION_DEST, OPTION_DEST,
OPTION_LEVEL_PREFIX,
OPTION_LIBRARY_KNOWLEDGE, OPTION_LIBRARY_KNOWLEDGE,
OPTION_LINK_TARGET, OPTION_LINK_TARGET,
OPTION_NO_GLIBC, OPTION_NO_GLIBC,
...@@ -140,6 +141,7 @@ static struct option long_options[] = ...@@ -140,6 +141,7 @@ static struct option long_options[] =
{ "container", required_argument, NULL, OPTION_CONTAINER }, { "container", required_argument, NULL, OPTION_CONTAINER },
{ "dest", required_argument, NULL, OPTION_DEST }, { "dest", required_argument, NULL, OPTION_DEST },
{ "help", no_argument, NULL, 'h' }, { "help", no_argument, NULL, 'h' },
{ "level-prefix", no_argument, NULL, OPTION_LEVEL_PREFIX },
{ "library-knowledge", required_argument, NULL, OPTION_LIBRARY_KNOWLEDGE }, { "library-knowledge", required_argument, NULL, OPTION_LIBRARY_KNOWLEDGE },
{ "link-target", required_argument, NULL, OPTION_LINK_TARGET }, { "link-target", required_argument, NULL, OPTION_LINK_TARGET },
{ "no-glibc", no_argument, NULL, OPTION_NO_GLIBC }, { "no-glibc", no_argument, NULL, OPTION_NO_GLIBC },
...@@ -249,6 +251,8 @@ static void usage (int code) ...@@ -249,6 +251,8 @@ static void usage (int code)
"\tdeciding which libraries are needed [default: /]\n" ); "\tdeciding which libraries are needed [default: /]\n" );
fprintf( fh, "--dest=LIBDIR\n" fprintf( fh, "--dest=LIBDIR\n"
"\tCreate symlinks in LIBDIR [default: .]\n" ); "\tCreate symlinks in LIBDIR [default: .]\n" );
fprintf( fh, "--level-prefix\n"
"\tAdd severity prefixes such as <3> to output\n" );
fprintf( fh, "--library-knowledge=FILE\n" fprintf( fh, "--library-knowledge=FILE\n"
"\tLoad information about known libraries from a" "\tLoad information about known libraries from a"
"\t.desktop-style file at FILE, overriding --compare-by.\n" ); "\t.desktop-style file at FILE, overriding --compare-by.\n" );
...@@ -1356,6 +1360,10 @@ main (int argc, char **argv) ...@@ -1356,6 +1360,10 @@ main (int argc, char **argv)
option_link_target = optarg; option_link_target = optarg;
break; break;
case OPTION_LEVEL_PREFIX:
capsule_level_prefix = 1;
break;
case OPTION_PRINT_LD_SO: case OPTION_PRINT_LD_SO:
puts( LD_SO ); puts( LD_SO );
goto out; goto out;
......
...@@ -48,6 +48,7 @@ enum ...@@ -48,6 +48,7 @@ enum
extern unsigned long debug_flags; extern unsigned long debug_flags;
void set_debug_flags (const char *control); void set_debug_flags (const char *control);
extern int capsule_level_prefix;
void capsule_log (int log_level, const char *fmt, ...) __attribute__((__format__(__printf__, 2, 3))); void capsule_log (int log_level, const char *fmt, ...) __attribute__((__format__(__printf__, 2, 3)));
void capsule_logv (int log_level, const char *fmt, va_list ap) __attribute__((__format__(__printf__, 2, 0))); void capsule_logv (int log_level, const char *fmt, va_list ap) __attribute__((__format__(__printf__, 2, 0)));
......
...@@ -28,6 +28,7 @@ ...@@ -28,6 +28,7 @@
#include "debug.h" #include "debug.h"
#include "utils.h" #include "utils.h"
int capsule_level_prefix = 0;
unsigned long debug_flags; unsigned long debug_flags;
// ========================================================================== // ==========================================================================
...@@ -734,6 +735,8 @@ _capsule_basename (const char *path) ...@@ -734,6 +735,8 @@ _capsule_basename (const char *path)
* @ap: Arguments for @fmt * @ap: Arguments for @fmt
* *
* Log the message @fmt, substituting the given arguments. * Log the message @fmt, substituting the given arguments.
* If enabled globally, a severity prefix compatible with
* `systemd-cat --level-prefix=true` is prepended.
* The basename of argv[0] is prepended, similar to warnx(). * The basename of argv[0] is prepended, similar to warnx().
* A newline is appended automatically and should not be included in @fmt. * A newline is appended automatically and should not be included in @fmt.
* *
...@@ -746,6 +749,10 @@ capsule_logv( int severity, const char *fmt, va_list ap ) ...@@ -746,6 +749,10 @@ capsule_logv( int severity, const char *fmt, va_list ap )
{ {
/* libcapsule tools are single-threaded, so it's an acceptable /* libcapsule tools are single-threaded, so it's an acceptable
* simplification that we do not emit the whole message atomically. */ * simplification that we do not emit the whole message atomically. */
if( capsule_level_prefix )
fprintf( stderr, "<%d>", severity );
fprintf( stderr, "%s: ", program_invocation_short_name ); fprintf( stderr, "%s: ", program_invocation_short_name );
vfprintf( stderr, fmt, ap ); vfprintf( stderr, fmt, ap );
fputc( '\n', stderr ); fputc( '\n', stderr );
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment