Skip to content

Commit bd3e1ee

Browse files
committed
in_kmsg: align fields with syslog input plugin
if we want to write both the kernel logs and system logs to /var/log/messages then we don't have to use separate templates Signed-off-by: Mohd Husaam Mehdi <[email protected]>
1 parent 1d4c4dc commit bd3e1ee

File tree

1 file changed

+13
-1
lines changed

1 file changed

+13
-1
lines changed

plugins/in_kmsg/in_kmsg.c

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -165,6 +165,15 @@ static inline int process_line(const char *line,
165165

166166
flb_time_set(&ts, ctx->boot_time.tv_sec + tv.tv_sec, tv.tv_usec * 1000);
167167

168+
/* Format syslog timestamp: "Jul 03 10:31:53" */
169+
time_t real_time = ctx->boot_time.tv_sec + tv.tv_sec;
170+
struct tm tm_info;
171+
char syslog_ts[32];
172+
173+
localtime_r(&real_time, &tm_info);
174+
strftime(syslog_ts, sizeof(syslog_ts), "%b %d %H:%M:%S", &tm_info);
175+
int syslog_ts_len = strlen(syslog_ts);
176+
168177
/* Now process the human readable message */
169178
p = strchr(p, ';');
170179
if (!p) {
@@ -198,7 +207,10 @@ static inline int process_line(const char *line,
198207
FLB_LOG_EVENT_UINT64_VALUE(tv.tv_usec),
199208

200209
FLB_LOG_EVENT_CSTRING_VALUE("msg"),
201-
FLB_LOG_EVENT_STRING_VALUE((char *) p, line_len - 1));
210+
FLB_LOG_EVENT_STRING_VALUE((char *) p, line_len - 1),
211+
212+
FLB_LOG_EVENT_CSTRING_VALUE("syslog_ts"),
213+
FLB_LOG_EVENT_STRING_VALUE(syslog_ts, syslog_ts_len));
202214
}
203215

204216
if (ret == FLB_EVENT_ENCODER_SUCCESS) {

0 commit comments

Comments
 (0)