Log message improvements

This commit is contained in:
Thulinma 2019-09-19 16:10:56 +02:00
parent ab14d614f6
commit a27f65743c

View file

@ -287,84 +287,69 @@ namespace Util{
char * lineno = 0; char * lineno = 0;
char * strmNm = 0; char * strmNm = 0;
char * message = 0; char * message = 0;
while (i < 9 && buf[i] != '|' && buf[i] != 0){++i;} while (i < 9 && buf[i] != '|' && buf[i] != 0 && buf[i] < 128){++i;}
if (buf[i] == '|'){ if (buf[i] != '|'){continue;}//on parse error, skip to next message
buf[i] = 0;//insert null byte buf[i] = 0;//insert null byte
++i; ++i;
progname = buf+i;//progname starts here progname = buf+i;//progname starts here
}
while (i < 40 && buf[i] != '|' && buf[i] != 0){++i;} while (i < 40 && buf[i] != '|' && buf[i] != 0){++i;}
if (buf[i] == '|'){ if (buf[i] != '|'){continue;}//on parse error, skip to next message
buf[i] = 0;//insert null byte buf[i] = 0;//insert null byte
++i; ++i;
progpid = buf+i;//progpid starts here progpid = buf+i;//progpid starts here
}
while (i < 60 && buf[i] != '|' && buf[i] != 0){++i;} while (i < 60 && buf[i] != '|' && buf[i] != 0){++i;}
if (buf[i] == '|'){ if (buf[i] != '|'){continue;}//on parse error, skip to next message
buf[i] = 0;//insert null byte buf[i] = 0;//insert null byte
++i; ++i;
lineno = buf+i;//lineno starts here lineno = buf+i;//lineno starts here
}
while (i < 180 && buf[i] != '|' && buf[i] != 0){++i;} while (i < 180 && buf[i] != '|' && buf[i] != 0){++i;}
if (buf[i] == '|'){ if (buf[i] != '|'){continue;}//on parse error, skip to next message
buf[i] = 0;//insert null byte buf[i] = 0;//insert null byte
++i; ++i;
strmNm = buf+i;//stream name starts here strmNm = buf+i;//stream name starts here
}
while (i < 380 && buf[i] != '|' && buf[i] != 0){++i;} while (i < 380 && buf[i] != '|' && buf[i] != 0){++i;}
if (buf[i] == '|'){ if (buf[i] != '|'){continue;}//on parse error, skip to next message
buf[i] = 0;//insert null byte buf[i] = 0;//insert null byte
++i; ++i;
message = buf+i;//message starts here message = buf+i;//message starts here
}
if (!message){
message = strmNm;
strmNm = 0;
if (message){i = message-buf;}
}
//find end of line, insert null byte //find end of line, insert null byte
unsigned int j = i; unsigned int j = i;
while (j < 1023 && buf[j] != '\n' && buf[j] != 0){++j;} while (j < 1023 && buf[j] != '\n' && buf[j] != 0){++j;}
buf[j] = 0; buf[j] = 0;
//print message //print message
if (message){ if (callback){callback(kind, message, strmNm, true);}
if (callback){callback(kind, message, strmNm, true);} color_msg = color_end;
color_msg = color_end; if (colored){
if (colored){ if (!strcmp(kind, "CONF")){color_msg = CONF_msg;}
if (!strcmp(kind, "CONF")){color_msg = CONF_msg;} if (!strcmp(kind, "FAIL")){color_msg = FAIL_msg;}
if (!strcmp(kind, "FAIL")){color_msg = FAIL_msg;} if (!strcmp(kind, "ERROR")){color_msg = ERROR_msg;}
if (!strcmp(kind, "ERROR")){color_msg = ERROR_msg;} if (!strcmp(kind, "WARN")){color_msg = WARN_msg;}
if (!strcmp(kind, "WARN")){color_msg = WARN_msg;} if (!strcmp(kind, "INFO")){color_msg = INFO_msg;}
if (!strcmp(kind, "INFO")){color_msg = INFO_msg;}
}
time_t rawtime;
struct tm *timeinfo;
struct tm timetmp;
char buffer[100];
time(&rawtime);
timeinfo = localtime_r(&rawtime, &timetmp);
strftime(buffer, 100, "%F %H:%M:%S", timeinfo);
dprintf(out, "%s[%s] ", color_time, buffer);
if (progname && progpid && strlen(progname) && strlen(progpid)){
if (strmNm && strlen(strmNm)){
dprintf(out, "%s:%s%s%s (%s) ", progname, color_strm, strmNm, color_time, progpid);
}else{
dprintf(out, "%s (%s) ", progname, progpid);
}
}else{
if (strmNm && strlen(strmNm)){
dprintf(out, "%s%s%s ", color_strm, strmNm, color_time);
}
}
dprintf(out, "%s%s: %s%s", color_msg, kind, message, color_end);
if (lineno && strlen(lineno)){
dprintf(out, " (%s) ", lineno);
}
dprintf(out, "\n");
}else{
//could not be parsed as log string - print the whole thing
dprintf(out, "%s\n", buf);
} }
time_t rawtime;
struct tm *timeinfo;
struct tm timetmp;
char buffer[100];
time(&rawtime);
timeinfo = localtime_r(&rawtime, &timetmp);
strftime(buffer, 100, "%F %H:%M:%S", timeinfo);
dprintf(out, "%s[%s] ", color_time, buffer);
if (progname && progpid && strlen(progname) && strlen(progpid)){
if (strmNm && strlen(strmNm)){
dprintf(out, "%s:%s%s%s (%s) ", progname, color_strm, strmNm, color_time, progpid);
}else{
dprintf(out, "%s (%s) ", progname, progpid);
}
}else{
if (strmNm && strlen(strmNm)){
dprintf(out, "%s%s%s ", color_strm, strmNm, color_time);
}
}
dprintf(out, "%s%s: %s%s", color_msg, kind, message, color_end);
if (lineno && strlen(lineno)){
dprintf(out, " (%s) ", lineno);
}
dprintf(out, "\n");
} }
fclose(output); fclose(output);
close(in); close(in);