~cpick/mongrel2/release

« back to all changes in this revision

Viewing changes to src/dbg.h

  • Committer: Chris Pick
  • Date: 2013-06-30 16:39:57 UTC
  • mfrom: (1106.1.15)
  • Revision ID: git-v1:ec39967acb6bc9867ed9b9dc3774304ca6b9c294
Merge tag 'v1.8.1' into debian

Hotfix for github issue 148

Show diffs side-by-side

added added

removed removed

Lines of Context:
38
38
#include <stdio.h>
39
39
#include <errno.h>
40
40
#include <string.h>
 
41
#include <stdarg.h>
41
42
 
42
43
void dbg_set_log(FILE *log_file);
43
44
FILE *dbg_get_log();
 
45
void fprintf_with_timestamp(FILE *log_file, const char *format, ...);
44
46
 
45
47
#ifdef NDEBUG
46
48
#define debug(M, ...)
47
49
#else
48
 
#define debug(M, ...) fprintf(dbg_get_log(), "DEBUG %s:%d: " M "\n", __FILE__, __LINE__, ##__VA_ARGS__)
 
50
#define debug(M, ...) fprintf_with_timestamp(dbg_get_log(), "DEBUG %s:%d: " M "\n", __FILE__, __LINE__, ##__VA_ARGS__)
49
51
#endif
50
52
 
51
53
 
58
60
 
59
61
#ifdef NO_LINENOS
60
62
// versions that don't feature line numbers
61
 
#define log_err(M, ...) fprintf(dbg_get_log(), "[ERROR] (errno: %s) " M "\n", clean_errno(), ##__VA_ARGS__)
62
 
#define log_warn(M, ...) fprintf(dbg_get_log(), "[WARN] (errno: %s) " M "\n", clean_errno(), ##__VA_ARGS__)
63
 
#define log_info(M, ...) fprintf(dbg_get_log(), "[INFO] " M "\n", ##__VA_ARGS__)
 
63
#define log_err(M, ...) fprintf_with_timestamp(dbg_get_log(), "[ERROR] (errno: %s) " M "\n", clean_errno(), ##__VA_ARGS__)
 
64
#define log_warn(M, ...) fprintf_with_timestamp(dbg_get_log(), "[WARN] (errno: %s) " M "\n", clean_errno(), ##__VA_ARGS__)
 
65
#define log_info(M, ...) fprintf_with_timestamp(dbg_get_log(), "[INFO] " M "\n", ##__VA_ARGS__)
64
66
#else
65
 
#define log_err(M, ...) fprintf(dbg_get_log(), "[ERROR] (%s:%d: errno: %s) " M "\n", __FILE__, __LINE__, clean_errno(), ##__VA_ARGS__)
66
 
#define log_warn(M, ...) fprintf(dbg_get_log(), "[WARN] (%s:%d: errno: %s) " M "\n", __FILE__, __LINE__, clean_errno(), ##__VA_ARGS__)
67
 
#define log_info(M, ...) fprintf(dbg_get_log(), "[INFO] (%s:%d) " M "\n", __FILE__, __LINE__, ##__VA_ARGS__)
 
67
#define log_err(M, ...) fprintf_with_timestamp(dbg_get_log(), "[ERROR] (%s:%d: errno: %s) " M "\n", __FILE__, __LINE__, clean_errno(), ##__VA_ARGS__)
 
68
#define log_warn(M, ...) fprintf_with_timestamp(dbg_get_log(), "[WARN] (%s:%d: errno: %s) " M "\n", __FILE__, __LINE__, clean_errno(), ##__VA_ARGS__)
 
69
#define log_info(M, ...) fprintf_with_timestamp(dbg_get_log(), "[INFO] (%s:%d) " M "\n", __FILE__, __LINE__, ##__VA_ARGS__)
68
70
#endif
69
71
 
70
72
#define check(A, M, ...) if(!(A)) { log_err(M, ##__VA_ARGS__); errno=0; goto error; }