logger: Add a mechanism to force colourised logging

This is handy if we want to redirect to a file but have colours to make
manual parsing easier (for example with `less -R`).
This commit is contained in:
Arun Raghavan 2023-08-08 08:23:31 -04:00 committed by Wim Taymans
parent 17cda59478
commit 86bd0eb708
4 changed files with 20 additions and 6 deletions

View file

@ -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");