@@ -45,7 +45,7 @@ class BaseLogOutput : public ILogOutput {
4545 uint64_t count = 0 ;
4646 time_t ts = 0 ;
4747 int log_file_fd;
48- struct iovec level_prefix[ALOG_AUDIT + 1 ], level_suffix[ ALOG_AUDIT + 1 ] ;
48+ struct iovec level_prefix[ALOG_AUDIT + 1 ];
4949
5050 constexpr BaseLogOutput (int fd = 0 )
5151 : log_file_fd(fd),
@@ -57,27 +57,11 @@ class BaseLogOutput : public ILogOutput {
5757 {(void *)ALOG_COLOR_MAGENTA , sizeof (ALOG_COLOR_MAGENTA ) - 1 },
5858 {(void *)ALOG_COLOR_CYAN , sizeof (ALOG_COLOR_CYAN ) - 1 },
5959 {(void *)ALOG_COLOR_GREEN , sizeof (ALOG_COLOR_GREEN ) - 1 },
60- },
61- level_suffix{
62- {(void *)ALOG_COLOR_RESET , sizeof (ALOG_COLOR_RESET ) - 1 },
63- {(void *)ALOG_COLOR_RESET , sizeof (ALOG_COLOR_RESET ) - 1 },
64- {(void *)ALOG_COLOR_RESET , sizeof (ALOG_COLOR_RESET ) - 1 },
65- {(void *)ALOG_COLOR_RESET , sizeof (ALOG_COLOR_RESET ) - 1 },
66- {(void *)ALOG_COLOR_RESET , sizeof (ALOG_COLOR_RESET ) - 1 },
67- {(void *)ALOG_COLOR_RESET , sizeof (ALOG_COLOR_RESET ) - 1 },
68- {(void *)ALOG_COLOR_RESET , sizeof (ALOG_COLOR_RESET ) - 1 },
6960 } {}
7061
7162 void set_level_color (int level, const char * color, size_t len) override {
7263 if (level < 0 || level > ALOG_AUDIT ) return ;
7364 level_prefix[level] = {(void *)color, len};
74- if (level_prefix[level].iov_base == nullptr ||
75- level_prefix[level].iov_len == 0 ) {
76- level_suffix[level] = {0 , 0 };
77- } else {
78- level_suffix[level] = {(void *)ALOG_COLOR_RESET ,
79- sizeof (ALOG_COLOR_RESET ) - 1 };
80- }
8165 }
8266
8367 void write (int level, const char * begin, const char * end) override {
@@ -87,9 +71,8 @@ class BaseLogOutput : public ILogOutput {
8771 .iov_base = (void *)begin,
8872 .iov_len = (size_t )(end - begin),
8973 },
90- level_suffix[level]
91- };
92- std::ignore = ::writev (log_file_fd, iov, 3 );
74+ {(void *)ALOG_COLOR_RESET , sizeof (ALOG_COLOR_RESET ) - 1 }};
75+ std::ignore = ::writev (log_file_fd, iov, 2 + !!iov[0 ].iov_len );
9376 throttle_block ();
9477 }
9578 void throttle_block () {
0 commit comments