summaryrefslogtreecommitdiff
path: root/logdefs.h
blob: 334a035eab34bcd35cd5ccda0b599b6a9fe2237f (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
/*
 * logdefs.h: Logging and debug output
 *
 * See the main source file 'xineliboutput.c' for copyright information and
 * how to reach the author.
 *
 * $Id: logdefs.h,v 1.2 2006-08-16 22:28:52 phintuka Exp $
 *
 */

#ifndef _LOGDEFS_H_

#ifndef LOG_MODULENAME
#  define LOG_MODULENAME "[xine..put] "
#endif

#define TRACELINE LOGDBG("at %s:%d %s", __FILE__, __LINE__, __FUNCTION__)


#if defined(XINELIBOUTPUT_DEBUG_STDOUT)
#  /* logging --> stdout */
#  include <stdio.h>
#  define x_syslog(l,x...) do { printf(LOG_MODULENAME x); \
                                printf("\n"); \
                           } while(0)

#elif defined(XINELIBOUTPUT_DEBUG_STDERR)
#  /* logging --> stderr */
#  include <stdio.h>
#  define x_syslog(l,x...) do { fprintf(stderr, LOG_MODULENAME x); \
                                fprintf(stderr,"\n"); \
                           } while(0)

#else
#  /* logging --> syslog */
#  include <syslog.h>
#  if defined(VDRVERSNUM) && VDRVERSNUM >= 10343
#    define x_syslog(l,x...) syslog_with_tid(l, LOG_MODULENAME x)
#  else
#    define x_syslog(l,x...) syslog(l, LOG_MODULENAME x)
#  endif
#endif

#include <errno.h>

#define LOG_ERRNO  x_syslog(LOG_ERR, "ERROR (%s,%d): %s", \
                   __FILE__, __LINE__, strerror(errno))

#define LOGERR(x...) do { \
                       if(SysLogLevel > 0) { \
                          x_syslog(LOG_ERR, x); \
                          if(errno) \
                            LOG_ERRNO; \
                       } \
                     } while(0)
#define LOGMSG(x...) do{ if(SysLogLevel > 1) x_syslog(LOG_INFO,  x); } while(0)
#define LOGDBG(x...) do{ if(SysLogLevel > 2) x_syslog(LOG_DEBUG, x); } while(0)


#ifdef XINELIBOUTPUT_DEBUG
# ifdef __cplusplus
#
#  include <fstream>
#  include <iostream>
#  include <stdio.h>
#
#  ifndef TRACE_IDENT
#    define TRACE_IDENT ""
#  endif
#  if defined(XINELIBOUTPUT_DEBUG_STDOUT)
#    define TRACE(x) do {std::cout << TRACE_IDENT << x << "\n"; fflush(stdout);}while(0)
#  elif defined(XINELIBOUTPUT_DEBUG_STDERR)
#    define TRACE(x) do {std::cerr << TRACE_IDENT << x << "\n"; fflush(stderr);}while(0)
#  else
#    error No trace target !
#  endif
#  define TRACEF(x) cTraceFunctionCall _x_cTraceFunctionCall(x);
   class cTraceFunctionCall {
     public:
       const char *m_name;
       cTraceFunctionCall(const char *name) : m_name(name)
         { TRACE(m_name << " - Enter"); }
       ~cTraceFunctionCall()
         { TRACE(m_name << " - Leave "); }
   };
# endif
#else
#  define TRACE(x)
#  define TRACEF(x)
#endif


#endif /* _LOGDEFS_H_ */