@@ -79,12 +79,20 @@ static void kill_child(void)
79
79
kill (child_pid , SIGTERM );
80
80
}
81
81
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
+
82
91
static void * error_reader_proc (void * arg )
83
92
{
84
93
int * errfd = (int * )arg ;
85
94
char buf [ERR_BUF_SIZE ];
86
95
int offs = 0 , rc ;
87
-
88
96
while ((rc = read (errfd [0 ], & buf [offs ], sizeof (buf ) - offs )) > 0 )
89
97
{
90
98
char * nl ;
@@ -93,22 +101,15 @@ static void* error_reader_proc(void* arg)
93
101
nl = strchr (buf , '\n' );
94
102
if (nl != NULL ) {
95
103
* 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 );
109
105
memmove (buf , nl + 1 , offs -= (nl + 1 - buf ));
110
106
}
111
107
}
108
+ if (offs != 0 )
109
+ {
110
+ buf [offs ] = '\0' ;
111
+ print_message (buf );
112
+ }
112
113
return NULL ;
113
114
}
114
115
0 commit comments