log.h 1.14 KB
Newer Older
Roger Dingledine's avatar
Roger Dingledine committed
1
2
3
/* Copyright 2001,2002,2003 Roger Dingledine, Matej Pfajfar. */
/* See LICENSE for licensing information */
/* $Id$ */
Roger Dingledine's avatar
Roger Dingledine committed
4
5
6

#ifndef __LOG_H

7
#ifdef HAVE_SYSLOG_H
Roger Dingledine's avatar
Roger Dingledine committed
8
#include <syslog.h>
Roger Dingledine's avatar
Roger Dingledine committed
9
#define LOG_WARN LOG_WARNING
10
11
12
#else
#define LOG_DEBUG   0
#define LOG_INFO    1
Roger Dingledine's avatar
Roger Dingledine committed
13
#define LOG_WARN    3
14
15
#define LOG_ERR     4
#endif
Roger Dingledine's avatar
Roger Dingledine committed
16

17
18
19
20
21
22
23
24
/* 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 

25
26
void log_set_severity(int severity);

27
void add_stream_log(int loglevel, const char *name, FILE *stream);
28
int add_file_log(int severity, const char *filename);
29
30
31
void close_logs();
void reset_logs();

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

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

Roger Dingledine's avatar
Roger Dingledine committed
45
46
# define __LOG_H
#endif