diff --git a/bind-mount.c b/bind-mount.c
index 2757cae..84cb148 100644
--- a/bind-mount.c
+++ b/bind-mount.c
@@ -560,6 +560,9 @@ die_with_bind_result (bind_mount_result res,
bool want_errno = TRUE;
char *message;
+ if (bwrap_level_prefix)
+ fprintf (stderr, "<%d>", LOG_ERR);
+
fprintf (stderr, "bwrap: ");
va_start (args, format);
diff --git a/bubblewrap.c b/bubblewrap.c
index aeecc65..9f87e90 100644
--- a/bubblewrap.c
+++ b/bubblewrap.c
@@ -311,6 +311,7 @@ usage (int ecode, FILE *out)
" --version Print version\n"
" --args FD Parse NUL-separated args from FD\n"
" --argv0 VALUE Set argv[0] to the value VALUE before running the program\n"
+ " --level-prefix Prepend e.g. <3> to diagnostic messages\n"
" --unshare-all Unshare every namespace we support by default\n"
" --share-net Retain the network namespace (can only combine with --unshare-all)\n"
" --unshare-user Create new user namespace (may be automatically implied if not setuid)\n"
@@ -1778,6 +1779,10 @@ parse_args_recurse (int *argcp,
argv++;
argc--;
}
+ else if (strcmp (arg, "--level-prefix") == 0)
+ {
+ bwrap_level_prefix = TRUE;
+ }
else if (strcmp (arg, "--unshare-all") == 0)
{
/* Keep this in order with the older (legacy) --unshare arguments,
diff --git a/bwrap.xml b/bwrap.xml
index 3bb5082..2bfca00 100644
--- a/bwrap.xml
+++ b/bwrap.xml
@@ -96,6 +96,26 @@
Set argv[0] to the value VALUE before running the program
+
+
+
+
+ Prefix each line of diagnostic output with a numeric severity
+ level enclosed in angle brackets.
+ The severity levels used are based on the constants used by
+ syslog3:
+ for example, <4> indicates a warning,
+ because LOG_WARNING has numeric value 4.
+ Numbers smaller than 4 indicate fatal errors, and numbers larger
+ than 4 indicate informational messages.
+ These prefixes can be parsed by tools compatible with
+ logger --prio-prefix (see
+ logger1)
+ or systemd-cat --level-prefix=1 (see
+ systemd-cat1).
+
+
+ Options related to kernel namespaces:
diff --git a/tests/test-run.sh b/tests/test-run.sh
index 479e027..c58c7e1 100755
--- a/tests/test-run.sh
+++ b/tests/test-run.sh
@@ -575,4 +575,8 @@ $RUN --chdir / --chdir / true > stdout 2>&1
assert_file_has_content stdout '^bwrap: Only the last --chdir option will take effect$'
ok "warning logged for redundant --chdir"
+$RUN --level-prefix --chdir / --chdir / true > stdout 2>&1
+assert_file_has_content stdout '^<4>bwrap: Only the last --chdir option will take effect$'
+ok "--level-prefix"
+
done_testing
diff --git a/utils.c b/utils.c
index daab654..1fbab91 100644
--- a/utils.c
+++ b/utils.c
@@ -34,12 +34,17 @@
#define security_check_context(x) security_check_context ((security_context_t) x)
#endif
+bool bwrap_level_prefix = FALSE;
+
__attribute__((format(printf, 2, 0))) static void
bwrap_logv (int severity,
const char *format,
va_list args,
const char *detail)
{
+ if (bwrap_level_prefix)
+ fprintf (stderr, "<%d>", severity);
+
fprintf (stderr, "bwrap: ");
vfprintf (stderr, format, args);
diff --git a/utils.h b/utils.h
index 0851b84..ced4351 100644
--- a/utils.h
+++ b/utils.h
@@ -53,6 +53,8 @@ typedef int bool;
#define PR_SET_CHILD_SUBREAPER 36
#endif
+extern bool bwrap_level_prefix;
+
void bwrap_log (int severity,
const char *format,
...) __attribute__((format (printf, 2, 3)));