aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorNeels Hofmeyr <neels@hofmeyr.de>2018-01-16 02:10:48 +0100
committerNeels Hofmeyr <nhofmeyr@sysmocom.de>2018-01-17 23:16:16 +0000
commitc4759885d7c2aedf310739d9a2420ae1d67a0338 (patch)
treee4d0332f27f99a02a75c75d7dbcff732ad0051cd /src
parent23d3161d4bbe80da13bf3e7afb64242dc8b7236c (diff)
cosmetic: logging: if color is disabled, don't print ""
If color output is disabled, skip the empty snprintf() to (not) clear the ANSI color. Also, no need to use a format string of "%s", just pass the string constant directly. That is a micro optimisation as well as clarification of the code. Change-Id: Ie7cb06de160830d2f8ee5718246c0fe311f68d49
Diffstat (limited to 'src')
-rw-r--r--src/logging.c11
1 files changed, 6 insertions, 5 deletions
diff --git a/src/logging.c b/src/logging.c
index 9b37bf53..e6e09e06 100644
--- a/src/logging.c
+++ b/src/logging.c
@@ -398,11 +398,12 @@ static void _output(struct log_target *target, unsigned int subsys,
goto err;
OSMO_SNPRINTF_RET(ret, rem, offset, len);
- ret = snprintf(buf + offset, rem, "%s",
- target->use_color ? "\033[0;m" : "");
- if (ret < 0)
- goto err;
- OSMO_SNPRINTF_RET(ret, rem, offset, len);
+ if (target->use_color) {
+ ret = snprintf(buf + offset, rem, "\033[0;m");
+ if (ret < 0)
+ goto err;
+ OSMO_SNPRINTF_RET(ret, rem, offset, len);
+ }
err:
buf[sizeof(buf)-1] = '\0';
target->output(target, level, buf);