OSDN Git Service

Merge commit 'sfj/heartbeat-ra'
[ultramonkey-l7/ultramonkey-l7-v2.git] / logger / logger_wrapper.h
1 /*
2  * @file  logger_wapprer.h
3  * @brief logger module c wrapper.
4  *
5  * L7VSD: Linux Virtual Server for Layer7 Load Balancing
6  * Copyright (C) 2008  NTT COMWARE Corporation.
7  *
8  * This program is free software; you can redistribute it and/or
9  * modify it under the terms of the GNU Lesser General Public
10  * License as published by the Free Software Foundation; either
11  * version 2.1 of the License, or (at your option) any later version.
12  *
13  * This program is distributed in the hope that it will be useful,
14  * but WITHOUT ANY WARRANTY; without even the implied warranty of
15  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
16  * Lesser General Public License for more details.
17  *
18  * You should have received a copy of the GNU Lesser General Public
19  * License along with this library; if not, write to the Free Software
20  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
21  * 02110-1301 USA
22  *      
23  **********************************************************************/
24
25 #ifndef __LOGGER_WRAPPER_H__
26 #define __LOGGER_WRAPPER_H__
27
28 #include "logger.h"
29
30 /*!
31  * retrieve category's log level.
32  * this is only wrapper to implement method.
33  * @param   category that want to know
34  * @return  log level
35  */
36 inline  enum LOG_LEVEL_TAG logger_get_log_level(const enum LOG_CATEGORY_TAG cat)
37 {
38         return l7vs::Logger::getInstance().getLogLevel(cat);
39 }
40
41 /*!
42  * set category's log level.
43  * this is only wrapper to implement method.
44  * @param   category to set log level
45  * @param   level
46  * @retval  0  succeed
47  * @retval  -1 failed
48  */
49 inline int      logger_set_log_level(const enum LOG_CATEGORY_TAG cat, const enum LOG_LEVEL_TAG level)
50 {
51         if (l7vs::Logger::getInstance().setLogLevel(cat, level)) {
52                 return 0;
53         }
54         return -1;
55 }
56
57 /*!
58  * output fatal log.
59  * this is only wrapper to implement method.
60  * @param   category that logging matter occured
61  * @param   log message id 
62  * @param   current file 
63  * @param   current line
64  * @param   log message 
65  * @retrun  void
66  */
67 inline  void    logger_put_log_fatal(const enum LOG_CATEGORY_TAG cat, const unsigned int message_id, char* file, int line, const char* message)
68 {
69         l7vs::Logger::getInstance().putLogFatal(cat, message_id, message, file, line);
70 }
71
72 /*!
73  * output error log.
74  * this is only wrapper to implement method.
75  * @param   category that logging matter occured
76  * @param   log message id 
77  * @param   current file 
78  * @param   current line
79  * @param   log message 
80  * @retrun  void
81  */
82 inline  void    logger_put_log_error(const enum LOG_CATEGORY_TAG cat, const unsigned int message_id, char* file, int line, const char* message)
83 {
84         l7vs::Logger::getInstance().putLogError(cat, message_id, message, file, line);
85 }
86
87 /*!
88  * output warn log.
89  * this is only wrapper to implement method.
90  * @param   category that logging matter occured
91  * @param   log message id 
92  * @param   current file 
93  * @param   current line
94  * @param   log message 
95  * @retrun  void
96  */
97 inline  void    logger_put_log_warn(const enum LOG_CATEGORY_TAG cat, const unsigned int  message_id, char* file, int line, const char* message)
98 {
99         l7vs::Logger::getInstance().putLogWarn(cat, message_id, message, file, line);
100 }
101
102 /*!
103  * output info log.
104  * this is only wrapper to implement method.
105  * @param   category that logging matter occured
106  * @param   log message id 
107  * @param   current file 
108  * @param   current line
109  * @param   log message 
110  * @retrun  void
111  */
112 inline  void    logger_put_log_info(const enum LOG_CATEGORY_TAG cat, const unsigned int message_id, char* file, int line, const char* message)
113 {
114         l7vs::Logger::getInstance().putLogInfo(cat, message_id, message, file, line);
115 }
116
117 /*!
118  * output debug log.
119  * this is only wrapper to implement method.
120  * @param   category that logging matter occured
121  * @param   log message id 
122  * @param   current file 
123  * @param   current line
124  * @param   log message 
125  * @retrun  void
126  */
127 inline  void    logger_put_log_debug(const enum LOG_CATEGORY_TAG cat, const unsigned int message_id, char* file, int line, const char* message)
128 {
129         l7vs::Logger::getInstance().putLogDebug(cat, message_id, message, file, line);
130 }
131
132 /*!
133  * return start category by using module.
134  * this is only wrapper to implement method.
135  * @param   module
136  * @retrun  start category
137  */
138 inline  enum LOG_CATEGORY_TAG logger_get_category_range_start(enum LOG_MODULE_TAG mod)
139 {
140         return l7vs::Logger::getInstance().getCategoryRangeStart(mod);
141 }
142
143 /*!
144  * return end category by using module.
145  * this is only wrapper to implement method.
146  * @param   module
147  * @retrun  end category
148  */
149 inline  enum LOG_CATEGORY_TAG logger_get_category_range_end(enum LOG_MODULE_TAG mod)
150 {
151         return l7vs::Logger::getInstance().getCategoryRangeEnd(mod);
152 }
153
154 #define LOGGER_PUT_LOG_FATAL(cat, message_id, message, arg...) { \
155         if (LOG_LV_FATAL >= logger_get_log_level(cat)) { \
156         char buf[BUF_LEN]; \
157         snprintf(buf, BUF_LEN, message, ##arg); \
158         logger_put_log_fatal(cat, message_id, __FILE__, __LINE__, buf); }}
159         
160 #define LOGGER_PUT_LOG_ERROR(cat, message_id, message, arg...) { \
161         if (LOG_LV_ERROR >= logger_get_log_level(cat)) { \
162         char buf[BUF_LEN]; \
163         snprintf(buf, BUF_LEN, message, ##arg); \
164         logger_put_log_error(cat, message_id, __FILE__, __LINE__, buf); }}
165
166 #define LOGGER_PUT_LOG_WARN(cat, message_id, message, arg...) { \
167         if (LOG_LV_WARN >= logger_get_log_level(cat)) { \
168         char buf[BUF_LEN]; \
169         snprintf(buf, BUF_LEN, message, ##arg); \
170         logger_put_log_warn(cat, message_id, __FILE__, __LINE__, buf); }}
171
172 #define LOGGER_PUT_LOG_INFO(cat, message_id, message, arg...) { \
173         if (LOG_LV_INFO >= logger_get_log_level(cat)) { \
174         char buf[BUF_LEN]; \
175         snprintf(buf, BUF_LEN, message, ##arg); \
176         logger_put_log_info(cat, message_id, __FILE__, __LINE__, buf); }}
177
178 #define LOGGER_PUT_LOG_DEBUG(cat, message_id, message, arg...) { \
179         char buf[BUF_LEN]; \
180         snprintf(buf, BUF_LEN, message, ##arg); \
181         logger_put_log_debug(cat, message_id, __FILE__, __LINE__, buf); }
182
183 #endif  //__LOGGER_WRAPPER_H__