Added support for MIST_COLOR and MIST_LOG_SYSTEMD environment variables to affect logging
This commit is contained in:
parent
8be233ccb2
commit
98b10473a4
1 changed files with 21 additions and 9 deletions
14
lib/util.cpp
14
lib/util.cpp
|
@ -277,7 +277,8 @@ namespace Util{
|
||||||
/// calling the given callback for each valid message. Closes the file descriptor on read error
|
/// calling the given callback for each valid message. Closes the file descriptor on read error
|
||||||
void logParser(int in, int out, bool colored,
|
void logParser(int in, int out, bool colored,
|
||||||
void callback(const std::string &, const std::string &, const std::string &, uint64_t, bool)){
|
void callback(const std::string &, const std::string &, const std::string &, uint64_t, bool)){
|
||||||
|
if (getenv("MIST_COLOR")){colored = true;}
|
||||||
|
bool sysd_log = getenv("MIST_LOG_SYSTEMD");
|
||||||
char buf[1024];
|
char buf[1024];
|
||||||
FILE *output = fdopen(in, "r");
|
FILE *output = fdopen(in, "r");
|
||||||
char *color_time, *color_msg, *color_end, *color_strm, *CONF_msg, *FAIL_msg, *ERROR_msg,
|
char *color_time, *color_msg, *color_end, *color_strm, *CONF_msg, *FAIL_msg, *ERROR_msg,
|
||||||
|
@ -356,6 +357,16 @@ namespace Util{
|
||||||
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;}
|
||||||
}
|
}
|
||||||
|
if (sysd_log){
|
||||||
|
if (!strcmp(kind, "CONF")){dprintf(out, "<5>");}
|
||||||
|
if (!strcmp(kind, "FAIL")){dprintf(out, "<0>");}
|
||||||
|
if (!strcmp(kind, "ERROR")){dprintf(out, "<1>");}
|
||||||
|
if (!strcmp(kind, "WARN")){dprintf(out, "<2>");}
|
||||||
|
if (!strcmp(kind, "INFO")){dprintf(out, "<5>");}
|
||||||
|
if (!strcmp(kind, "VERYHIGH") || !strcmp(kind, "EXTREME") || !strcmp(kind, "INSANE") || !strcmp(kind, "DONTEVEN")){
|
||||||
|
dprintf(out, "<7>");
|
||||||
|
}
|
||||||
|
}else{
|
||||||
time_t rawtime;
|
time_t rawtime;
|
||||||
struct tm *timeinfo;
|
struct tm *timeinfo;
|
||||||
struct tm timetmp;
|
struct tm timetmp;
|
||||||
|
@ -364,6 +375,7 @@ namespace Util{
|
||||||
timeinfo = localtime_r(&rawtime, &timetmp);
|
timeinfo = localtime_r(&rawtime, &timetmp);
|
||||||
strftime(buffer, 100, "%F %H:%M:%S", timeinfo);
|
strftime(buffer, 100, "%F %H:%M:%S", timeinfo);
|
||||||
dprintf(out, "%s[%s] ", color_time, buffer);
|
dprintf(out, "%s[%s] ", color_time, buffer);
|
||||||
|
}
|
||||||
if (progname && progpid && strlen(progname) && strlen(progpid)){
|
if (progname && progpid && strlen(progname) && strlen(progpid)){
|
||||||
if (strmNm && strlen(strmNm)){
|
if (strmNm && strlen(strmNm)){
|
||||||
dprintf(out, "%s:%s%s%s (%s) ", progname, color_strm, strmNm, color_time, progpid);
|
dprintf(out, "%s:%s%s%s (%s) ", progname, color_strm, strmNm, color_time, progpid);
|
||||||
|
|
Loading…
Add table
Reference in a new issue