log.h 1.16 KB
Newer Older
Roger Dingledine's avatar
Roger Dingledine committed
1
2
3
4
5
6
7
8
9
/*
 * log.h
 * Logging facilities.
 * 
 * Matej Pfajfar <mp292@cam.ac.uk>
 */

#ifndef __LOG_H

10
#ifdef HAVE_SYSLOG_H
Roger Dingledine's avatar
Roger Dingledine committed
11
#include <syslog.h>
12
13
14
15
16
17
18
19
20
21
#else
#define LOG_DEBUG   0
#define LOG_INFO    1
#define LOG_NOTICE  2
#define LOG_WARNING 3
#define LOG_ERR     4
#define LOG_CRIT    5
#define LOG_ALERT   6
#define LOG_EMERG   7
#endif
Roger Dingledine's avatar
Roger Dingledine committed
22

23
24
25
26
27
28
29
30
/* magic to make GCC check for proper format strings. */ 
#ifdef __GNUC__
#define CHECK_PRINTF(formatIdx, firstArg) \
   __attribute__ ((format (printf, formatIdx, firstArg)))
#else
#define CHECK_PRINTF(formatIdx, firstArg) 
#endif 

31
32
void log_set_severity(int severity);

33
34
35
36
37
void add_stream_log(int loglevel, const char *name, FILE *stream);
void add_file_log(int severity, const char *filename);
void close_logs();
void reset_logs();

Roger Dingledine's avatar
Roger Dingledine committed
38
/* Outputs a message to stdout */
Roger Dingledine's avatar
Roger Dingledine committed
39
void _log(int severity, const char *format, ...) CHECK_PRINTF(2,3);
Roger Dingledine's avatar
Roger Dingledine committed
40

41
#ifdef __GNUC__
42
43
void _log_fn(int severity, const char *funcname, const char *format, ...)
     CHECK_PRINTF(3,4);
44
#define log_fn(severity, args...) \
45
  _log_fn(severity, __PRETTY_FUNCTION__, args)
46
#else
Roger Dingledine's avatar
Roger Dingledine committed
47
#define log_fn _log
48
#endif
Roger Dingledine's avatar
Roger Dingledine committed
49
#define log _log /* hack it so we don't conflict with log() as much */
50

Roger Dingledine's avatar
Roger Dingledine committed
51
52
# define __LOG_H
#endif