From e206e6a2e27ddbe8b9c61b60e399868f8751bc94 Mon Sep 17 00:00:00 2001 From: James Tavares Date: Tue, 15 Nov 2022 08:04:03 -0500 Subject: [PATCH] bankd, client, server: add -L option to disable log coloring When the stderr of these services is sent to syslog, for example by using systemd's StandardError=syslog, syslog's escaping of ANSI color ESC sequences in log messages really clutter the log files. This option allows log coloring to be disabled on the command line. Change-Id: I6955b0af1ceb11a4029383e32bb298ee8da7503f --- src/bankd/bankd_main.c | 7 ++++++- src/client/remsim_client_main.c | 7 ++++++- src/server/remsim_server.c | 15 ++++++++++----- 3 files changed, 22 insertions(+), 7 deletions(-) diff --git a/src/bankd/bankd_main.c b/src/bankd/bankd_main.c index 3fd4d6b..90b05d8 100644 --- a/src/bankd/bankd_main.c +++ b/src/bankd/bankd_main.c @@ -301,6 +301,7 @@ static void printf_help() " -s --permit-shared-pcsc Permit SHARED access to PC/SC readers (default: exclusive)\n" " -g --gsmtap-ip A.B.C.D Enable GSMTAP and send APDU traces to given IP\n" " -G --gsmtap-slot <0-1023> Limit tracing to given bank slot, only (default: all slots)\n" +" -L --disable-color Disable colors for logging to stderr\n" ); } @@ -325,10 +326,11 @@ static void handle_options(int argc, char **argv) { "permit-shared-pcsc", 0, 0, 's' }, { "gsmtap-ip", 1, 0, 'g' }, { "gsmtap-slot", 1, 0, 'G' }, + { "disable-color", 0, 0, 'L' }, { 0, 0, 0, 0 } }; - c = getopt_long(argc, argv, "hVd:i:p:b:n:N:I:P:sg:G:", long_options, &option_index); + c = getopt_long(argc, argv, "hVd:i:p:b:n:N:I:P:sg:G:L", long_options, &option_index); if (c == -1) break; @@ -374,6 +376,9 @@ static void handle_options(int argc, char **argv) case 'G': g_bankd->cfg.gsmtap_slot = atoi(optarg); break; + case 'L': + log_set_use_color(osmo_stderr_target, 0); + break; } } } diff --git a/src/client/remsim_client_main.c b/src/client/remsim_client_main.c index 5a23d82..f7f55e7 100644 --- a/src/client/remsim_client_main.c +++ b/src/client/remsim_client_main.c @@ -35,6 +35,7 @@ static void printf_help() " -a --atr HEXSTRING default ATR to simulate (until bankd overrides it)\n" " -r --atr-ignore-rspro Ignore any ATR from bankd; use only ATR given by -a)\n" " -e --event-script event script to be called by client\n" + " -L --disable-color Disable colors for logging to stderr\n" #ifdef USB_SUPPORT " -V --usb-vendor VENDOR_ID\n" " -P --usb-product PRODUCT_ID\n" @@ -64,6 +65,7 @@ static void handle_options(struct client_config *cfg, int argc, char **argv) { "atr", 1, 0, 'a' }, { "atr-ignore-rspro", 0, 0, 'r' }, { "event-script", 1, 0, 'e' }, + {" disable-color", 0, 0, 'L' }, #ifdef USB_SUPPORT { "usb-vendor", 1, 0, 'V' }, { "usb-product", 1, 0, 'P' }, @@ -76,7 +78,7 @@ static void handle_options(struct client_config *cfg, int argc, char **argv) { 0, 0, 0, 0 } }; - c = getopt_long(argc, argv, "hvd:i:p:c:n:a:re:" + c = getopt_long(argc, argv, "hvd:i:p:c:n:a:re:L" #ifdef USB_SUPPORT "V:P:C:I:S:A:H:" #endif @@ -122,6 +124,9 @@ static void handle_options(struct client_config *cfg, int argc, char **argv) case 'e': osmo_talloc_replace_string(cfg, &cfg->event_script, optarg); break; + case 'L': + log_set_use_color(osmo_stderr_target, 0); + break; #ifdef USB_SUPPORT case 'V': cfg->usb.vendor_id = strtol(optarg, NULL, 16); diff --git a/src/server/remsim_server.c b/src/server/remsim_server.c index 419dcad..fad0b14 100644 --- a/src/server/remsim_server.c +++ b/src/server/remsim_server.c @@ -33,9 +33,10 @@ static void handle_sig_usr1(int signal) static void print_help() { printf( " Some useful help...\n" - " -h --help This text\n" - " -V --version Print version of the program\n" - " -d --debug option Enable debug logging (e.g. DMAIN:DST2)\n" + " -h --help This text\n" + " -V --version Print version of the program\n" + " -d --debug option Enable debug logging (e.g. DMAIN:DST2)\n" + " -L --disable-color Disable colors for logging to stderr\n" ); } @@ -47,10 +48,11 @@ static void handle_options(int argc, char **argv) { "help", 0, 0, 'h' }, { "version", 0, 0, 'V' }, { "debug", 1, 0, 'd' }, - {0, 0, 0, 0} + { "disable-color", 0, 0, 'L' }, + { 0, 0, 0, 0 } }; - c = getopt_long(argc, argv, "hVd:", long_options, &option_index); + c = getopt_long(argc, argv, "hVd:L", long_options, &option_index); if (c == -1) break; @@ -66,6 +68,9 @@ static void handle_options(int argc, char **argv) printf("osmo-resmim-server version %s\n", VERSION); exit(0); break; + case 'L': + log_set_use_color(osmo_stderr_target, 0); + break; default: /* ignore */ break;