Browse Source

Move and add some common log helpers to utils

personal/stbuehler/wip
Stefan Bühler 13 years ago
parent
commit
ab1387d4ba
  1. 8
      include/lighttpd/angel_log.h
  2. 22
      include/lighttpd/log.h
  3. 17
      include/lighttpd/utils.h
  4. 10
      src/angel/angel_log.c
  5. 20
      src/common/utils.c
  6. 10
      src/main/log.c

8
include/lighttpd/angel_log.h

@ -7,14 +7,6 @@
/* #include <lighttpd/valgrind/valgrind.h> */
#define LI_REMOVE_PATH_FROM_FILE 1
#if LI_REMOVE_PATH_FROM_FILE
LI_API const char *li_remove_path(const char *path);
#define LI_REMOVE_PATH(file) li_remove_path(file)
#else
#define LI_REMOVE_PATH(file) file
#endif
#define SEGFAULT(srv, fmt, ...) \
do { \
li_log_write_(srv, LI_LOG_LEVEL_ABORT, LI_LOG_FLAG_TIMESTAMP, "(crashing) %s.%d: "fmt, LI_REMOVE_PATH(__FILE__), __LINE__, __VA_ARGS__); \

22
include/lighttpd/log.h

@ -7,37 +7,29 @@
/* #include <lighttpd/valgrind/valgrind.h> */
#define REMOVE_PATH_FROM_FILE 1
#if REMOVE_PATH_FROM_FILE
LI_API const char *li_remove_path(const char *path);
#define REMOVE_PATH(file) li_remove_path(file)
#else
#define REMOVE_PATH(file) file
#endif
#define _SEGFAULT(srv, vr, fmt, ...) \
do { \
li_log_write_(srv, NULL, LI_LOG_LEVEL_ABORT, LOG_FLAG_TIMESTAMP, "(crashing) %s.%d: "fmt, REMOVE_PATH(__FILE__), __LINE__, __VA_ARGS__); \
li_log_write_(srv, NULL, LI_LOG_LEVEL_ABORT, LOG_FLAG_TIMESTAMP, "(crashing) %s.%d: "fmt, LI_REMOVE_PATH(__FILE__), __LINE__, __VA_ARGS__); \
/* VALGRIND_PRINTF_BACKTRACE(fmt, __VA_ARGS__); */\
abort();\
} while(0)
#define _ERROR(srv, vr, fmt, ...) \
li_log_write_(srv, vr, LI_LOG_LEVEL_ERROR, LOG_FLAG_TIMESTAMP, "(error) %s.%d: "fmt, REMOVE_PATH(__FILE__), __LINE__, __VA_ARGS__)
li_log_write_(srv, vr, LI_LOG_LEVEL_ERROR, LOG_FLAG_TIMESTAMP, "(error) %s.%d: "fmt, LI_REMOVE_PATH(__FILE__), __LINE__, __VA_ARGS__)
#define _WARNING(srv, vr, fmt, ...) \
li_log_write_(srv, vr, LI_LOG_LEVEL_WARNING, LOG_FLAG_TIMESTAMP, "(warning) %s.%d: "fmt, REMOVE_PATH(__FILE__), __LINE__, __VA_ARGS__)
li_log_write_(srv, vr, LI_LOG_LEVEL_WARNING, LOG_FLAG_TIMESTAMP, "(warning) %s.%d: "fmt, LI_REMOVE_PATH(__FILE__), __LINE__, __VA_ARGS__)
#define _INFO(srv, vr, fmt, ...) \
li_log_write_(srv, vr, LI_LOG_LEVEL_INFO, LOG_FLAG_TIMESTAMP, "(info) %s.%d: "fmt, REMOVE_PATH(__FILE__), __LINE__, __VA_ARGS__)
li_log_write_(srv, vr, LI_LOG_LEVEL_INFO, LOG_FLAG_TIMESTAMP, "(info) %s.%d: "fmt, LI_REMOVE_PATH(__FILE__), __LINE__, __VA_ARGS__)
#define _DEBUG(srv, vr, fmt, ...) \
li_log_write_(srv, vr, LI_LOG_LEVEL_DEBUG, LOG_FLAG_TIMESTAMP, "(debug) %s.%d: "fmt, REMOVE_PATH(__FILE__), __LINE__, __VA_ARGS__)
li_log_write_(srv, vr, LI_LOG_LEVEL_DEBUG, LOG_FLAG_TIMESTAMP, "(debug) %s.%d: "fmt, LI_REMOVE_PATH(__FILE__), __LINE__, __VA_ARGS__)
#define _BACKEND(srv, vr, fmt, ...) \
li_log_write_(srv, vr, LI_LOG_LEVEL_BACKEND, LOG_FLAG_TIMESTAMP, "(backend) %s.%d: "fmt, REMOVE_PATH(__FILE__), __LINE__, __VA_ARGS__)
li_log_write_(srv, vr, LI_LOG_LEVEL_BACKEND, LOG_FLAG_TIMESTAMP, "(backend) %s.%d: "fmt, LI_REMOVE_PATH(__FILE__), __LINE__, __VA_ARGS__)
#define _BACKEND_LINES(srv, vr, txt, fmt, ...) \
li_log_split_lines_(srv, vr, LI_LOG_LEVEL_BACKEND, LOG_FLAG_TIMESTAMP, txt, "(backend) %s.%d: "fmt, REMOVE_PATH(__FILE__), __LINE__, __VA_ARGS__)
li_log_split_lines_(srv, vr, LI_LOG_LEVEL_BACKEND, LOG_FLAG_TIMESTAMP, txt, "(backend) %s.%d: "fmt, LI_REMOVE_PATH(__FILE__), __LINE__, __VA_ARGS__)
#define VR_SEGFAULT(vr, fmt, ...) _SEGFAULT(vr->wrk->srv, vr, fmt, __VA_ARGS__)

17
include/lighttpd/utils.h

@ -67,4 +67,21 @@ LI_API void li_string_append_int(GString *dest, gint64 val);
LI_API gsize li_dirent_buf_size(DIR * dirp);
/* error log helper functions */
#define LI_REMOVE_PATH_FROM_FILE 1
#if LI_REMOVE_PATH_FROM_FILE
LI_API const char *li_remove_path(const char *path);
#define LI_REMOVE_PATH(file) li_remove_path(file)
#else
#define LI_REMOVE_PATH(file) file
#endif
#define LI_SYS_ERROR li_sys_error_quark()
LI_API GQuark li_sys_error_quark();
#define LI_SET_SYS_ERROR(error, msg) \
_li_set_sys_error(error, msg, REMOVE_PATH(__FILE__), __LINE__);
LI_API gboolean _li_set_sys_error(GError **error, const gchar *msg, const gchar *file, int lineno);
#endif

10
src/angel/angel_log.c

@ -1,16 +1,6 @@
#include <lighttpd/angel_base.h>
#if LI_REMOVE_PATH_FROM_FILE
const char *li_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(liServer *srv) {
srv->log.type = LI_LOG_TYPE_STDERR;

20
src/common/utils.c

@ -724,3 +724,23 @@ gsize li_dirent_buf_size(DIR * dirp) {
return (name_end > sizeof(struct dirent) ? name_end : sizeof(struct dirent));
}
#if LI_REMOVE_PATH_FROM_FILE
const char *li_remove_path(const char *path) {
char *p = strrchr(path, DIR_SEPERATOR);
if (NULL != p && *(p) != '\0') {
return (p + 1);
}
return path;
}
#endif
GQuark li_sys_error_quark() {
return g_quark_from_static_string("li-sys-error-quark");
}
gboolean _li_set_sys_error(GError **error, const gchar *msg, const gchar *file, int lineno) {
int code = errno;
g_set_error(error, LI_SYS_ERROR, code, "(%s:%d): %s: %s", file, lineno, msg, g_strerror(code));
return FALSE;
}

10
src/main/log.c

@ -11,16 +11,6 @@
#include <fcntl.h>
#include <stdarg.h>
#if REMOVE_PATH_FROM_FILE
const char *li_remove_path(const char *path) {
char *p = strrchr(path, DIR_SEPERATOR);
if (NULL != p && *(p) != '\0') {
return (p + 1);
}
return path;
}
#endif
void li_log_write(liServer *srv, liLog *log, GString *msg) {
liLogEntry *log_entry;

Loading…
Cancel
Save