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
This commit is contained in:
James Tavares 2022-11-15 08:04:03 -05:00 committed by laforge
parent 31e8bd786b
commit e206e6a2e2
3 changed files with 22 additions and 7 deletions

View File

@ -301,6 +301,7 @@ static void printf_help()
" -s --permit-shared-pcsc Permit SHARED access to PC/SC readers (default: exclusive)\n" " -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-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" " -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' }, { "permit-shared-pcsc", 0, 0, 's' },
{ "gsmtap-ip", 1, 0, 'g' }, { "gsmtap-ip", 1, 0, 'g' },
{ "gsmtap-slot", 1, 0, 'G' }, { "gsmtap-slot", 1, 0, 'G' },
{ "disable-color", 0, 0, 'L' },
{ 0, 0, 0, 0 } { 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) if (c == -1)
break; break;
@ -374,6 +376,9 @@ static void handle_options(int argc, char **argv)
case 'G': case 'G':
g_bankd->cfg.gsmtap_slot = atoi(optarg); g_bankd->cfg.gsmtap_slot = atoi(optarg);
break; break;
case 'L':
log_set_use_color(osmo_stderr_target, 0);
break;
} }
} }
} }

View File

@ -35,6 +35,7 @@ static void printf_help()
" -a --atr HEXSTRING default ATR to simulate (until bankd overrides it)\n" " -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" " -r --atr-ignore-rspro Ignore any ATR from bankd; use only ATR given by -a)\n"
" -e --event-script <path> event script to be called by client\n" " -e --event-script <path> event script to be called by client\n"
" -L --disable-color Disable colors for logging to stderr\n"
#ifdef USB_SUPPORT #ifdef USB_SUPPORT
" -V --usb-vendor VENDOR_ID\n" " -V --usb-vendor VENDOR_ID\n"
" -P --usb-product PRODUCT_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", 1, 0, 'a' },
{ "atr-ignore-rspro", 0, 0, 'r' }, { "atr-ignore-rspro", 0, 0, 'r' },
{ "event-script", 1, 0, 'e' }, { "event-script", 1, 0, 'e' },
{" disable-color", 0, 0, 'L' },
#ifdef USB_SUPPORT #ifdef USB_SUPPORT
{ "usb-vendor", 1, 0, 'V' }, { "usb-vendor", 1, 0, 'V' },
{ "usb-product", 1, 0, 'P' }, { "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 } { 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 #ifdef USB_SUPPORT
"V:P:C:I:S:A:H:" "V:P:C:I:S:A:H:"
#endif #endif
@ -122,6 +124,9 @@ static void handle_options(struct client_config *cfg, int argc, char **argv)
case 'e': case 'e':
osmo_talloc_replace_string(cfg, &cfg->event_script, optarg); osmo_talloc_replace_string(cfg, &cfg->event_script, optarg);
break; break;
case 'L':
log_set_use_color(osmo_stderr_target, 0);
break;
#ifdef USB_SUPPORT #ifdef USB_SUPPORT
case 'V': case 'V':
cfg->usb.vendor_id = strtol(optarg, NULL, 16); cfg->usb.vendor_id = strtol(optarg, NULL, 16);

View File

@ -33,9 +33,10 @@ static void handle_sig_usr1(int signal)
static void print_help() static void print_help()
{ {
printf( " Some useful help...\n" printf( " Some useful help...\n"
" -h --help This text\n" " -h --help This text\n"
" -V --version Print version of the program\n" " -V --version Print version of the program\n"
" -d --debug option Enable debug logging (e.g. DMAIN:DST2)\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' }, { "help", 0, 0, 'h' },
{ "version", 0, 0, 'V' }, { "version", 0, 0, 'V' },
{ "debug", 1, 0, 'd' }, { "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) if (c == -1)
break; break;
@ -66,6 +68,9 @@ static void handle_options(int argc, char **argv)
printf("osmo-resmim-server version %s\n", VERSION); printf("osmo-resmim-server version %s\n", VERSION);
exit(0); exit(0);
break; break;
case 'L':
log_set_use_color(osmo_stderr_target, 0);
break;
default: default:
/* ignore */ /* ignore */
break; break;