add log level "backend"

personal/stbuehler/wip
Thomas Porzelt 14 years ago
parent 025f0b5f84
commit 66f7e669dd
  1. 19
      include/lighttpd/log.h
  2. 21
      src/log.c
  3. 8
      src/plugin_core.c

@ -17,22 +17,24 @@ LI_API const char *remove_path(const char *path);
#define _SEGFAULT(srv, vr, fmt, ...) \
do { \
log_write_(srv, NULL, LOG_LEVEL_ABORT, LOG_FLAG_TIMETAMP, "(crashing) %s.%d: "fmt, REMOVE_PATH(__FILE__), __LINE__, __VA_ARGS__); \
log_write_(srv, NULL, LOG_LEVEL_ABORT, LOG_FLAG_TIMESTAMP, "(crashing) %s.%d: "fmt, REMOVE_PATH(__FILE__), __LINE__, __VA_ARGS__); \
/* VALGRIND_PRINTF_BACKTRACE(fmt, __VA_ARGS__); */\
abort();\
} while(0)
#define _ERROR(srv, vr, fmt, ...) \
log_write_(srv, vr, LOG_LEVEL_ERROR, LOG_FLAG_TIMETAMP, "(error) %s.%d: "fmt, REMOVE_PATH(__FILE__), __LINE__, __VA_ARGS__)
log_write_(srv, vr, LOG_LEVEL_ERROR, LOG_FLAG_TIMESTAMP, "(error) %s.%d: "fmt, REMOVE_PATH(__FILE__), __LINE__, __VA_ARGS__)
#define _WARNING(srv, vr, fmt, ...) \
log_write_(srv, vr, LOG_LEVEL_WARNING, LOG_FLAG_TIMETAMP, "(warning) %s.%d: "fmt, REMOVE_PATH(__FILE__), __LINE__, __VA_ARGS__)
log_write_(srv, vr, LOG_LEVEL_WARNING, LOG_FLAG_TIMESTAMP, "(warning) %s.%d: "fmt, REMOVE_PATH(__FILE__), __LINE__, __VA_ARGS__)
#define _INFO(srv, vr, fmt, ...) \
log_write_(srv, vr, LOG_LEVEL_INFO, LOG_FLAG_TIMETAMP, "(info) %s.%d: "fmt, REMOVE_PATH(__FILE__), __LINE__, __VA_ARGS__)
log_write_(srv, vr, LOG_LEVEL_INFO, LOG_FLAG_TIMESTAMP, "(info) %s.%d: "fmt, REMOVE_PATH(__FILE__), __LINE__, __VA_ARGS__)
#define _DEBUG(srv, vr, fmt, ...) \
log_write_(srv, vr, LOG_LEVEL_INFO, LOG_FLAG_TIMETAMP, "(debug) %s.%d: "fmt, REMOVE_PATH(__FILE__), __LINE__, __VA_ARGS__)
log_write_(srv, vr, LOG_LEVEL_INFO, LOG_FLAG_TIMESTAMP, "(debug) %s.%d: "fmt, REMOVE_PATH(__FILE__), __LINE__, __VA_ARGS__)
#define _BACKEND(srv, vr, fmt, ...) \
log_write_(srv, vr, LOG_LEVEL_BACKEND, LOG_FLAG_TIMESTAMP)
#define VR_SEGFAULT(vr, fmt, ...) _SEGFAULT(vr->con->srv, vr, fmt, __VA_ARGS__)
@ -40,12 +42,14 @@ LI_API const char *remove_path(const char *path);
#define VR_WARNING(vr, fmt, ...) _WARNING(vr->con->srv, vr, fmt, __VA_ARGS__)
#define VR_INFO(vr, fmt, ...) _INFO(vr->con->srv, vr, fmt, __VA_ARGS__)
#define VR_DEBUG(vr, fmt, ...) _DEBUG(vr->con->srv, vr, fmt, __VA_ARGS__)
#define VR_BACKEND(vr, fmt, ...) _BACKEND(vr->con->srv, vr, fmt, __VA_ARGS__)
#define SEGFAULT(srv, fmt, ...) _SEGFAULT(srv, NULL, fmt, __VA_ARGS__)
#define ERROR(srv, fmt, ...) _ERROR(srv, NULL, fmt, __VA_ARGS__)
#define WARNING(srv, fmt, ...) _WARNING(srv, NULL, fmt, __VA_ARGS__)
#define INFO(srv, fmt, ...) _INFO(srv, NULL, fmt, __VA_ARGS__)
#define DEBUG(srv, fmt, ...) _DEBUG(srv, NULL, fmt, __VA_ARGS__)
#define BACKEND(srv, fmt, ...) _BACKEND(srv, NULL, fmt, __VA_ARGS__)
/* TODO: perhaps make portable (detect if cc supports) */
@ -68,7 +72,8 @@ typedef enum {
LOG_LEVEL_INFO,
LOG_LEVEL_WARNING,
LOG_LEVEL_ERROR,
LOG_LEVEL_ABORT
LOG_LEVEL_ABORT,
LOG_LEVEL_BACKEND
} log_level_t;
typedef enum {
@ -81,7 +86,7 @@ typedef enum {
/* flags for log_write */
#define LOG_FLAG_NONE (0x0) /* default flag */
#define LOG_FLAG_TIMETAMP (0x1) /* prepend a timestamp to the log message */
#define LOG_FLAG_TIMESTAMP (0x1) /* prepend a timestamp to the log message */
#define LOG_FLAG_NOLOCK (0x1 << 1) /* for internal use only */
#define LOG_FLAG_ALLOW_REPEAT (0x1 << 2) /* allow writing of multiple equal entries after each other */

@ -1,3 +1,9 @@
/*
todo:
- write out logs at startup directly
- scheme:// prefix
*/
#include <lighttpd/base.h>
#include <lighttpd/plugin_core.h>
@ -89,7 +95,7 @@ gboolean log_write_(server *srv, vrequest *vr, log_level_t log_level, guint flag
g_string_assign(log->lastmsg, log_line->str);
/* for normal error messages, we prepend a timestamp */
if (flags & LOG_FLAG_TIMETAMP) {
if (flags & LOG_FLAG_TIMESTAMP) {
time_t cur_ts;
g_mutex_lock(srv->logs.mutex);
@ -260,6 +266,16 @@ log_type_t log_type_from_path(GString *path) {
if (path->len == 0)
return LOG_TYPE_NONE;
/* look for scheme:// paths */
if (g_str_has_prefix(path->str, "file://"))
return LOG_TYPE_FILE;
if (g_str_has_prefix(path->str, "pipe://"))
return LOG_TYPE_PIPE;
if (g_str_has_prefix(path->str, "stderr://"))
return LOG_TYPE_STDERR;
if (g_str_has_prefix(path->str, "syslog://"))
return LOG_TYPE_SYSLOG;
/* targets starting with a slash are absolute paths and therefor file targets */
if (*path->str == '/')
return LOG_TYPE_FILE;
@ -287,6 +303,8 @@ log_level_t log_level_from_string(GString *str) {
return LOG_LEVEL_WARNING;
if (g_str_equal(str->str, "error"))
return LOG_LEVEL_ERROR;
if (g_str_equal(str->str, "backend"))
return LOG_LEVEL_BACKEND;
/* fall back to debug level */
return LOG_LEVEL_DEBUG;
@ -298,6 +316,7 @@ gchar* log_level_str(log_level_t log_level) {
case LOG_LEVEL_INFO: return "info";
case LOG_LEVEL_WARNING: return "warning";
case LOG_LEVEL_ERROR: return "error";
case LOG_LEVEL_BACKEND: return "backend";
default: return "unknown";
}
}

@ -484,21 +484,23 @@ static gboolean core_option_log_parse(server *srv, plugin *p, size_t ndx, value
log_level_t level;
GString *path;
GString *level_str;
GArray *arr = g_array_sized_new(FALSE, TRUE, sizeof(log_t*), 5);
GArray *arr = g_array_sized_new(FALSE, TRUE, sizeof(log_t*), 6);
UNUSED(p);
UNUSED(ndx);
oval->list = arr;
g_array_set_size(arr, 5);
g_array_set_size(arr, 6);
/* default value */
if (!val) {
/* default: log LOG_LEVEL_WARNING and LOG_LEVEL_ERROR to stderr */
/* default: log LOG_LEVEL_WARNING, LOG_LEVEL_ERROR and LOG_LEVEL_BACKEND to stderr */
log_t *log = srv->logs.stderr;
log_ref(srv, log);
g_array_index(arr, log_t*, LOG_LEVEL_WARNING) = log;
log_ref(srv, log);
g_array_index(arr, log_t*, LOG_LEVEL_ERROR) = log;
log_ref(srv, log);
g_array_index(arr, log_t*, LOG_LEVEL_BACKEND) = log;
return TRUE;
}

Loading…
Cancel
Save