StRoot  1
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Groups Pages
rtsLog.h
1 #ifndef _RTS_LOG_H_
2 #define _RTS_LOG_H_
3 
4 /*
5  Version 2.1 Added __ROOT__ to stderr.
6  Version 2.0 Revamped to use funky variadic GNU cpp stuff...
7  Version 1.2 Added RTS_PROJECT so that the defaults work
8  even with PP2PP
9  Version 1.11 Replaced "extern __inline__" with just "inline"
10  so that Sun's CC can use it...
11  Version 1.1 Should be useful by vxWorks: I960, PPC
12  unix
13 
14 
15 */
16 
17 #ifdef __cplusplus
18 extern "C" {
19 #endif
20 
21 
22 /* colored output, :-) */
23 #define ANSI_GREEN "\033[32m"
24 #define ANSI_RED "\033[31m"
25 #define ANSI_BLUE "\033[34m"
26 #define ANSI_YELLOW "\033[33m"
27 #define ANSI_MAGENTA "\033[35m"
28 #define ANSI_CYAN "\033[36m"
29 #define ANSI_BOLD "\033[1m"
30 #define ANSI_ITALIC "\033[3m"
31 #define ANSI_UNDERLINE "\033[4m"
32 #define ANSI_REVERSE "\033[7m"
33 #define ANSI_RESET "\033[0m"
34 
35 
36 /* this is only used in the UNIX version */
37 
38 
39 #define RTS_LOG_PORT_RTS 8000
40 #define RTS_LOG_PORT_TEST 8001
41 #define RTS_LOG_PORT_DAQ 8002
42 #define RTS_LOG_PORT_TRG 8003
43 #define RTS_LOG_PORT_EVP 8004
44 #define RTS_LOG_PORT_READER 8005
45 #define RTS_LOG_PORT_TPX 8006
46 #define RTS_LOG_PORT_DB 8007
47 #define RTS_LOG_PORT_ESB 8008
48 #define RTS_LOG_PORT_L3 8009
49 #define RTS_LOG_PORT_DET 8010
50 #define RTS_LOG_PORT_EMAIL 8013
51 #define RTS_LOG_PORT_DCS 8014
52 #define RTS_LOG_PORT_ITPC 8015
53 #define RTS_LOG_PORT_FWD 8016
54 
55 #define RTS_LOG_PORT RTS_LOG_PORT_TEST /* default, test.log, port */
56 
57 /* the hostname _must_ be in the number notation! */
58 #ifdef RTS_DAQMAN
59  #define RTS_LOG_HOST RTS_DAQMAN
60 #else
61  #define RTS_LOG_HOST "130.199.60.86" /* daqman.starp */
62 #endif
63 
64 /* Bit pattern: log over network and/or stderr. Default is both. */
65 #define RTS_LOG_NET 1
66 #define RTS_LOG_STDERR 2
67 #define RTS_LOG_FILE 4
68 #define RTS_LOG_JML 8
69 
70 void rtsLogAddJmlFile (char *fname);
71 
72 /* strings used */
73 #define CRIT "CRITICAL" /* unmasked (5) */
74 #define OPER "OPERATOR" /* 4 */
75 #define ERR "ERROR" /* 3 */
76 #define WARN "WARNING" /* 2 */
77 #define NOTE "NOTICE" /* 1 */
78 #define DBG "DEBUG" /* 0 */
79 
80 #define INFO "INFO" /* unmasked */
81 
82 #define CAUTION "CAUTION" /* unmasked - for the operator */
83 
84 #define TERR "Tonko"
85 
86 #define U_TONKO "U_TONKO" /* Tonko gets email */
87 #define U_JEFF "U_JEFF" /* Jeff gets email */
88 #define U_IST "U_IST" /* IST manager gets email currently Gerrit */
89 #define U_TOF "U_TOF" /* TOF/MTD manager, Geary */
90 #define U_RP2 "U_RP2" /* New pp2pp */
91 #define SAVEme "SAVEme" /* gets saved in saved.log */
92 
93 
94 
95 #ifndef RTS_ENABLE_LOG
96 #define RTS_ASSERT(expr) assert(expr)
97 #define LOG(SEV,STRING,ARGS...)
98 #endif
99 
100 #ifdef __GNUC__
101  #define INLINE_HACK extern __inline__
102 #else
103  #define INLINE_HACK inline
104 #endif
105 
106 
107 
108 /* exists in all flavors */
109 extern volatile int tonkoLogLevel ; /* the unfortunte name is due to historic reasons... */
110 
111 extern int rtsLogAddDest(const char *server, int port) ;
112 
113 
114 INLINE_HACK void rtsLogLevelInt(int level)
115 {
116  tonkoLogLevel = level;
117  return;
118 }
119 
120 /* let's have a function too... */
121 INLINE_HACK void rtsLogLevel(const char *level)
122 {
123  switch((int) *level) {
124  case 'D' :
125  tonkoLogLevel = 0 ;
126  break ;
127  case 'N' :
128  tonkoLogLevel = 1 ;
129  break ;
130  case 'W' :
131  tonkoLogLevel = 2 ;
132  break ;
133  case 'E' :
134  tonkoLogLevel = 3 ;
135  break ;
136  case 'O' :
137  tonkoLogLevel = 4 ;
138  break ;
139  case 'C' :
140  default :
141  tonkoLogLevel = 5 ;
142  break ;
143  }
144 
145  return ;
146 }
147 
148 
149 
150 
151 
152 #ifdef __vxworks
153 /* Following is vxWorks specific */
154  #include <vxWorks.h>
155  #include <logLib.h>
156 
157  #define RTS_ASSERT(expr)
158 
159  /* Only in MVME vxworks kernels! */
160  #ifdef _ARCH_PPC
161  extern int sbLoggerStart(void) ;
162  extern int sbLOG(char *str, unsigned int a1, unsigned int a2,
163  unsigned int a3, unsigned int a4, unsigned int a5, unsigned int a6) ;
164  extern int sbLoggerRemoveDesc(int desc) ;
165  extern int sbLoggerAddDesc(int desc) ;
166  #else
167  #define sbLOG(args...)
168  #endif
169 
170 #ifdef RTS_ENABLE_LOG
171  #define LOG(SEV,STRING,A1,A2,A3,A4,A5) \
172  do { \
173  const char *const yada = SEV ; \
174  if((tonkoLogLevel>0) && (*yada == 'D')) ; \
175  else if((tonkoLogLevel>1) && (*yada == 'N')) ; \
176  else if((tonkoLogLevel>2) && (*yada == 'W')) ; \
177  else if((tonkoLogLevel>3) && (*yada == 'E')) ; \
178  else if((tonkoLogLevel>4) && (*yada == 'O')) ; \
179  else { \
180  logMsg((char *)"" SEV ": " __FILE__ " [line %d]: " STRING "\n",__LINE__,(unsigned int)A1,(unsigned int)A2,(unsigned int)A3,(unsigned int)A4,(unsigned int)A5) ; \
181  sbLOG((char *)"" SEV ": " __FILE__ " [line %d]: " STRING "\n",__LINE__,(unsigned int)A1,(unsigned int)A2,(unsigned int)A3,(unsigned int)A4,(unsigned int)A5) ; \
182  } \
183  } while(0)
184 
185 #endif // RTS_ENABLE_LOG
186 
187  #define rtsLogOutput(x)
188 
189 #else /* unix */
190 
191 #ifdef RTS_ENABLE_LOG
192  #define RTS_ASSERT(expr) LOG(CRIT,"assert(%s) true -- certain death follows",__STRING(expr))
193 #endif
194  extern int rtsLogUnix_v(const char *str, ...) ;
195 
196  extern int rtsLogOutput(int flag) ;
197 
198  extern void rtsLogAddCmd(const char *cmd) ;
199 
200  extern int rtsLogAddFile(char *fname) ;
201 
202 #ifdef RTS_ENABLE_LOG
203 #ifdef RTS_LOG_COLORED
204 
205  #define LOG(SEV,STRING,ARGS...) \
206  do { \
207  const char *const yada = SEV ; \
208  if((tonkoLogLevel>0) && (*yada == 'D')) ; \
209  else if((tonkoLogLevel>1) && (*yada == 'N')) ; \
210  else if((tonkoLogLevel>2) && (*yada == 'W')) ; \
211  else if((tonkoLogLevel>3) && (*yada == 'E')) ; \
212  else if((tonkoLogLevel>4) && (*yada == 'O')) ; \
213  else { \
214  rtsLogUnix_v("COLOR" SEV ": " __FILE__ " [line %d]: " STRING "\n" , __LINE__ , ##ARGS) ;\
215  } \
216  } while(0) \
217 
218 #else
219  #define LOG(SEV,STRING,ARGS...) \
220  do { \
221  const char *const yada = SEV ; \
222  if((tonkoLogLevel>0) && (*yada == 'D')) ; \
223  else if((tonkoLogLevel>1) && (*yada == 'N')) ; \
224  else if((tonkoLogLevel>2) && (*yada == 'W')) ; \
225  else if((tonkoLogLevel>3) && (*yada == 'E')) ; \
226  else if((tonkoLogLevel>4) && (*yada == 'O')) ; \
227  else { \
228  rtsLogUnix_v("" SEV ": " __FILE__ " [line %d]: " STRING "\n" , __LINE__ , ##ARGS) ;\
229  } \
230  } while(0) \
231 
232 
233 #endif /* RTS_LOG_COLORED */
234 #endif /* ENABLE LOG */
235 #endif /* __vxworks */
236 
237 #ifdef __cplusplus
238 }
239 #endif /* __cplusplus */
240 
241 #endif /* _RTS_LOG_H */