summaryrefslogtreecommitdiffstats
path: root/JMXGlobals.h
blob: 924ae352ec27b51ed3b12c61c5128196a25ce53e (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
/*
 *  JMXGlobals.h
 *  JMX
 *
 *  Created by xant on 2/18/11.
 *  Copyright 2011 Dyne.org. All rights reserved.
 *
 */

// Generic syslog based logging

#ifndef __JMXGLOBALS_H__
#define __JMXGLOBALS_H__

#include <syslog.h>
#import <Foundation/NSObjCRuntime.h>
#import "JMXApplicationDelegate.h"

#define LOG_DEBUG2              (LOG_DEBUG+1)
#define LOG_DEBUG3              (LOG_DEBUG+2)
#define LOG_DEBUG4              (LOG_DEBUG+3)

#define ERROR(fmt,args...)      do { if (verbose >= LOG_ERR)     syslog(LOG_ERR,     "E: " fmt, ## args); } while (0)
#define WARNING(fmt,args...)    do { if (verbose >= LOG_WARNING) syslog(LOG_WARNING, "W: " fmt, ## args); } while (0)
#define NOTICE(fmt,args...)     do { if (verbose >= LOG_NOTICE)  syslog(LOG_NOTICE,  "N: " fmt, ## args); } while (0)
#define INFO(fmt,args...)       do { if (verbose >= LOG_INFO)    syslog(LOG_INFO,    "I: " fmt, ## args); } while (0)
#define DBG(fmt,args...)      do { if (verbose >= LOG_DEBUG)   syslog(LOG_DEBUG,   "D:%s:%d " fmt, __FUNCTION__, __LINE__, ## args); } while (0)
#define DBG2(fmt,args...)     do { if (verbose >= LOG_DEBUG2)  syslog(LOG_DEBUG,   "D2:%s:%d " fmt, __FUNCTION__, __LINE__, ## args); } while (0)
#define DBG3(fmt,args...)     do { if (verbose >= LOG_DEBUG3)  syslog(LOG_DEBUG,   "D3:%s:%d " fmt, __FUNCTION__, __LINE__, ## args); } while (0)
// Two versions that increase (decrement) and decrease (increment) the priority
#define DEBDEC(n,fmt,args...)   do { if (verbose >= LOG_DEBUG-(n)) syslog(LOG_DEBUG-(n), "V%d:%s:%d " fmt, 1-n, __FUNCTION__, __LINE__, ## args); } while (0)
#define DEBINC(n,fmt,args...)   do { if (verbose >= LOG_DEBUG+(n)) syslog(LOG_DEBUG+(n), "V%d:%s:%d " fmt, 1+n, __FUNCTION__, __LINE__, ## args); } while (0)
// Syslog is too slow for this level
//#define DPRINTF(fmt,args...)    do { if (verbose >= LOG_DEBUG4)  fprintf(stderr, fmt "\n", ## args); } while (0)

#define VERBOSE_DEFAULT         LOG_WARNING     //!< \brief default verbose level (syslog LOG_* value)


#define NSLog(__format, args...) do { [(id<JMXApplicationDelegate>)[[NSApplication sharedApplication] delegate]\
                                                          logMessage:__format, ## args ];\
                                    } while (0)

#define NSDebug(__format, args...) do {\
                                        if (verbose >= LOG_DEBUG) {\
                                            NSLog(__format, ## args);\
                                        }\
                                      } while (0)

extern int verbose;

#endif