2008-06-24 19:19:20 +00:00
|
|
|
#ifndef _LIGHTTPD_LOG_H_
|
|
|
|
#define _LIGHTTPD_LOG_H_
|
|
|
|
|
2008-10-28 21:11:50 +00:00
|
|
|
#ifndef _LIGHTTPD_BASE_H_
|
2008-11-16 20:33:53 +00:00
|
|
|
#error Please include <lighttpd/base.h> instead of this file
|
2008-10-28 21:11:50 +00:00
|
|
|
#endif
|
|
|
|
|
2008-11-16 20:33:53 +00:00
|
|
|
/* #include <lighttpd/valgrind/valgrind.h> */
|
2008-06-24 19:19:20 +00:00
|
|
|
|
2008-12-30 13:24:33 +00:00
|
|
|
#define _SEGFAULT(srv, vr, fmt, ...) \
|
|
|
|
do { \
|
2009-07-17 10:19:25 +00:00
|
|
|
li_log_write_(srv, NULL, LI_LOG_LEVEL_ABORT, LOG_FLAG_TIMESTAMP, "(crashing) %s.%d: "fmt, LI_REMOVE_PATH(__FILE__), __LINE__, __VA_ARGS__); \
|
2008-12-30 13:24:33 +00:00
|
|
|
/* VALGRIND_PRINTF_BACKTRACE(fmt, __VA_ARGS__); */\
|
|
|
|
abort();\
|
|
|
|
} while(0)
|
2008-06-24 19:19:20 +00:00
|
|
|
|
2008-12-30 13:24:33 +00:00
|
|
|
#define _ERROR(srv, vr, fmt, ...) \
|
2009-07-17 10:19:25 +00:00
|
|
|
li_log_write_(srv, vr, LI_LOG_LEVEL_ERROR, LOG_FLAG_TIMESTAMP, "(error) %s.%d: "fmt, LI_REMOVE_PATH(__FILE__), __LINE__, __VA_ARGS__)
|
2008-09-24 21:43:22 +00:00
|
|
|
|
2008-12-30 13:24:33 +00:00
|
|
|
#define _WARNING(srv, vr, fmt, ...) \
|
2009-07-17 10:19:25 +00:00
|
|
|
li_log_write_(srv, vr, LI_LOG_LEVEL_WARNING, LOG_FLAG_TIMESTAMP, "(warning) %s.%d: "fmt, LI_REMOVE_PATH(__FILE__), __LINE__, __VA_ARGS__)
|
2008-12-29 17:46:51 +00:00
|
|
|
|
2008-12-30 13:24:33 +00:00
|
|
|
#define _INFO(srv, vr, fmt, ...) \
|
2009-07-17 10:19:25 +00:00
|
|
|
li_log_write_(srv, vr, LI_LOG_LEVEL_INFO, LOG_FLAG_TIMESTAMP, "(info) %s.%d: "fmt, LI_REMOVE_PATH(__FILE__), __LINE__, __VA_ARGS__)
|
2008-12-02 14:58:06 +00:00
|
|
|
|
2008-12-30 13:24:33 +00:00
|
|
|
#define _DEBUG(srv, vr, fmt, ...) \
|
2009-07-17 10:19:25 +00:00
|
|
|
li_log_write_(srv, vr, LI_LOG_LEVEL_DEBUG, LOG_FLAG_TIMESTAMP, "(debug) %s.%d: "fmt, LI_REMOVE_PATH(__FILE__), __LINE__, __VA_ARGS__)
|
2009-04-24 08:03:04 +00:00
|
|
|
|
2008-12-31 01:50:32 +00:00
|
|
|
#define _BACKEND(srv, vr, fmt, ...) \
|
2009-10-03 13:26:03 +00:00
|
|
|
li_log_write_(srv, vr, LI_LOG_LEVEL_BACKEND, LOG_FLAG_TIMESTAMP, fmt, __VA_ARGS__)
|
2009-02-03 14:25:14 +00:00
|
|
|
#define _BACKEND_LINES(srv, vr, txt, fmt, ...) \
|
2009-10-03 13:26:03 +00:00
|
|
|
li_log_split_lines_(srv, vr, LI_LOG_LEVEL_BACKEND, LOG_FLAG_TIMESTAMP, txt, fmt, __VA_ARGS__)
|
2008-12-02 14:58:06 +00:00
|
|
|
|
2009-07-17 10:19:57 +00:00
|
|
|
#define _GERROR(srv, vr, error, fmt, ...) \
|
|
|
|
li_log_write_(srv, vr, 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")
|
2008-09-24 21:43:22 +00:00
|
|
|
|
2009-04-15 10:34:06 +00:00
|
|
|
#define VR_SEGFAULT(vr, fmt, ...) _SEGFAULT(vr->wrk->srv, vr, fmt, __VA_ARGS__)
|
|
|
|
#define VR_ERROR(vr, fmt, ...) _ERROR(vr->wrk->srv, vr, fmt, __VA_ARGS__)
|
|
|
|
#define VR_WARNING(vr, fmt, ...) _WARNING(vr->wrk->srv, vr, fmt, __VA_ARGS__)
|
|
|
|
#define VR_INFO(vr, fmt, ...) _INFO(vr->wrk->srv, vr, fmt, __VA_ARGS__)
|
|
|
|
#define VR_DEBUG(vr, fmt, ...) _DEBUG(vr->wrk->srv, vr, fmt, __VA_ARGS__)
|
|
|
|
#define VR_BACKEND(vr, fmt, ...) _BACKEND(vr->wrk->srv, vr, fmt, __VA_ARGS__)
|
|
|
|
#define VR_BACKEND_LINES(vr, txt, fmt, ...) _BACKEND_LINES(vr->wrk->srv, vr, txt, fmt, __VA_ARGS__)
|
2009-09-13 15:46:02 +00:00
|
|
|
#define VR_GERROR(vr, error, fmt, ...) _GERROR(vr->wrk->srv, vr, error, fmt, __VA_ARGS__)
|
2008-12-29 17:46:51 +00:00
|
|
|
|
2008-12-30 13:24:33 +00:00
|
|
|
#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__)
|
2009-02-03 14:25:14 +00:00
|
|
|
#define BACKEND(srv, fmt, ...) _BACKEND(srv, NULL, fmt, __VA_ARGS__)
|
2009-07-17 10:19:57 +00:00
|
|
|
#define GERROR(srv, error, fmt, ...) _GERROR(srv, NULL, error, fmt, __VA_ARGS__)
|
2008-09-24 21:43:22 +00:00
|
|
|
|
2009-07-09 20:17:24 +00:00
|
|
|
/* flags for li_log_write */
|
2008-09-24 21:43:22 +00:00
|
|
|
#define LOG_FLAG_NONE (0x0) /* default flag */
|
2008-12-31 01:50:32 +00:00
|
|
|
#define LOG_FLAG_TIMESTAMP (0x1) /* prepend a timestamp to the log message */
|
2008-09-24 21:43:22 +00:00
|
|
|
#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 */
|
|
|
|
|
2009-07-08 19:06:07 +00:00
|
|
|
struct liLog {
|
|
|
|
liLogType type;
|
2008-07-19 20:13:32 +00:00
|
|
|
GString *path;
|
2008-07-20 16:28:58 +00:00
|
|
|
gint refcount;
|
2008-07-18 20:16:30 +00:00
|
|
|
gint fd;
|
2008-09-24 21:43:22 +00:00
|
|
|
|
2008-07-18 20:16:30 +00:00
|
|
|
GString *lastmsg;
|
|
|
|
guint lastmsg_count;
|
2008-09-24 21:43:22 +00:00
|
|
|
|
2008-07-20 14:35:04 +00:00
|
|
|
GMutex *mutex;
|
2008-07-18 20:16:30 +00:00
|
|
|
};
|
|
|
|
|
2009-07-08 19:06:07 +00:00
|
|
|
struct liLogTimestamp {
|
2008-09-24 21:43:22 +00:00
|
|
|
gint refcount;
|
2008-11-12 21:16:52 +00:00
|
|
|
ev_tstamp last_ts;
|
2008-09-24 21:43:22 +00:00
|
|
|
GString *format;
|
|
|
|
GString *cached;
|
|
|
|
};
|
|
|
|
|
2009-07-08 19:06:07 +00:00
|
|
|
struct liLogEntry {
|
|
|
|
liLog *log;
|
|
|
|
liLogLevel level;
|
2008-07-18 22:11:08 +00:00
|
|
|
GString *msg;
|
|
|
|
};
|
|
|
|
|
2008-08-13 17:57:19 +00:00
|
|
|
/* determines the type of a log target by the path given. /absolute/path = file; |app = pipe; stderr = stderr; syslog = syslog */
|
2009-10-09 13:38:12 +00:00
|
|
|
LI_API liLogType li_log_type_from_path(GString *path);
|
2008-08-13 17:57:19 +00:00
|
|
|
|
2009-10-09 13:38:12 +00:00
|
|
|
LI_API liLogLevel li_log_level_from_string(GString *str);
|
|
|
|
LI_API gchar* li_log_level_str(liLogLevel log_level);
|
2008-07-19 20:13:32 +00:00
|
|
|
|
2008-07-22 14:00:31 +00:00
|
|
|
/* log_new is used to create a new log target, if a log with the same path already exists, it is referenced instead */
|
2009-10-09 13:38:12 +00:00
|
|
|
LI_API liLog *li_log_new(liServer *srv, liLogType type, GString *path);
|
2008-07-19 20:13:32 +00:00
|
|
|
|
2009-10-09 13:38:12 +00:00
|
|
|
LI_API void li_log_ref(liServer *srv, liLog *log);
|
|
|
|
LI_API void li_log_unref(liServer *srv, liLog *log);
|
2008-07-19 20:13:32 +00:00
|
|
|
|
2009-10-09 13:38:12 +00:00
|
|
|
LI_API void li_log_thread_start(liServer *srv);
|
|
|
|
LI_API void li_log_thread_wakeup(liServer *srv);
|
2008-09-24 21:43:22 +00:00
|
|
|
|
2009-10-09 13:38:12 +00:00
|
|
|
LI_API void li_log_init(liServer *srv);
|
|
|
|
LI_API void li_log_cleanup(liServer *srv);
|
2008-09-24 21:43:22 +00:00
|
|
|
|
2009-07-09 20:17:24 +00:00
|
|
|
/* li_log_write is used to directly write a message to a log target */
|
|
|
|
LI_API void li_log_write(liServer *srv, liLog *log, GString *msg);
|
|
|
|
/* li_log_write_ is used to write to the errorlog */
|
|
|
|
LI_API gboolean li_log_write_(liServer *srv, liVRequest *vr, liLogLevel log_level, guint flags, const gchar *fmt, ...) G_GNUC_PRINTF(5, 6);
|
2008-09-24 21:43:22 +00:00
|
|
|
|
2009-07-09 20:17:24 +00:00
|
|
|
LI_API liLogTimestamp *li_log_timestamp_new(liServer *srv, GString *format);
|
|
|
|
LI_API gboolean li_log_timestamp_free(liServer *srv, liLogTimestamp *ts);
|
2009-02-03 14:25:14 +00:00
|
|
|
|
|
|
|
/* replaces '\r' and '\n' with '\0' */
|
2009-07-09 20:17:24 +00:00
|
|
|
LI_API void li_log_split_lines(liServer *srv, liVRequest *vr, liLogLevel log_level, guint flags, gchar *txt, const gchar *prefix);
|
|
|
|
LI_API void li_log_split_lines_(liServer *srv, liVRequest *vr, liLogLevel log_level, guint flags, gchar *txt, const gchar *fmt, ...) G_GNUC_PRINTF(6, 7);
|
2009-02-03 14:25:14 +00:00
|
|
|
|
2008-07-18 20:16:30 +00:00
|
|
|
|
2008-06-24 19:19:20 +00:00
|
|
|
#endif
|