the upcoming 2.0 version
https://redmine.lighttpd.net/projects/lighttpd2
You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
69 lines
1.6 KiB
69 lines
1.6 KiB
|
|
#include <lighttpd/angel_base.h> |
|
|
|
#if REMOVE_PATH_FROM_FILE |
|
const char *remove_path(const char *path) { |
|
char *p = strrchr(path, DIR_SEPERATOR); |
|
if (NULL != p && *(p) != '\0') { |
|
return (p + 1); |
|
} |
|
return path; |
|
} |
|
#endif |
|
|
|
void log_init(server *srv) { |
|
srv->log.type = LOG_TYPE_STDERR; |
|
|
|
srv->log.levels[LOG_LEVEL_ABORT] = TRUE; |
|
srv->log.levels[LOG_LEVEL_ERROR] = TRUE; |
|
srv->log.levels[LOG_LEVEL_WARNING] = TRUE; |
|
|
|
srv->log.levels[LOG_LEVEL_INFO] = TRUE; /* TODO: remove debug levels */ |
|
srv->log.levels[LOG_LEVEL_DEBUG] = TRUE; |
|
|
|
srv->log.fd = -1; |
|
srv->log.ts_cache = g_string_sized_new(0); |
|
srv->log.log_line = g_string_sized_new(0); |
|
} |
|
|
|
void log_clean(server *srv) { |
|
g_string_free(srv->log.ts_cache, TRUE); |
|
g_string_free(srv->log.log_line, TRUE); |
|
} |
|
|
|
void log_write(server *srv, log_level_t log_level, guint flags, const gchar *fmt, ...) { |
|
va_list ap; |
|
GString *log_line = srv->log.log_line; |
|
|
|
if (!srv->log.levels[log_level]) return; |
|
|
|
g_string_truncate(log_line, 0); |
|
|
|
/* for normal error messages, we prepend a timestamp */ |
|
if (flags & LOG_FLAG_TIMESTAMP) { |
|
GString *log_ts = srv->log.ts_cache; |
|
time_t cur_ts; |
|
|
|
cur_ts = (time_t)ev_now(srv->loop); |
|
|
|
if (cur_ts != srv->log.last_ts) { |
|
gsize s; |
|
g_string_set_size(log_ts, 255); |
|
s = strftime(log_ts->str, log_ts->allocated_len, "%Y-%m-%d %H:%M:%S %Z: ", localtime(&cur_ts)); |
|
|
|
g_string_set_size(log_ts, s); |
|
|
|
srv->log.last_ts = cur_ts; |
|
} |
|
|
|
g_string_append_len(log_line, GSTR_LEN(log_ts)); |
|
} |
|
|
|
va_start(ap, fmt); |
|
g_string_append_vprintf(log_line, fmt, ap); |
|
va_end(ap); |
|
|
|
g_string_append_len(log_line, CONST_STR_LEN("\n")); |
|
|
|
fprintf(stderr, "%s", log_line->str); |
|
}
|
|
|