Browse Source

Refactored logging. Increased default log buffer size.

djm34
troky 11 years ago
parent
commit
9f6bf16196
  1. 39
      logging.c
  2. 15
      logging.h

39
logging.c

@ -47,20 +47,37 @@ static void my_log_curses(int prio, const char *datetime, const char *str, bool @@ -47,20 +47,37 @@ static void my_log_curses(int prio, const char *datetime, const char *str, bool
}
}
/* high-level logging function, based on global opt_log_level */
void applog(int prio, const char* fmt, ...) {
void applog(int prio, const char* fmt, ...)
{
va_list args;
va_start(args, fmt);
vapplogsiz(prio, LOGBUFSIZ, fmt, args);
va_end(args);
}
void applogsiz(int prio, int size, const char* fmt, ...)
{
va_list args;
if (opt_debug || prio != LOG_DEBUG) {
if (use_syslog || opt_log_output || prio <= opt_log_level) {
char tmp42[LOGBUFSIZ];
va_start(args, fmt);
vsnprintf(tmp42, sizeof(tmp42), fmt, args);
vapplogsiz(prio, size, fmt, args);
va_end(args);
}
/* high-level logging function, based on global opt_log_level */
void vapplogsiz(int prio, int size, const char* fmt, va_list args)
{
if (opt_debug || prio != LOG_DEBUG) {
if (use_syslog || opt_log_output || prio <= opt_log_level) {
char *tmp42 = (char *)calloc(size, 1);
vsnprintf(tmp42, size, fmt, args);
_applog(prio, tmp42, false);
free(tmp42);
}
}
}
/*
* log function
*/
@ -84,8 +101,7 @@ void _applog(int prio, const char *str, bool force) @@ -84,8 +101,7 @@ void _applog(int prio, const char *str, bool force)
tm = localtime(&tmp_time);
/* Day changed. */
if (opt_log_show_date && (last_date_output_day != tm->tm_mday))
{
if (opt_log_show_date && (last_date_output_day != tm->tm_mday)) {
last_date_output_day = tm->tm_mday;
char date_output_str[64];
snprintf(date_output_str, sizeof(date_output_str), "Log date is now %d-%02d-%02d",
@ -93,11 +109,9 @@ void _applog(int prio, const char *str, bool force) @@ -93,11 +109,9 @@ void _applog(int prio, const char *str, bool force)
tm->tm_mon + 1,
tm->tm_mday);
_applog(prio, date_output_str, force);
}
if (opt_log_show_date)
{
if (opt_log_show_date) {
snprintf(datetime, sizeof(datetime), "[%d-%02d-%02d %02d:%02d:%02d] ",
tm->tm_year + 1900,
tm->tm_mon + 1,
@ -106,8 +120,7 @@ void _applog(int prio, const char *str, bool force) @@ -106,8 +120,7 @@ void _applog(int prio, const char *str, bool force)
tm->tm_min,
tm->tm_sec);
}
else
{
else {
snprintf(datetime, sizeof(datetime), "[%02d:%02d:%02d] ",
tm->tm_hour,
tm->tm_min,

15
logging.h

@ -28,23 +28,16 @@ extern int opt_log_level; @@ -28,23 +28,16 @@ extern int opt_log_level;
extern int opt_log_show_date;
#define LOGBUFSIZ 256
#define LOGBUFSIZ 512
void applog(int prio, const char* fmt, ...);
void applogsiz(int prio, int size, const char* fmt, ...);
void vapplogsiz(int prio, int size, const char* fmt, va_list args);
extern void _applog(int prio, const char *str, bool force);
#define IN_FMT_FFL " in %s %s():%d"
#define applogsiz(prio, _SIZ, fmt, ...) do { \
if (opt_debug || prio != LOG_DEBUG) { \
if (use_syslog || opt_log_output || prio <= opt_log_level) { \
char tmp42[_SIZ]; \
snprintf(tmp42, sizeof(tmp42), fmt, ##__VA_ARGS__); \
_applog(prio, tmp42, false); \
} \
} \
} while (0)
#define forcelog(prio, fmt, ...) do { \
if (opt_debug || prio != LOG_DEBUG) { \
if (use_syslog || opt_log_output || prio <= opt_log_level) { \

Loading…
Cancel
Save