Browse Source

Handle multi-lines for error-pipe logging

personal/stbuehler/wip
Stefan Bühler 13 years ago
parent
commit
baa78b1ebb
  1. 9
      include/lighttpd/angel_log.h
  2. 36
      src/angel/angel_log.c
  3. 2
      src/angel/angel_proc.c

9
include/lighttpd/angel_log.h

@ -31,7 +31,10 @@
li_log_write(srv, LI_LOG_LEVEL_ERROR, LI_LOG_FLAG_NONE, "lighttpd[%d]: %s", (int) inst->pid, msg)
#define GERROR(srv, error, fmt, ...) \
li_log_write_(srv, LI_LOG_LEVEL_ERROR, LOG_FLAG_TIMESTAMP, "error (%s:%d): " fmt "\n %s", LI_REMOVE_PATH(__FILE__), __LINE__, __VA_ARGS__, error ? error->message : "Empty GError")
li_log_write_(srv, LI_LOG_LEVEL_ERROR, LI_LOG_FLAG_TIMESTAMP, "error (%s:%d): " fmt "\n %s", LI_REMOVE_PATH(__FILE__), __LINE__, __VA_ARGS__, error ? error->message : "Empty GError")
#define BACKEND_LINES(srv, txt, ...) \
li_log_split_lines_(srv, LI_LOG_LEVEL_INFO, LI_LOG_FLAG_TIMESTAMP, txt, __VA_ARGS__)
typedef enum {
LI_LOG_LEVEL_DEBUG,
@ -73,4 +76,8 @@ void log_clean(liServer *srv);
LI_API void li_log_write(liServer *srv, liLogLevel log_level, guint flags, const gchar *fmt, ...) G_GNUC_PRINTF(4, 5);
/* replaces '\r' and '\n' with '\0' */
LI_API void li_log_split_lines(liServer *srv, liLogLevel log_level, guint flags, gchar *txt, const gchar *prefix);
LI_API void li_log_split_lines_(liServer *srv, liLogLevel log_level, guint flags, gchar *txt, const gchar *fmt, ...) G_GNUC_PRINTF(5, 6);
#endif

36
src/angel/angel_log.c

@ -63,3 +63,39 @@ void li_log_write(liServer *srv, liLogLevel log_level, guint flags, const gchar
fprintf(stderr, "%s", log_line->str);
}
void li_log_split_lines(liServer *srv, liLogLevel log_level, guint flags, gchar *txt, const gchar *prefix) {
gchar *start;
start = txt;
while ('\0' != *txt) {
if ('\r' == *txt || '\n' == *txt) {
*txt = '\0';
if (txt - start > 1) { /* skip empty lines*/
li_log_write(srv, log_level, flags, "%s%s", prefix, start);
}
txt++;
while (*txt == '\n' || *txt == '\r') txt++;
start = txt;
} else {
txt++;
}
}
if (txt - start > 1) { /* skip empty lines*/
li_log_write(srv, log_level, flags, "%s%s", prefix, start);
}
}
void li_log_split_lines_(liServer *srv, liLogLevel log_level, guint flags, gchar *txt, const gchar *fmt, ...) {
va_list ap;
GString *prefix;
prefix = g_string_sized_new(0);
va_start(ap, fmt);
g_string_vprintf(prefix, fmt, ap);
va_end(ap);
li_log_split_lines(srv, log_level, flags, txt, prefix->str);
g_string_free(prefix, TRUE);
}

2
src/angel/angel_proc.c

@ -134,7 +134,7 @@ void li_error_pipe_flush(liErrorPipe *epipe) {
static void proc_epipe_cb(liServer *srv, liErrorPipe *epipe, GString *msg) {
liProc *proc = epipe->ctx;
ERROR(srv, "%s (pid: %i): %s", proc->appname, proc->child_pid, msg->str);
BACKEND_LINES(srv, msg->str, "%s[%i]: ", proc->appname, proc->child_pid);
}
liProc* li_proc_new(liServer *srv, gchar **args, gchar **env, uid_t uid, gid_t gid, gchar *username, liProcSetupCB cb, gpointer ctx) {

Loading…
Cancel
Save