Skip to content

Commit 2a709df

Browse files
author
Pat
authored
core: add compile flag to disable control chars (#5583)
Signed-off-by: Patrick Stephens <[email protected]>
1 parent 341ae83 commit 2a709df

File tree

4 files changed

+34
-5
lines changed

4 files changed

+34
-5
lines changed

CMakeLists.txt

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -545,6 +545,11 @@ if(FLB_TRACE)
545545
FLB_DEFINITION(FLB_HAVE_TRACE)
546546
endif()
547547

548+
# Disable colors and any other control characters in the output
549+
if (FLB_LOG_NO_CONTROL_CHARS)
550+
FLB_DEFINITION(FLB_LOG_NO_CONTROL_CHARS)
551+
endif()
552+
548553
if(FLB_HTTP_SERVER)
549554
FLB_OPTION(FLB_METRICS ON)
550555
FLB_DEFINITION(FLB_HAVE_METRICS)

dockerfiles/Dockerfile

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -53,10 +53,10 @@ RUN apt-get update && \
5353
&& rm -rf /var/lib/apt/lists/*
5454

5555
# Must be run from root of repo
56-
WORKDIR /tmp/fluent-bit/
56+
WORKDIR /src/fluent-bit/
5757
COPY . ./
5858

59-
WORKDIR /tmp/fluent-bit/build/
59+
WORKDIR /src/fluent-bit/build/
6060
RUN cmake -DFLB_RELEASE=On \
6161
-DFLB_TRACE=Off \
6262
-DFLB_JEMALLOC=On \
@@ -69,6 +69,7 @@ RUN cmake -DFLB_RELEASE=On \
6969
-DFLB_OUT_KAFKA=On \
7070
-DFLB_OUT_PGSQL=On \
7171
-DFLB_NIGHTLY_BUILD="$FLB_NIGHTLY_BUILD" \
72+
-DFLB_LOG_NO_CONTROL_CHARS=On \
7273
..
7374

7475
RUN make -j "$(getconf _NPROCESSORS_ONLN)"

include/fluent-bit/flb_version.h.in

Lines changed: 20 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -55,16 +55,33 @@ static inline void flb_version()
5555

5656
static inline void flb_version_banner()
5757
{
58+
const char *copyright_color = ANSI_BOLD ANSI_YELLOW;
59+
const char *bold_color = ANSI_BOLD;
60+
const char *reset_color = ANSI_RESET;
61+
62+
#ifdef FLB_LOG_NO_CONTROL_CHARS
63+
copyright_color = "";
64+
bold_color = "";
65+
reset_color = "";
66+
#else
67+
/* Only print colors to a terminal */
68+
if (!isatty(STDOUT_FILENO)) {
69+
copyright_color = "";
70+
bold_color = "";
71+
reset_color = "";
72+
}
73+
#endif // FLB_LOG_NO_CONTROL_CHARS
74+
5875
#ifdef FLB_NIGHTLY_BUILD
5976
fprintf(stderr,
6077
"%sFluent Bit v%s | NIGHTLY_BUILD=%s - DO NOT USE IN PRODUCTION!"
61-
"%s\n", ANSI_BOLD, FLB_VERSION_STR, STR(FLB_NIGHTLY_BUILD), ANSI_RESET);
78+
"%s\n", bold_color, FLB_VERSION_STR, STR(FLB_NIGHTLY_BUILD), reset_color);
6279
#else
6380
fprintf(stderr,
64-
"%sFluent Bit v%s%s\n", ANSI_BOLD, FLB_VERSION_STR, ANSI_RESET);
81+
"%sFluent Bit v%s%s\n", bold_color, FLB_VERSION_STR, reset_color);
6582
#endif
6683
fprintf(stderr, "* %sCopyright (C) 2015-2022 The Fluent Bit Authors%s\n",
67-
ANSI_BOLD ANSI_YELLOW, ANSI_RESET);
84+
copyright_color, reset_color);
6885
fprintf(stderr, "* Fluent Bit is a CNCF sub-project under the "
6986
"umbrella of Fluentd\n");
7087
fprintf(stderr, "* https://fluentbit.io\n\n");

src/flb_log.c

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -370,12 +370,18 @@ void flb_log_print(int type, const char *file, int line, const char *fmt, ...)
370370
break;
371371
}
372372

373+
#ifdef FLB_LOG_NO_CONTROL_CHARS
374+
header_color = "";
375+
bold_color = "";
376+
reset_color = "";
377+
#else
373378
/* Only print colors to a terminal */
374379
if (!isatty(STDOUT_FILENO)) {
375380
header_color = "";
376381
bold_color = "";
377382
reset_color = "";
378383
}
384+
#endif // FLB_LOG_NO_CONTROL_CHARS
379385

380386
now = time(NULL);
381387
current = localtime_r(&now, &result);

0 commit comments

Comments
 (0)