~ubuntu-branches/ubuntu/utopic/gridengine/utopic

« back to all changes in this revision

Viewing changes to source/libs/uti/sge_log.h

  • Committer: Bazaar Package Importer
  • Author(s): Mark Hymers
  • Date: 2008-06-25 22:36:13 UTC
  • Revision ID: james.westby@ubuntu.com-20080625223613-tvd9xlhuoct9kyhm
Tags: upstream-6.2~beta2
ImportĀ upstreamĀ versionĀ 6.2~beta2

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
#ifndef __SGE_LOG_H
 
2
#define __SGE_LOG_H
 
3
/*___INFO__MARK_BEGIN__*/
 
4
/*************************************************************************
 
5
 * 
 
6
 *  The Contents of this file are made available subject to the terms of
 
7
 *  the Sun Industry Standards Source License Version 1.2
 
8
 * 
 
9
 *  Sun Microsystems Inc., March, 2001
 
10
 * 
 
11
 * 
 
12
 *  Sun Industry Standards Source License Version 1.2
 
13
 *  =================================================
 
14
 *  The contents of this file are subject to the Sun Industry Standards
 
15
 *  Source License Version 1.2 (the "License"); You may not use this file
 
16
 *  except in compliance with the License. You may obtain a copy of the
 
17
 *  License at http://gridengine.sunsource.net/Gridengine_SISSL_license.html
 
18
 * 
 
19
 *  Software provided under this License is provided on an "AS IS" basis,
 
20
 *  WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING,
 
21
 *  WITHOUT LIMITATION, WARRANTIES THAT THE SOFTWARE IS FREE OF DEFECTS,
 
22
 *  MERCHANTABLE, FIT FOR A PARTICULAR PURPOSE, OR NON-INFRINGING.
 
23
 *  See the License for the specific provisions governing your rights and
 
24
 *  obligations concerning the Software.
 
25
 * 
 
26
 *   The Initial Developer of the Original Code is: Sun Microsystems, Inc.
 
27
 * 
 
28
 *   Copyright: 2001 by Sun Microsystems, Inc.
 
29
 * 
 
30
 *   All Rights Reserved.
 
31
 * 
 
32
 ************************************************************************/
 
33
/*___INFO__MARK_END__*/
 
34
 
 
35
#include <stdio.h>
 
36
#include <syslog.h>
 
37
 
 
38
#include "basis_types.h"
 
39
#include "msg_utilib.h"
 
40
 
 
41
#define LOG_PROF       0      /* no action, but it has to be printed allways */
 
42
 
 
43
void log_state_set_log_level(u_long32);
 
44
void log_state_set_log_file(char *file);
 
45
void log_state_set_log_verbose(int i);
 
46
void log_state_set_log_gui(int i);
 
47
void log_state_set_log_as_admin_user(int i);
 
48
 
 
49
char*           log_get_log_buffer(void);
 
50
 
 
51
u_long32        log_state_get_log_level(void);
 
52
const char*     log_state_get_log_file(void);
 
53
int             log_state_get_log_verbose(void);
 
54
int             log_state_get_log_gui(void);
 
55
int             log_state_get_log_as_admin_user(void);
 
56
 
 
57
void log_state_set_log_context(void *context);
 
58
 
 
59
int sge_log(int log_level, const char *mesg, const char *file__, 
 
60
            const char *func__, int line__);
 
61
 
 
62
/* extern stringTlong SGE_EVENT; */
 
63
#define SGE_EVENT log_get_log_buffer()
 
64
 
 
65
#ifdef NO_SGE_COMPILE_DEBUG
 
66
#   define SGE_FUNC ""
 
67
#endif
 
68
 
 
69
#define SGE_LOG(level,msg) sge_log(level, msg, __FILE__, SGE_FUNC, __LINE__ );
 
70
 
 
71
#if defined(__INSURE__)
 
72
#   define PROFILING(x)     (sprintf x,sge_log(LOG_PROF,   SGE_EVENT,__FILE__,SGE_FUNC,__LINE__)) ? 1 : 0
 
73
#   define CRITICAL(x) (sprintf x,sge_log(LOG_CRIT,   SGE_EVENT,__FILE__,SGE_FUNC,__LINE__)) ? 1 : 0
 
74
#   define ERROR(x)    (sprintf x,sge_log(LOG_ERR,    SGE_EVENT,__FILE__,SGE_FUNC,__LINE__)) ? 1 : 0
 
75
#   define WARNING(x)  (sprintf x,sge_log(LOG_WARNING,SGE_EVENT,__FILE__,SGE_FUNC,__LINE__)) ? 1 : 0
 
76
#   define NOTICE(x)   (sprintf x,sge_log(LOG_NOTICE, SGE_EVENT,__FILE__,SGE_FUNC,__LINE__)) ? 1 : 0
 
77
#   define INFO(x)     (sprintf x,sge_log(LOG_INFO,   SGE_EVENT,__FILE__,SGE_FUNC,__LINE__)) ? 1 : 0
 
78
#   define DEBUG(x)    (sprintf x,sge_log(LOG_DEBUG,  SGE_EVENT,__FILE__,SGE_FUNC,__LINE__)) ? 1 : 0
 
79
#else
 
80
 
 
81
/****** uti/log/PROFILING() ****************************************************
 
82
*  NAME
 
83
*     PROFILING() -- Log a profiling message 
 
84
*
 
85
*  SYNOPSIS
 
86
*     #define PROFILING(params)
 
87
*     void PROFILING(char *buffer, const char* formatstring, ...) 
 
88
*
 
89
*  FUNCTION
 
90
*     Log a profiling message 
 
91
*
 
92
*  INPUTS
 
93
*     buffer       - e.g SGE_EVENT
 
94
*     formatstring - printf formatstring
 
95
*     ...
 
96
******************************************************************************/ 
 
97
#ifdef __SGE_COMPILE_WITH_GETTEXT__
 
98
#   define PROFILING(x) (sge_set_message_id_output(1), \
 
99
                        sprintf x, \
 
100
                        sge_set_message_id_output(0), \
 
101
                        sge_log(LOG_PROF, SGE_EVENT,__FILE__,SGE_FUNC,__LINE__) ,1) ? 1 : 0
 
102
#else
 
103
#   define PROFILING(x) (sprintf x, \
 
104
                        sge_log(LOG_PROF, SGE_EVENT,__FILE__,SGE_FUNC,__LINE__) ,1) ? 1 : 0
 
105
#endif
 
106
 
 
107
/****** uti/log/CRITICAL() ****************************************************
 
108
*  NAME
 
109
*     CRITICAL() -- Log a critical message 
 
110
*
 
111
*  SYNOPSIS
 
112
*     #define CRITICAL(params)
 
113
*     void CRITICAL(char *buffer, const char* formatstring, ...) 
 
114
*
 
115
*  FUNCTION
 
116
*     Log a critical message 
 
117
*
 
118
*  INPUTS
 
119
*     buffer       - e.g SGE_EVENT
 
120
*     formatstring - printf formatstring
 
121
*     ...
 
122
******************************************************************************/ 
 
123
#ifdef __SGE_COMPILE_WITH_GETTEXT__
 
124
#   define CRITICAL(x) (sge_set_message_id_output(1), \
 
125
                        sprintf x, \
 
126
                        sge_set_message_id_output(0), \
 
127
                        sge_log(LOG_CRIT, SGE_EVENT,__FILE__,SGE_FUNC,__LINE__) ,1) ? 1 : 0
 
128
#else
 
129
#   define CRITICAL(x) (sprintf x, \
 
130
                        sge_log(LOG_CRIT, SGE_EVENT,__FILE__,SGE_FUNC,__LINE__) ,1) ? 1 : 0
 
131
#endif
 
132
 
 
133
/****** uti/log/ERROR() *******************************************************
 
134
*  NAME
 
135
*     ERROR() -- Log an error message 
 
136
*
 
137
*  SYNOPSIS
 
138
*     #define ERROR(params)
 
139
*     void ERROR(char *buffer, const char* formatstring, ...) 
 
140
*
 
141
*  FUNCTION
 
142
*     Log a error message 
 
143
*
 
144
*  INPUTS
 
145
*     buffer       - e.g SGE_EVENT
 
146
*     formatstring - printf formatstring
 
147
*     ...
 
148
******************************************************************************/ 
 
149
#ifdef __SGE_COMPILE_WITH_GETTEXT__
 
150
#   define ERROR(x) ( sge_set_message_id_output(1),                          \
 
151
                        sprintf x,                                             \
 
152
                        sge_set_message_id_output(0),                          \
 
153
                        sge_log(LOG_ERR,SGE_EVENT,__FILE__,SGE_FUNC,__LINE__), 1) ? 1 : 0
 
154
#else
 
155
#   define ERROR(x)    (sprintf x,                                             \
 
156
                        sge_log(LOG_ERR,SGE_EVENT,__FILE__,SGE_FUNC,__LINE__), 1) ? 1 : 0
 
157
#endif
 
158
 
 
159
/****** uti/log/WARNING() ******************************************************
 
160
*  NAME
 
161
*     WARNING() -- Log an warning message
 
162
*
 
163
*  SYNOPSIS
 
164
*     #define WARNING(params)
 
165
*     void WARNING(char *buffer, const char* formatstring, ...)
 
166
*
 
167
*  FUNCTION
 
168
*     Log a warning message
 
169
*
 
170
*  INPUTS
 
171
*     buffer       - e.g SGE_EVENT
 
172
*     formatstring - printf formatstring
 
173
*     ...
 
174
******************************************************************************/ 
 
175
#ifdef __SGE_COMPILE_WITH_GETTEXT__
 
176
#   define WARNING(x) ( sge_set_message_id_output(1), \
 
177
                        sprintf x,       \
 
178
                        sge_set_message_id_output(0), \
 
179
                        sge_log(LOG_WARNING,SGE_EVENT,__FILE__,SGE_FUNC,__LINE__) ,1) ? 1 : 0 
 
180
#else
 
181
#   define WARNING(x)  ( sprintf x,       \
 
182
                        sge_log(LOG_WARNING,SGE_EVENT,__FILE__,SGE_FUNC,__LINE__) ,1) ? 1 : 0
 
183
#endif
 
184
 
 
185
/****** uti/log/NOTICE() ******************************************************
 
186
*  NAME
 
187
*     NOTICE() -- Log a notice message
 
188
*
 
189
*  SYNOPSIS
 
190
*     #define NOTICE(params)
 
191
*     void NOTICE(char *buffer, const char* formatstring, ...)
 
192
*
 
193
*  FUNCTION
 
194
*     Log a notice message
 
195
*
 
196
*  INPUTS
 
197
*     buffer       - e.g SGE_EVENT
 
198
*     formatstring - printf formatstring
 
199
*     ...
 
200
******************************************************************************/ 
 
201
#   define NOTICE(x)  (sprintf x,  \
 
202
                       sge_log(LOG_NOTICE, SGE_EVENT,__FILE__,SGE_FUNC,__LINE__) ,1) ? 1 : 0
 
203
 
 
204
/****** uti/log/INFO() ********************************************************
 
205
*  NAME
 
206
*     INFO() -- Log an info message
 
207
*
 
208
*  SYNOPSIS
 
209
*     #define INFO(params)
 
210
*     void INFO(char *buffer, const char* formatstring, ...)
 
211
*
 
212
*  FUNCTION
 
213
*     Log an info message
 
214
*
 
215
*  INPUTS
 
216
*     buffer       - e.g SGE_EVENT
 
217
*     formatstring - printf formatstring
 
218
*     ...
 
219
******************************************************************************/ 
 
220
#   define INFO(x)   (sprintf x,  \
 
221
                      sge_log(LOG_INFO, SGE_EVENT,__FILE__,SGE_FUNC,__LINE__) ,1) ? 1 : 0
 
222
 
 
223
/****** uti/log/DEBUG() ******************************************************
 
224
*  NAME
 
225
*     DEBUG() -- Log a debug message
 
226
*
 
227
*  SYNOPSIS
 
228
*     #define DEBUG(params)
 
229
*     void DEBUG(char *buffer, const char* formatstring, ...)
 
230
*
 
231
*  FUNCTION
 
232
*     Log a debug message
 
233
*
 
234
*  INPUTS
 
235
*     buffer       - e.g SGE_EVENT
 
236
*     formatstring - printf formatstring
 
237
*     ...
 
238
******************************************************************************/ 
 
239
#ifdef __SGE_COMPILE_WITH_GETTEXT__
 
240
#   define DEBUG(x)  ((LOG_DEBUG <= MAX(log_state_get_log_level(), LOG_WARNING)) ? (sge_set_message_id_output(1), \
 
241
                      sprintf x, \
 
242
                      sge_set_message_id_output(0), sge_log(LOG_DEBUG, SGE_EVENT,__FILE__,SGE_FUNC,__LINE__)): 0  ,1) ? 1 : 0
 
243
 
 
244
/*                     (sge_set_message_id_output(1),  \
 
245
                        sprintf x,  \
 
246
                        sge_set_message_id_output(0), \
 
247
                        sge_log(LOG_DEBUG,  SGE_EVENT,__FILE__,SGE_FUNC,__LINE__) ,1) ? 1 : 0 */
 
248
#else
 
249
#   define DEBUG(x)    (sprintf x,  \
 
250
                        sge_log(LOG_DEBUG,  SGE_EVENT,__FILE__,SGE_FUNC,__LINE__) ,1) ? 1 : 0
 
251
#endif
 
252
#endif
 
253
 
 
254
/****** uti/log/SGE_ASSERT() **************************************************
 
255
*  NAME
 
256
*     SGE_ASSERT() -- Log a message and exit if assertion is false 
 
257
*
 
258
*  SYNOPSIS
 
259
*     #define SGE_ASSERT(expression)
 
260
*     void SGE_ASSERT(int expression) 
 
261
*
 
262
*  FUNCTION
 
263
*     Log a critical message and exit if assertion is false.
 
264
*
 
265
*  INPUTS
 
266
*     expression   - a logical expression 
 
267
******************************************************************************/
 
268
#if defined(_AIX) || defined(SVR3)
 
269
#  define SGE_ASSERT(x) \
 
270
   if (x) { \
 
271
      ; \
 
272
   } else { \
 
273
      sge_log(LOG_CRIT, # x ,__FILE__,SGE_FUNC,__LINE__); \
 
274
      sge_log(LOG_CRIT, MSG_UNREC_ERROR,__FILE__,SGE_FUNC,__LINE__); \
 
275
      abort(); \
 
276
   }
 
277
#else
 
278
#  define SGE_ASSERT(x) \
 
279
   if (x) { \
 
280
      ; \
 
281
   } else { \
 
282
      sge_log(LOG_CRIT, MSG_UNREC_ERROR,__FILE__,SGE_FUNC,__LINE__); \
 
283
      abort(); \
 
284
   }
 
285
#endif
 
286
 
 
287
#endif /* __SGE_LOG_H */
 
288