log.h 1.1 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>
Roger Dingledine's avatar
Roger Dingledine committed
12
#define LOG_WARN LOG_WARNING
13
14
15
#else
#define LOG_DEBUG   0
#define LOG_INFO    1
Roger Dingledine's avatar
Roger Dingledine committed
16
#define LOG_WARN    3
17
18
#define LOG_ERR     4
#endif
Roger Dingledine's avatar
Roger Dingledine committed
19

20
21
22
23
24
25
26
27
/* 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 

28
29
void log_set_severity(int severity);

30
31
32
33
34
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
35
/* Outputs a message to stdout */
Roger Dingledine's avatar
Roger Dingledine committed
36
void _log(int severity, const char *format, ...) CHECK_PRINTF(2,3);
Roger Dingledine's avatar
Roger Dingledine committed
37

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

Roger Dingledine's avatar
Roger Dingledine committed
48
49
# define __LOG_H
#endif