diff --git a/pressure-vessel/adverb.1.md b/pressure-vessel/adverb.1.md index 6488004e6dbfe88f5c2343641fc1f31c032d79ee..d198ab62867f13009f4c3db31d04a6524a31d14b 100644 --- a/pressure-vessel/adverb.1.md +++ b/pressure-vessel/adverb.1.md @@ -159,6 +159,10 @@ exit status. : If set to `1`, increase the log verbosity up to the info level. If set to `0`, no effect. +`PRESSURE_VESSEL_LOG_WITH_TIMESTAMP` (boolean) +: If set to `1`, prepend the log entries with a timestamp. + If set to `0`, no effect. + # OUTPUT The standard output from *COMMAND* is printed on standard output. diff --git a/pressure-vessel/launch.1.md b/pressure-vessel/launch.1.md index 785aa65b07e2c3f85535748a9cca1d3ab59522aa..a5e07bdf82f0916e9d7bc870b1acece16311eb48 100644 --- a/pressure-vessel/launch.1.md +++ b/pressure-vessel/launch.1.md @@ -143,6 +143,10 @@ it set, and pass through **FONTS** from the caller. : If set to `1`, increase the log verbosity up to the info level. If set to `0`, no effect. +`PRESSURE_VESSEL_LOG_WITH_TIMESTAMP` (boolean) +: If set to `1`, prepend the log entries with a timestamp. + If set to `0`, no effect. + # OUTPUT The standard output from *COMMAND* is printed on standard output. diff --git a/pressure-vessel/launcher.1.md b/pressure-vessel/launcher.1.md index dd97cb2a30344acbe190ea223b5b8cbb6015cf96..546bc84acb78b18bc8d3cbc966d46ffd48ee0344 100644 --- a/pressure-vessel/launcher.1.md +++ b/pressure-vessel/launcher.1.md @@ -84,6 +84,10 @@ D-Bus session bus, and executes arbitrary commands as subprocesses. : If set to `1`, increase the log verbosity up to the info level. If set to `0`, no effect. +`PRESSURE_VESSEL_LOG_WITH_TIMESTAMP` (boolean) +: If set to `1`, prepend the log entries with a timestamp. + If set to `0`, no effect. + # OUTPUT **pressure-vessel-launcher** prints zero or more lines of diff --git a/pressure-vessel/utils.c b/pressure-vessel/utils.c index 1c46bda188ca440c931ee126a652230495f428ac..ba28e4c13517d6b188c4e9b40252dd8b21ba3fc3 100644 --- a/pressure-vessel/utils.c +++ b/pressure-vessel/utils.c @@ -911,6 +911,30 @@ pv_current_namespace_path_to_host_path (const gchar *current_env_path) return path_on_host; } +/** + * log_handler_with_timestamp: + * @log_domain: the log domain of the message + * @log_level: the log level of the message + * @message: the message to process + * @user_data: not used + */ +static void +pv_log_to_stderr_with_timestamp (const gchar *log_domain, + GLogLevelFlags log_level, + const gchar *message, + gpointer user_data) +{ + g_autoptr(GDateTime) date_time = g_date_time_new_now_local (); + + /* We can't use the format specifier "%f" for microseconds because it + * was introduced in GLib 2.66 and we are targeting an older version */ + g_autofree gchar *timestamp = g_date_time_format (date_time, "%T"); + + g_printerr ("%s.%06i: %s[%d]: %s\n", timestamp, + g_date_time_get_microsecond (date_time), + my_prgname, my_pid, message); +} + /** * pv_log_to_stderr: * @log_domain: the log domain of the message @@ -935,6 +959,8 @@ void pv_set_up_logging (gboolean opt_verbose) { GLogLevelFlags log_levels = G_LOG_LEVEL_WARNING | G_LOG_LEVEL_MESSAGE; + gboolean opt_timestamp = pv_boolean_environment ("PRESSURE_VESSEL_LOG_WITH_TIMESTAMP", + FALSE); gboolean opt_info = pv_boolean_environment ("PRESSURE_VESSEL_LOG_INFO", FALSE); my_pid = getpid (); @@ -947,6 +973,6 @@ pv_set_up_logging (gboolean opt_verbose) log_levels |= G_LOG_LEVEL_DEBUG | G_LOG_LEVEL_INFO; g_log_set_handler (G_LOG_DOMAIN, log_levels, - pv_log_to_stderr, + opt_timestamp ? pv_log_to_stderr_with_timestamp : pv_log_to_stderr, NULL); } diff --git a/pressure-vessel/wrap.1.md b/pressure-vessel/wrap.1.md index b31c8a603703fbbf207cdf8867fcb2629c7224da..028852c42652542336ee082ff3b56fbb2e064e37 100644 --- a/pressure-vessel/wrap.1.md +++ b/pressure-vessel/wrap.1.md @@ -249,6 +249,10 @@ The following environment variables (among others) are read by : If set to `1`, increase the log verbosity up to the info level. If set to `0`, no effect. +`PRESSURE_VESSEL_LOG_WITH_TIMESTAMP` (boolean) +: If set to `1`, prepend the log entries with a timestamp. + If set to `0`, no effect. + `PRESSURE_VESSEL_REMOVE_GAME_OVERLAY` (boolean) : If set to `1`, equivalent to `--remove-game-overlay`. If set to `0`, equivalent to `--keep-game-overlay`.