bottleneck testcase based on rubbos
[bottlenecks.git] / rubbos / app / tomcat-connectors-1.2.32-src / native / common / jk_logger.h
1 /*
2  *  Licensed to the Apache Software Foundation (ASF) under one or more
3  *  contributor license agreements.  See the NOTICE file distributed with
4  *  this work for additional information regarding copyright ownership.
5  *  The ASF licenses this file to You under the Apache License, Version 2.0
6  *  (the "License"); you may not use this file except in compliance with
7  *  the License.  You may obtain a copy of the License at
8  *
9  *      http://www.apache.org/licenses/LICENSE-2.0
10  *
11  *  Unless required by applicable law or agreed to in writing, software
12  *  distributed under the License is distributed on an "AS IS" BASIS,
13  *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14  *  See the License for the specific language governing permissions and
15  *  limitations under the License.
16  */
17
18 /***************************************************************************
19  * Description: Logger object definitions                                  *
20  * Author:      Gal Shachor <shachor@il.ibm.com>                           *
21  * Version:     $Revision: 1001219 $                                           *
22  ***************************************************************************/
23
24 #ifndef JK_LOGGER_H
25 #define JK_LOGGER_H
26
27 #include "jk_global.h"
28
29 #ifdef __cplusplus
30 extern "C"
31 {
32 #endif
33
34 #define JK_TIME_MAX_SIZE (64)
35
36 typedef struct jk_logger jk_logger_t;
37 struct jk_logger
38 {
39     void *logger_private;
40     int level;
41     const char *log_fmt;                   /* the configured timestamp format for logging */
42     char log_fmt_subsec[JK_TIME_MAX_SIZE]; /* like log_fmt, but milli/micro seconds marker
43                                               replaced, because strftime() doesn't handle those */
44     int    log_fmt_type;                   /* do we want milli or microseconds */
45     size_t log_fmt_offset;                 /* at which position should we insert */
46     size_t log_fmt_size;                   /* how long is this format string */
47
48     int (JK_METHOD * log) (jk_logger_t *l, int level, int used, char *what);
49
50 };
51
52 typedef struct jk_file_logger_t jk_file_logger_t;
53 struct jk_file_logger_t
54 {
55     FILE *logfile;
56     /* For Apache 2 APR piped logging */
57     void *jklogfp;
58     /* For Apache 1.3 piped logging */
59     int log_fd;
60 };
61
62 /* Level like Java tracing, but available only
63    at compile time on DEBUG preproc define.
64  */
65 #define JK_LOG_TRACE_LEVEL   0
66 #define JK_LOG_DEBUG_LEVEL   1
67 #define JK_LOG_INFO_LEVEL    2
68 #define JK_LOG_WARNING_LEVEL 3
69 #define JK_LOG_ERROR_LEVEL   4
70 #define JK_LOG_EMERG_LEVEL   5
71 #define JK_LOG_REQUEST_LEVEL 6
72 #define JK_LOG_DEF_LEVEL     JK_LOG_INFO_LEVEL
73
74 #define JK_LOG_TRACE_VERB   "trace"
75 #define JK_LOG_DEBUG_VERB   "debug"
76 #define JK_LOG_INFO_VERB    "info"
77 #define JK_LOG_WARN_VERB    "warn"
78 #define JK_LOG_ERROR_VERB   "error"
79 #define JK_LOG_EMERG_VERB   "emerg"
80 #define JK_LOG_DEF_VERB     JK_LOG_INFO_VERB
81
82 #if defined(__GNUC__) || (defined(_MSC_VER) && (_MSC_VER > 1200))
83 #define JK_LOG_TRACE   __FILE__,__LINE__,__FUNCTION__,JK_LOG_TRACE_LEVEL
84 #define JK_LOG_DEBUG   __FILE__,__LINE__,__FUNCTION__,JK_LOG_DEBUG_LEVEL
85 #define JK_LOG_ERROR   __FILE__,__LINE__,__FUNCTION__,JK_LOG_ERROR_LEVEL
86 #define JK_LOG_EMERG   __FILE__,__LINE__,__FUNCTION__,JK_LOG_EMERG_LEVEL
87 #define JK_LOG_INFO    __FILE__,__LINE__,__FUNCTION__,JK_LOG_INFO_LEVEL
88 #define JK_LOG_WARNING __FILE__,__LINE__,__FUNCTION__,JK_LOG_WARNING_LEVEL
89 #else
90 #define JK_LOG_TRACE   __FILE__,__LINE__,NULL,JK_LOG_TRACE_LEVEL
91 #define JK_LOG_DEBUG   __FILE__,__LINE__,NULL,JK_LOG_DEBUG_LEVEL
92 #define JK_LOG_ERROR   __FILE__,__LINE__,NULL,JK_LOG_ERROR_LEVEL
93 #define JK_LOG_EMERG   __FILE__,__LINE__,NULL,JK_LOG_EMERG_LEVEL
94 #define JK_LOG_INFO    __FILE__,__LINE__,NULL,JK_LOG_INFO_LEVEL
95 #define JK_LOG_WARNING __FILE__,__LINE__,NULL,JK_LOG_WARNING_LEVEL
96 #endif
97
98 #define JK_LOG_REQUEST __FILE__,0,NULL,JK_LOG_REQUEST_LEVEL
99
100 #if defined(JK_PRODUCTION)
101 /* TODO: all DEBUG messages should be compiled out
102  * when this define is in place.
103  */
104 #define JK_IS_PRODUCTION    1
105 #define JK_TRACE_ENTER(l)
106 #define JK_TRACE_EXIT(l)
107 #else
108 #define JK_IS_PRODUCTION    0
109 #define JK_TRACE_ENTER(l)                               \
110     do {                                                \
111         if ((l) && (l)->level == JK_LOG_TRACE_LEVEL) {  \
112             int tmp_errno = errno;                      \
113             jk_log((l), JK_LOG_TRACE, "enter");         \
114             errno = tmp_errno;                          \
115     } } while (0)
116
117 #define JK_TRACE_EXIT(l)                                \
118     do {                                                \
119         if ((l) && (l)->level == JK_LOG_TRACE_LEVEL) {  \
120             int tmp_errno = errno;                      \
121             jk_log((l), JK_LOG_TRACE, "exit");          \
122             errno = tmp_errno;                          \
123     } } while (0)
124
125 #endif  /* JK_PRODUCTION */
126
127 #define JK_LOG_NULL_PARAMS(l) jk_log((l), JK_LOG_ERROR, "NULL parameters")
128
129 /* Debug level macro
130  * It is more efficient to check the level prior
131  * calling function that will not execute anyhow because of level
132  */
133 #define JK_IS_DEBUG_LEVEL(l)  ((l) && (l)->level <  JK_LOG_INFO_LEVEL)
134
135
136 #ifdef __cplusplus
137 }
138 #endif      /* __cplusplus */
139 #endif      /* JK_LOGGER_H */