Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 4e3e62b

Browse files
committed
Fix problem with logging
1 parent 85b247d commit 4e3e62b

File tree

2 files changed

+18
-14
lines changed

2 files changed

+18
-14
lines changed

src/utils/logger.c

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -131,6 +131,9 @@ exit_if_necessary(int elevel)
131131
pthread_mutex_unlock(&log_file_mutex);
132132
}
133133

134+
if (remote_agent)
135+
sleep(1); /* Let parent receive sent messages */
136+
134137
/* If this is not the main thread then don't call exit() */
135138
if (main_tid != pthread_self())
136139
#ifdef WIN32

src/utils/remote.c

Lines changed: 15 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -79,12 +79,20 @@ static void kill_child(void)
7979
kill(child_pid, SIGTERM);
8080
}
8181

82+
83+
static void print_message(char const* buf)
84+
{
85+
char const* const severity[] = {"VERBOSE", "LOG", "INFO", "NOTICE", "WARNING", "FATAL", "ERROR", ""};
86+
size_t i;
87+
for (i = 0; strncmp(buf, severity[i], strlen(severity[i])) != 0; i++);
88+
elog(i+VERBOSE, "%s", buf + strlen(severity[i]) + 2);
89+
}
90+
8291
static void* error_reader_proc(void* arg)
8392
{
8493
int* errfd = (int*)arg;
8594
char buf[ERR_BUF_SIZE];
8695
int offs = 0, rc;
87-
8896
while ((rc = read(errfd[0], &buf[offs], sizeof(buf) - offs)) > 0)
8997
{
9098
char* nl;
@@ -93,22 +101,15 @@ static void* error_reader_proc(void* arg)
93101
nl = strchr(buf, '\n');
94102
if (nl != NULL) {
95103
*nl = '\0';
96-
if (strncmp(buf, "ERROR: ", 7) == 0) {
97-
elog(ERROR, "%s", buf + 7);
98-
} if (strncmp(buf, "WARNING: ", 9) == 0) {
99-
elog(WARNING, "%s", buf + 9);
100-
} if (strncmp(buf, "VERBOSE: ", 9) == 0) {
101-
elog(VERBOSE, "%s", buf + 9);
102-
} else if (strncmp(buf, "LOG: ", 5) == 0) {
103-
elog(LOG, "%s", buf + 5);
104-
} else if (strncmp(buf, "INFO: ", 6) == 0) {
105-
elog(INFO, "%s", buf + 6);
106-
} else {
107-
elog(LOG, "%s", buf);
108-
}
104+
print_message(buf);
109105
memmove(buf, nl+1, offs -= (nl + 1 - buf));
110106
}
111107
}
108+
if (offs != 0)
109+
{
110+
buf[offs] = '\0';
111+
print_message(buf);
112+
}
112113
return NULL;
113114
}
114115

0 commit comments

Comments
 (0)