diff --git a/doc/pipewire-daemon.dox b/doc/pipewire-daemon.dox index 5ffba0aa4..9781adc36 100644 --- a/doc/pipewire-daemon.dox +++ b/doc/pipewire-daemon.dox @@ -171,5 +171,7 @@ environment variables: - `PIPEWIRE_LOG_SYSTEMD=false`: Disable logging to the systemd journal. - `PIPEWIRE_LOG=`: Redirect the log to the given filename. - `PIPEWIRE_LOG_LINE=false`: Don't log filename, function, and source code line. +- `PIPEWIRE_LOG_COLOR=true/false/force`: Enable/disable color logging, and optionally force + colors even when logging to a file. */ diff --git a/spa/include/spa/support/log.h b/spa/include/spa/support/log.h index f10c04104..a2d7552be 100644 --- a/spa/include/spa/support/log.h +++ b/spa/include/spa/support/log.h @@ -284,7 +284,8 @@ do { \ /** keys can be given when initializing the logger handle */ #define SPA_KEY_LOG_LEVEL "log.level" /**< the default log level */ -#define SPA_KEY_LOG_COLORS "log.colors" /**< enable colors in the logger */ +#define SPA_KEY_LOG_COLORS "log.colors" /**< enable colors in the logger, set to "force" to enable + * colors even when not logging to a terminal */ #define SPA_KEY_LOG_FILE "log.file" /**< log to the specified file instead of * stderr. */ #define SPA_KEY_LOG_TIMESTAMP "log.timestamp" /**< log timestamps */ diff --git a/spa/plugins/support/logger.c b/spa/plugins/support/logger.c index d59049f08..6b59919f3 100644 --- a/spa/plugins/support/logger.c +++ b/spa/plugins/support/logger.c @@ -295,6 +295,7 @@ impl_init(const struct spa_handle_factory *factory, struct spa_loop *loop = NULL; const char *str, *dest = ""; bool linebuf = false; + bool force_colors = false; spa_return_val_if_fail(factory != NULL, -EINVAL); spa_return_val_if_fail(handle != NULL, -EINVAL); @@ -333,8 +334,14 @@ impl_init(const struct spa_handle_factory *factory, this->timestamp = spa_atob(str); if ((str = spa_dict_lookup(info, SPA_KEY_LOG_LINE)) != NULL) this->line = spa_atob(str); - if ((str = spa_dict_lookup(info, SPA_KEY_LOG_COLORS)) != NULL) - this->colors = spa_atob(str); + if ((str = spa_dict_lookup(info, SPA_KEY_LOG_COLORS)) != NULL) { + if (spa_streq(str, "force")) { + this->colors = true; + force_colors = true; + } else { + this->colors = spa_atob(str); + } + } if ((str = spa_dict_lookup(info, SPA_KEY_LOG_LEVEL)) != NULL) this->log.level = atoi(str); if ((str = spa_dict_lookup(info, SPA_KEY_LOG_FILE)) != NULL) { @@ -363,8 +370,9 @@ impl_init(const struct spa_handle_factory *factory, if (linebuf) setlinebuf(this->file); - if (!isatty(fileno(this->file))) + if (!isatty(fileno(this->file)) && !force_colors) { this->colors = false; + } spa_ringbuffer_init(&this->trace_rb); diff --git a/src/pipewire/pipewire.c b/src/pipewire/pipewire.c index 1192a1a7e..2d5fce24f 100644 --- a/src/pipewire/pipewire.c +++ b/src/pipewire/pipewire.c @@ -598,8 +598,11 @@ void pw_init(int *argc, char **argv[]) char *patterns = NULL; n_items = 0; - if (!support->no_color) - items[n_items++] = SPA_DICT_ITEM_INIT(SPA_KEY_LOG_COLORS, "true"); + if (!support->no_color) { + if ((str = getenv("PIPEWIRE_LOG_COLOR")) == NULL) + str = "true"; + items[n_items++] = SPA_DICT_ITEM_INIT(SPA_KEY_LOG_COLORS, str); + } items[n_items++] = SPA_DICT_ITEM_INIT(SPA_KEY_LOG_TIMESTAMP, "true"); if ((str = getenv("PIPEWIRE_LOG_LINE")) == NULL || spa_atob(str)) items[n_items++] = SPA_DICT_ITEM_INIT(SPA_KEY_LOG_LINE, "true");