OSDN Git Service

Temporary implementation of insert X-Forwarded-For.
[ultramonkey-l7/sslproxy.git] / logger / logger_impl.cpp
1 /*
2  * @file  logger_impl.cpp
3  * @brief logger module implementation class.
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 #include <sstream>
26 #include <iomanip>
27 #include <limits.h>
28 #include <log4cxx/logmanager.h>
29 #include <log4cxx/helpers/loglog.h>
30 #include <log4cxx/rolling/rollingfileappender.h>
31 #include <log4cxx/rolling/fixedwindowrollingpolicy.h>
32 #include <log4cxx/rolling/sizebasedtriggeringpolicy.h>
33 #include <log4cxx/rolling/timebasedrollingpolicy.h>
34 #include <log4cxx/consoleappender.h>
35 #include <errno.h>
36 #include <stdexcept>
37
38 #include "logger_impl.h"
39 #include "parameter.h"
40 #include "lexical_cast.h"
41 #include "strict_time_based_rolling_policy.h"
42 #include "time_and_size_based_rolling_policy.h"
43
44 #define LOGGER_LAYOUT "%d{%Y/%m/%d %H:%M:%S} [%p] %c %m %t %F:%L%n"
45 #define LOGGER_DEFAULT_BUFFER_SIZE (8 * 1024)
46 #define LOGGER_SYSLOG_FACILITY "USER"
47 #define LOGGER_BACKUP_INDEX_LOWER_LIMIT (1)
48 #define LOGGER_BACKUP_INDEX_LIMIT (12)
49 #define LOGGER_FILESIZE_LOWER_LIMIT (65535)
50 #define LOGGER_FILE_PATTERN "%i"
51
52 #define LOGGER_LOG_FILENAME_KEY "sslproxy_log_filename"
53 #define LOGGER_ROTATION_KEY "sslproxy_rotation"
54 #define LOGGER_MAX_BACKUP_INDEX_KEY "sslproxy_max_backup_index"
55 #define LOGGER_MAX_FILE_SIZE_KEY "sslproxy_max_filesize"
56 #define LOGGER_ROTATION_TIMING_KEY "sslproxy_rotation_timing"
57 #define LOGGER_ROTATION_TIMING_VALUE_KEY "sslproxy_rotation_timing_value"
58
59 #define LOGGER_CONN_LOG_FILENAME_KEY "conn_log_filename"
60 #define LOGGER_CONN_ROTATION_KEY "conn_rotation"
61 #define LOGGER_CONN_MAX_BACKUP_INDEX_KEY "conn_max_backup_index"
62 #define LOGGER_CONN_MAX_FILE_SIZE_KEY "conn_max_filesize"
63 #define LOGGER_CONN_ROTATION_TIMING_KEY "conn_rotation_timing"
64 #define LOGGER_CONN_ROTATION_TIMING_VALUE_KEY "conn_rotation_timing_value"
65
66 //! for transration between log4cxx::LevelPtr and LOGER_LEVEL_TAG
67 char l7vs::LoggerImpl::categoryTable[][LOGGER_CATEGORY_NUM] = { 
68         "none",
69         "sslproxy_logger",
70         "sslproxy_parameter",
71         "sslproxy_common",
72         "sslproxy_server",
73         "sslproxy_session",
74         "sslproxy_connection",
75         "http",
76         "end"
77         };
78
79 //! for transration between string and LOGGER_CATEGORY_TAG
80 log4cxx::LevelPtr l7vs::LoggerImpl::levelTable[LOGGER_LEVEL_NUM];
81
82 /*!
83  * returns single instance.
84  *
85  * @param   void
86  * @return  instance
87  */
88 l7vs::LoggerImpl& l7vs::LoggerImpl::getInstance()
89 {
90         if (!instance) {
91                 instance = new LoggerImpl;
92         }
93         return *instance;
94 }
95
96 //! static Logger instance pointer initialized by 0.
97 l7vs::LoggerImpl* l7vs::LoggerImpl::instance = 0;
98
99 /*!
100  * initialize function.
101  * logger initialized to use syslogappender and fileappender(/dev/console)
102  *
103  * @param   void
104  * @retval  true succeed
105  * @retval  false failed
106  */
107 bool l7vs::LoggerImpl::init()
108 {
109         int ret = 0;
110         if (initialized) return false;
111
112         try {
113                 log4cxx::LoggerPtr root = log4cxx::Logger::getRootLogger();
114                 if (0 == root) {
115                         return false;
116                 }
117                 log4cxx::LayoutPtr layout =
118                         new log4cxx::PatternLayout(LOGGER_LAYOUT);
119                 log4cxx::net::SyslogAppenderPtr syslogAppender =
120                         new log4cxx::net::SyslogAppender(layout, log4cxx::net::SyslogAppender::getFacility(LOGGER_SYSLOG_FACILITY));
121                 root->addAppender(syslogAppender);
122                 log4cxx::WriterAppender* consoleAppender =
123                         new log4cxx::ConsoleAppender( layout, log4cxx::ConsoleAppender::getSystemErr() );
124                 root->addAppender(consoleAppender);
125
126                 for (LOG_CATEGORY_TAG cat = LOG_CAT_NONE; cat < LOG_CAT_END; ++cat) {
127                         log4cxx::Logger::getLogger(categoryTable[cat])->setLevel(categoryLevel[cat]);
128                 }
129         }
130         catch (const std::exception& e) {
131                 std::ostringstream oss;
132                 oss <<  "Logger Initialization Failed : " << e.what();
133                 errorConf(6, oss.str(), __FILE__, __LINE__);
134                 return false;
135         }
136         
137         ret = gethostname(hostname, HOST_NAME_LEN);
138         if (0 > ret) {
139                 if (LOG_LV_WARN >= this->getLogLevel(loggerCategory)) {
140                         this->putLogWarn(loggerCategory,1, "Fail to get Hostname", __FILE__, __LINE__);
141                 }
142         }       
143
144         if (LOG_LV_INFO >= this->getLogLevel(loggerCategory)) {
145                 this->putLogInfo(loggerCategory,1, "Logger Initialized.", __FILE__, __LINE__);
146         }
147
148         initialized = true;
149         return true;
150 }
151
152 /*!
153  * error handling function.
154  * if error occured, switch appenders to syslogappender and fileappender(/dev/console)
155  * message will output to syslog/fileappender appender
156  * 
157  * @param   log message id 
158  * @param   log message 
159  * @param   current file 
160  * @param   current line
161  * @return  void
162  */
163 void l7vs::LoggerImpl::errorConf(unsigned int message_id, const std::string& errorMessage, const char* file, int line)
164 {
165         try {
166                 log4cxx::LogManager::resetConfiguration();
167                 log4cxx::LoggerPtr root = log4cxx::Logger::getRootLogger();
168                 if (0 == root)
169                         return;
170                 log4cxx::LayoutPtr layout =
171                         new log4cxx::PatternLayout(LOGGER_LAYOUT);
172                 log4cxx::net::SyslogAppenderPtr syslogAppender =
173                         new log4cxx::net::SyslogAppender(layout, log4cxx::net::SyslogAppender::getFacility(LOGGER_SYSLOG_FACILITY));
174                 log4cxx::ConsoleAppender* consoleAppender = new log4cxx::ConsoleAppender(layout, log4cxx::ConsoleAppender::getSystemErr() );
175                 root->addAppender(consoleAppender);
176                 root->addAppender(syslogAppender);
177
178                 for (LOG_CATEGORY_TAG cat = LOG_CAT_NONE; cat < LOG_CAT_END; ++cat) {
179                         log4cxx::Logger::getLogger(categoryTable[cat])->setLevel(categoryLevel[cat]);
180                 }
181
182                 char buf[BUF_LEN];
183                 snprintf(buf, BUF_LEN, "%s%d%03d%04d %s %s", LOGGER_PROCESS_ID, LOG_LV_FATAL, loggerCategory, message_id, errorMessage.c_str(), hostname);
184                 log4cxx::Logger::getLogger(categoryTable[loggerCategory])->forcedLog(log4cxx::Level::getFatal(), buf, log4cxx::spi::LocationInfo(file, "", line));
185         }
186         catch (const std::exception& e) {
187                 std::ostringstream oss;
188                 oss <<  "Logger Error Output Failed : " << e.what() << "\n";
189                 fputs(oss.str().c_str(), stderr);
190         }
191 }
192
193 /*!
194  * load the logger parameter.
195  * get settings from parameter component, and configure log4cxx property
196  *
197  * @param   void
198  * @return  void
199  */
200 void l7vs::LoggerImpl::loadConf()
201 {
202         for (LOG_CATEGORY_TAG cat = LOG_CAT_NONE; cat < LOG_CAT_END; ++cat) {
203                 if (cat == LOG_CAT_SSLPROXY_CONNECTION) {
204                         // Connection category Logger setting.
205                         log_filename_key          = LOGGER_CONN_LOG_FILENAME_KEY;
206                         rotation_key              = LOGGER_CONN_ROTATION_KEY;
207                         max_backup_index_key      = LOGGER_CONN_MAX_BACKUP_INDEX_KEY;
208                         max_file_size_key         = LOGGER_CONN_MAX_FILE_SIZE_KEY;
209                         rotation_timing_key       = LOGGER_CONN_ROTATION_TIMING_KEY;
210                         rotation_timing_value_key = LOGGER_CONN_ROTATION_TIMING_VALUE_KEY;
211                         /*-------- DEBUG LOG for sslproxy --------*/
212                         if (LOG_LV_DEBUG >= this->getLogLevel(loggerCategory)) {
213                                 std::ostringstream oss;
214                                 oss << "function : void l7vs::LoggerImpl::loadConf() : "
215                                     << "Connection category Logger setting. "
216                                     << "cat = " << cat;
217                                 this->putLogDebug(loggerCategory, 1, oss.str(), __FILE__, __LINE__);
218                         }
219                         /*------ DEBUG LOG END for sslproxy ------*/
220                 } else {
221                         // Other category Logger setting.
222                         log_filename_key          = LOGGER_LOG_FILENAME_KEY;
223                         rotation_key              = LOGGER_ROTATION_KEY;
224                         max_backup_index_key      = LOGGER_MAX_BACKUP_INDEX_KEY;
225                         max_file_size_key         = LOGGER_MAX_FILE_SIZE_KEY;
226                         rotation_timing_key       = LOGGER_ROTATION_TIMING_KEY;
227                         rotation_timing_value_key = LOGGER_ROTATION_TIMING_VALUE_KEY;
228                         /*-------- DEBUG LOG for sslproxy --------*/
229                         if (LOG_LV_DEBUG >= this->getLogLevel(loggerCategory) &&
230                             cat != LOG_CAT_SSLPROXY_LOGGER) {
231                                 std::ostringstream oss;
232                                 oss << "function : void l7vs::LoggerImpl::loadConf() : "
233                                     << "Other category Logger setting. "
234                                     << "cat = " << cat;
235                                 this->putLogDebug(loggerCategory, 2, oss.str(), __FILE__, __LINE__);
236                         }
237                         /*------ DEBUG LOG END for sslproxy ------*/
238                 }
239                 loadCategoryLoggerConf(cat);
240         }
241         if (LOG_LV_INFO >= this->getLogLevel(loggerCategory)) {
242                 std::ostringstream oss;
243                 oss << "Logger Configuration Succeed.";
244                 this->putLogInfo(loggerCategory,2, oss.str(), __FILE__, __LINE__);
245         }
246
247         /*-------- DEBUG LOG for sslproxy --------*/
248         if (LOG_LV_DEBUG >= this->getLogLevel(loggerCategory)) {
249                 std::ostringstream oss;
250                 oss << "out_function : void l7vs::LoggerImpl::loadConf() : "
251                     << "loadCategoryLoggerConf() END.";
252                 this->putLogDebug(loggerCategory, 3, oss.str(), __FILE__, __LINE__);
253         }
254         /*------ DEBUG LOG END for sslproxy ------*/
255 }
256
257 /*!
258  * load the category logger parameter.
259  * get settings from parameter component of each category, and configure log4cxx property
260  *
261  * @param[in]   catnum  LOG_CATEGORY_TAG
262  * @return  void
263  */
264 void l7vs::LoggerImpl::loadCategoryLoggerConf(LOG_CATEGORY_TAG catnum)
265 {
266         std::string ret;
267
268         //get log filename
269         if (l7vs::Parameter::getInstance().isStringExist(PARAM_COMP_LOGGER, log_filename_key)) {
270                 logFilename = l7vs::Parameter::getInstance().getStringValue(PARAM_COMP_LOGGER, log_filename_key);
271         }
272         else {
273                 if (LOG_LV_ERROR >= this->getLogLevel(loggerCategory)) {
274                         this->putLogError(loggerCategory,1, "Not Exist Log Filename Setting.", __FILE__, __LINE__);
275                 }
276                 throw std::logic_error("Not Exist Log Filename Setting.");
277         }
278         
279         //get rotation
280         if (l7vs::Parameter::getInstance().isStringExist(PARAM_COMP_LOGGER, rotation_key)) {
281                 std::string rotationStr = l7vs::Parameter::getInstance().getStringValue(PARAM_COMP_LOGGER, rotation_key);
282                 if ("size" == rotationStr) rotation = LOG_ROT_SIZE;
283                 else if ("date" == rotationStr) rotation = LOG_ROT_DATE;
284                 else if ("datesize" == rotationStr) rotation = LOG_ROT_DATESIZE;
285                 else {
286                         if (LOG_LV_ERROR >= this->getLogLevel(loggerCategory)) {
287                                 this->putLogError(loggerCategory,2, "Invalid Log Rotation Setting.", __FILE__, __LINE__);
288                         }
289                         throw std::logic_error("Invalid Log Rotation Setting.");
290                 }
291         }
292         else {
293                 if (LOG_LV_ERROR >= this->getLogLevel(loggerCategory)) {
294                         this->putLogError(loggerCategory,3, "Not Exist Log Rotation Setting.", __FILE__, __LINE__);
295                 }
296                 throw std::logic_error("Not Exist Log Rotation Setting.");
297         }
298
299         //get max backup index
300         if (l7vs::Parameter::getInstance().isStringExist(PARAM_COMP_LOGGER, max_backup_index_key)) {
301                 std::string maxBackupIndexStr = l7vs::Parameter::getInstance().getStringValue(PARAM_COMP_LOGGER, max_backup_index_key);
302                 try {
303                         maxBackupIndex = lexical_cast<unsigned int>(maxBackupIndexStr);
304                 }
305                 catch (const l7vs::bad_lexical_cast& bc) {
306                         if (LOG_LV_ERROR >= this->getLogLevel(loggerCategory)) {
307                                 this->putLogError(loggerCategory,4, "Invalid MaxBackupIndex Value.", __FILE__, __LINE__);
308                         }
309                         throw std::logic_error("Invalid MaxBackupIndex Value.");
310                 }
311                 if (LOGGER_BACKUP_INDEX_LOWER_LIMIT > maxBackupIndex) {
312                         std::ostringstream oss;
313                         oss << "Max Backup Index must at least " << LOGGER_BACKUP_INDEX_LOWER_LIMIT << ".";
314                         if (LOG_LV_ERROR >= this->getLogLevel(loggerCategory)) {
315                                 this->putLogError(loggerCategory,5, oss.str(), __FILE__, __LINE__);
316                         }
317                         throw std::logic_error(oss.str());
318                 }               
319                 if (LOGGER_BACKUP_INDEX_LIMIT < maxBackupIndex) {
320                         std::ostringstream oss;
321                         oss << "Max Backup Index must at most " << LOGGER_BACKUP_INDEX_LIMIT << ".";
322                         if (LOG_LV_ERROR >= this->getLogLevel(loggerCategory)) {
323                                 this->putLogError(loggerCategory,6, oss.str(), __FILE__, __LINE__);
324                         }
325                         throw std::logic_error(oss.str());
326                 }               
327         }
328         else {
329                 if (LOG_LV_ERROR >= this->getLogLevel(loggerCategory)) {
330                         this->putLogError(loggerCategory,7, "Not Exist Log MaxBackupIndex Setting.", __FILE__, __LINE__);
331                 }
332                 throw std::logic_error("Not Exist Log MaxBackupIndex Setting.");
333         }
334
335         if (LOG_ROT_SIZE == rotation || LOG_ROT_DATESIZE == rotation) {
336                 // get max file size
337                 std::string maxFileSizeStr;
338                 if (l7vs::Parameter::getInstance().isStringExist(PARAM_COMP_LOGGER, max_file_size_key)) {
339                         maxFileSizeStr = l7vs::Parameter::getInstance().getStringValue(PARAM_COMP_LOGGER, max_file_size_key);
340                 }
341                 else {
342                         if (LOG_LV_ERROR >= this->getLogLevel(loggerCategory)) {
343                                 this->putLogError(loggerCategory,8, "Not Exist Log MaxFileSize Setting.", __FILE__, __LINE__);
344                         }
345                         throw std::logic_error("Not Exist Log MaxFileSize Setting.");
346                 }
347                 
348                 std::string size_val;
349                 std::string last_str = maxFileSizeStr.substr(maxFileSizeStr.length() - 1, 1);
350                 // when unit was specified
351                 if (("K" == last_str) || ("M" == last_str) || ("G" == last_str)) {
352                         size_val = maxFileSizeStr.substr(0, maxFileSizeStr.length() - 1);
353                 }
354                 else {
355                         size_val = maxFileSizeStr;
356                 }
357                         
358                 try {
359                         maxFileSize = lexical_cast<size_t>(size_val);
360                 }
361                 catch (const l7vs::bad_lexical_cast& bc) {
362                         if (LOG_LV_ERROR >= this->getLogLevel(loggerCategory)) {
363                                 this->putLogError(loggerCategory,9, "Invalid FileSize Value.", __FILE__, __LINE__);
364                         }
365                         throw std::logic_error("Invalid FileSize Value.");
366                 }
367
368                 if ("K" == last_str) {
369                         if ((ULLONG_MAX / 1024) < maxFileSize) {
370                                 if (LOG_LV_ERROR >= this->getLogLevel(loggerCategory)) {
371                                         this->putLogError(loggerCategory,10, "Invalid FileSize Value.", __FILE__, __LINE__);
372                                 }
373                                 throw std::logic_error("Invalid FileSize Value.");
374                         }
375                         maxFileSize = maxFileSize * 1024;
376                 }
377                 else if ("M" == last_str) {
378                         if ((ULLONG_MAX / 1024 / 1024) < maxFileSize) {
379                                 if (LOG_LV_ERROR >= this->getLogLevel(loggerCategory)) {
380                                         this->putLogError(loggerCategory,11, "Invalid FileSize Value.", __FILE__, __LINE__);
381                                 }
382                                 throw std::logic_error("Invalid FileSize Value.");
383                         }
384                         maxFileSize = maxFileSize * 1024 * 1024;
385                 }
386                 else if ("G" == last_str) {
387                         if ((ULLONG_MAX / 1024 / 1024 / 1024) < maxFileSize) {
388                                 if (LOG_LV_ERROR >= this->getLogLevel(loggerCategory)) {
389                                         this->putLogError(loggerCategory,12, "Invalid FileSize Value.", __FILE__, __LINE__);
390                                 }
391                                 throw std::logic_error("Invalid FileSize Value.");
392                         }
393                         maxFileSize = maxFileSize * 1024 * 1024 * 1024;
394                 }
395                 if (LOGGER_FILESIZE_LOWER_LIMIT > maxFileSize) {
396                         int limit = LOGGER_FILESIZE_LOWER_LIMIT;
397                         std::ostringstream oss;
398                         oss << "FileSize must at least " << limit << " bytes.";
399                         if (LOG_LV_ERROR >= this->getLogLevel(loggerCategory)) {
400                                 this->putLogError(loggerCategory,13, oss.str(), __FILE__, __LINE__);
401                         }
402                         throw std::logic_error(oss.str());
403                 }
404         }
405
406         if (LOG_ROT_DATE == rotation || LOG_ROT_DATESIZE == rotation) {
407                 // get rotation timing
408                 if (l7vs::Parameter::getInstance().isStringExist(PARAM_COMP_LOGGER, rotation_timing_key)) {
409                         std::string rotationTimingStr = l7vs::Parameter::getInstance().getStringValue(PARAM_COMP_LOGGER, rotation_timing_key);
410                         if ("year" == rotationTimingStr) rotationTiming = LOG_TIM_YEAR;
411                         else if ("month" == rotationTimingStr) rotationTiming = LOG_TIM_MONTH;
412                         else if ("week" == rotationTimingStr) rotationTiming = LOG_TIM_WEEK;
413                         else if ("date" == rotationTimingStr) rotationTiming = LOG_TIM_DATE;
414                         else if ("hour" == rotationTimingStr) rotationTiming = LOG_TIM_HOUR;
415                         else {
416                                 if (LOG_LV_ERROR >= this->getLogLevel(loggerCategory)) {
417                                         this->putLogError(loggerCategory,14, "Invalid Log RotationTiming Setting.", __FILE__, __LINE__);
418                                 }
419                                 throw std::logic_error("Invalid Log RotationTiming Setting.");
420                         }
421                 }
422                 else {
423                         if (LOG_LV_ERROR >= this->getLogLevel(loggerCategory)) {
424                                 this->putLogError(loggerCategory,15, "Not Exist Log RotaionTiming Setting.", __FILE__, __LINE__);
425                         }
426                         throw std::logic_error("Not Exist Log RotaionTiming Setting.");
427                 }
428
429                 if (LOG_TIM_YEAR == rotationTiming) {
430                         if (l7vs::Parameter::getInstance().isStringExist(PARAM_COMP_LOGGER, rotation_timing_value_key)) {
431                                 ret = l7vs::Parameter::getInstance().getStringValue(PARAM_COMP_LOGGER, rotation_timing_value_key);
432
433                                 std::string::size_type fpos = 0;
434                                 std::string::size_type rpos = 0;
435                                 int month = 0;
436                                 int date = 0;
437                                 int hour = 0;
438                                 int minute = 0;
439                                 // find month
440                                 rpos = ret.find_first_of('/', fpos);
441                                 if (std::string::npos != rpos) {
442                                         std::string monthStr = ret.substr(fpos, rpos - fpos);
443                                         try {
444                                                 month = lexical_cast<int>(monthStr);
445                                         }
446                                         catch (const l7vs::bad_lexical_cast& bc) {
447                                                 if (LOG_LV_ERROR >= this->getLogLevel(loggerCategory)) {
448                                                         this->putLogError(loggerCategory,16, "Parse Timing Year Error.", __FILE__, __LINE__);
449                                                 }
450                                                 throw std::logic_error("Parse Timing Year Error.");
451                                         }
452                                         if (1 > month || month > 12) {
453                                                 if (LOG_LV_ERROR >= this->getLogLevel(loggerCategory)) {
454                                                         this->putLogError(loggerCategory,17, "Parse Timing Year Error.", __FILE__, __LINE__);
455                                                 }
456                                                 throw std::logic_error("Parse Timing Year Error.");
457                                         }
458                                         fpos = rpos + 1;
459                                         // find date
460                                         rpos = ret.find_first_of(' ', fpos);
461                                         if (std::string::npos != rpos) {
462                                                 std::string dateStr = ret.substr(fpos, rpos - fpos);
463                                                 try {
464                                                         date = lexical_cast<int>(dateStr);
465                                                 }
466                                                 catch (const l7vs::bad_lexical_cast& bc) {
467                                                         if (LOG_LV_ERROR >= this->getLogLevel(loggerCategory)) {
468                                                                 this->putLogError(loggerCategory,18, "Parse Timing Year Error.", __FILE__, __LINE__);
469                                                         }
470                                                         throw std::logic_error("Parse Timing Year Error.");
471                                                 }
472                                                 if (1 > date || date > 31) {
473                                                         if (LOG_LV_ERROR >= this->getLogLevel(loggerCategory)) {
474                                                                 this->putLogError(loggerCategory,19, "Parse Timing Year Error.", __FILE__, __LINE__);
475                                                         }
476                                                         throw std::logic_error("Parse Timing Year Error.");
477                                                 }
478                                                 int dates[] = {31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};
479                                                 if (date > dates[month - 1]) {
480                                                         if (LOG_LV_ERROR >= this->getLogLevel(loggerCategory)) {
481                                                                 this->putLogError(loggerCategory,20, "Parse Timing Year Error.", __FILE__, __LINE__);
482                                                         }
483                                                         throw std::logic_error("Parse Timing Year Error.");
484                                                 }
485                                                 fpos = rpos + 1;
486                                                 // find hour 
487                                                 rpos = ret.find_first_of(':', fpos);
488                                                 if (std::string::npos != rpos) {
489                                                         std::string hourStr = ret.substr(fpos, rpos - fpos);
490                                                         try {
491                                                                 hour = lexical_cast<int>(hourStr);
492                                                         }
493                                                         catch (const l7vs::bad_lexical_cast& bc) {
494                                                                 if (LOG_LV_ERROR >= this->getLogLevel(loggerCategory)) {
495                                                                         this->putLogError(loggerCategory,21, "Parse Timing Year Error.", __FILE__, __LINE__);
496                                                                 }
497                                                                 throw std::logic_error("Parse Timing Year Error.");
498                                                         }
499                                                         if (0 > hour || hour > 23) {
500                                                                 if (LOG_LV_ERROR >= this->getLogLevel(loggerCategory)) {
501                                                                         this->putLogError(loggerCategory,22, "Parse Timing Year Error.", __FILE__, __LINE__);
502                                                                 }
503                                                                 throw std::logic_error("Parse Timing Year Error.");
504                                                         }
505                                                         // minute
506                                                         std::string minuteStr = ret.substr(rpos + 1);
507                                                         try {
508                                                                 minute = lexical_cast<int>(minuteStr);
509                                                         }
510                                                         catch (const l7vs::bad_lexical_cast& bc) {
511                                                                 if (LOG_LV_ERROR >= this->getLogLevel(loggerCategory)) {
512                                                                         this->putLogError(loggerCategory,23, "Parse Timing Year Error.", __FILE__, __LINE__);
513                                                                 }
514                                                                 throw std::logic_error("Parse Timing Year Error.");
515                                                         }
516                                                         if (0 > minute || minute > 59) {
517                                                                 if (LOG_LV_ERROR >= this->getLogLevel(loggerCategory)) {
518                                                                         this->putLogError(loggerCategory,24, "Parse Timing Year Error.", __FILE__, __LINE__);
519                                                                 }
520                                                                 throw std::logic_error("Parse Timing Year Error.");
521                                                         }
522                                                 }
523                                                 else {
524                                                         if (LOG_LV_ERROR >= this->getLogLevel(loggerCategory)) {
525                                                                 this->putLogError(loggerCategory,25, "Parse Timing Year Error.", __FILE__, __LINE__);
526                                                         }
527                                                         throw std::logic_error("Parse Timing Year Error.");
528                                                 }
529                                         }
530                                         else {
531                                                 if (LOG_LV_ERROR >= this->getLogLevel(loggerCategory)) {        
532                                                         this->putLogError(loggerCategory,26, "Parse Timing Year Error.", __FILE__, __LINE__);
533                                                 }
534                                                 throw std::logic_error("Parse Timing Year Error.");
535                                         }
536                                 }
537                                 else {
538                                         if (LOG_LV_ERROR >= this->getLogLevel(loggerCategory)) {
539                                                 this->putLogError(loggerCategory,27, "Parse Timing Year Error.", __FILE__, __LINE__);
540                                         }
541                                         throw std::logic_error("Parse Timing Year Error.");
542                                 }
543
544                                 // format to internal rotation timing value expresson
545                                 std::ostringstream oss;
546                                 oss << std::setfill('0') << std::setw(2) << month
547                                         << std::setfill('0') << std::setw(2) << date
548                                         << std::setfill('0') << std::setw(2) << hour
549                                         << std::setfill('0') << std::setw(2) << minute;
550                                 
551                                 rotationTimingValue = oss.str();
552
553                         }
554                         else {
555                                 if (LOG_LV_ERROR >= this->getLogLevel(loggerCategory)) {
556                                         this->putLogError(loggerCategory,28, "Not Exist Log RotaionTiming Year Setting.", __FILE__, __LINE__);
557                                 }
558                                 throw std::logic_error("Not Exist Log RotaionTiming Year Setting.");
559                         }
560                 }
561
562                 if (LOG_TIM_MONTH == rotationTiming) {
563                         if (l7vs::Parameter::getInstance().isStringExist(PARAM_COMP_LOGGER, rotation_timing_value_key)) {
564                                 ret = l7vs::Parameter::getInstance().getStringValue(PARAM_COMP_LOGGER, rotation_timing_value_key);
565
566                                 std::string::size_type fpos = 0;
567                                 std::string::size_type rpos = 0;
568                                 int date = 0;
569                                 int hour = 0;
570                                 int minute = 0;
571                                 // find day
572                                 rpos = ret.find_first_of(' ', fpos);
573                                 if (std::string::npos != rpos) {
574                                         std::string dateStr = ret.substr(fpos, rpos - fpos);
575                                         try {
576                                                 date = lexical_cast<int>(dateStr);
577                                         }
578                                         catch (const l7vs::bad_lexical_cast& bc) {
579                                                 if (LOG_LV_ERROR >= this->getLogLevel(loggerCategory)) {
580                                                         this->putLogError(loggerCategory,29, "Parse Timing Month Error.", __FILE__, __LINE__);
581                                                 }
582                                                 throw std::logic_error("Parse Timing Month Error.");
583                                         }
584                                         if (1 > date || date > 31) {
585                                                 if (LOG_LV_ERROR >= this->getLogLevel(loggerCategory)) {
586                                                         this->putLogError(loggerCategory,30, "Parse Timing Month Error.", __FILE__, __LINE__);
587                                                 }
588                                                 throw std::logic_error("Parse Timing Month Error.");
589                                         }
590                                         fpos = rpos + 1;
591                                         // find hour
592                                         rpos = ret.find_first_of(':', fpos);
593                                         if (std::string::npos != rpos) {
594                                                 std::string hourStr = ret.substr(fpos, rpos - fpos);
595                                                 try {
596                                                         hour = lexical_cast<int>(hourStr);
597                                                 }
598                                                 catch (const l7vs::bad_lexical_cast& bc) {
599                                                         if (LOG_LV_ERROR >= this->getLogLevel(loggerCategory)) {
600                                                                 this->putLogError(loggerCategory,31, "Parse Timing Month Error.", __FILE__, __LINE__);
601                                                         }
602                                                         throw std::logic_error("Parse Timing Month Error.");
603                                                 }
604                                                 if (0 > hour || hour > 23) {
605                                                         if (LOG_LV_ERROR >= this->getLogLevel(loggerCategory)) {
606                                                                 this->putLogError(loggerCategory,32, "Parse Timing Month Error.", __FILE__, __LINE__);
607                                                         }
608                                                         throw std::logic_error("Parse Timing Month Error.");
609                                                 }
610                                                 // minute
611                                                 std::string minuteStr = ret.substr(rpos + 1);
612                                                 try {
613                                                         minute = lexical_cast<int>(minuteStr);
614                                                 }
615                                                 catch (const l7vs::bad_lexical_cast& bc) {
616                                                         if (LOG_LV_ERROR >= this->getLogLevel(loggerCategory)) {
617                                                                 this->putLogError(loggerCategory,33, "Parse Timing Month Error.", __FILE__, __LINE__);
618                                                         }
619                                                         throw std::logic_error("Parse Timing Month Error.");
620                                                 }
621                                                 if (0 > minute || minute > 59) {
622                                                         if (LOG_LV_ERROR >= this->getLogLevel(loggerCategory)) {
623                                                                 this->putLogError(loggerCategory,34, "Parse Timing Month Error.", __FILE__, __LINE__);
624                                                         }
625                                                         throw std::logic_error("Parse Timing Month Error.");
626                                                 }
627                                         }
628                                         else {
629                                                 if (LOG_LV_ERROR >= this->getLogLevel(loggerCategory)) {
630                                                         this->putLogError(loggerCategory,35, "Parse Timing Month Error.", __FILE__, __LINE__);
631                                                 }
632                                                 throw std::logic_error("Parse Timing Month Error.");
633                                         }
634                                 }
635                                 else {
636                                         if (LOG_LV_ERROR >= this->getLogLevel(loggerCategory)) {
637                                                 this->putLogError(loggerCategory,36, "Parse Timing Month Error.", __FILE__, __LINE__);
638                                         }
639                                         throw std::logic_error("Parse Timing Month Error.");
640                                 }
641
642                                 // format to internal rotation timing value expresson
643                                 std::ostringstream oss;
644                                 oss << std::setfill('0') << std::setw(2) << date
645                                         << std::setfill('0') << std::setw(2) << hour
646                                         << std::setfill('0') << std::setw(2) << minute;
647                                 
648                                 rotationTimingValue = oss.str();
649
650                         }
651                         else {
652                                 if (LOG_LV_ERROR >= this->getLogLevel(loggerCategory)) {
653                                         this->putLogError(loggerCategory,37, "Not Exist Log RotaionTiming Month Setting.", __FILE__, __LINE__);
654                                 }
655                                 throw std::logic_error("Not Exist Log RotaionTiming Month Setting.");
656                         }
657                 }
658
659                 if (LOG_TIM_WEEK == rotationTiming) {
660                         if (l7vs::Parameter::getInstance().isStringExist(PARAM_COMP_LOGGER, rotation_timing_value_key)) {
661                                 ret = l7vs::Parameter::getInstance().getStringValue(PARAM_COMP_LOGGER, rotation_timing_value_key);
662
663                                 std::string::size_type fpos = 0;
664                                 std::string::size_type rpos = 0;
665                                 int week = 0;
666                                 int hour = 0;
667                                 int minute = 0;
668                                 rpos = ret.find_first_of(' ', fpos);
669                                 //find week
670                                 if (std::string::npos != rpos) {
671                                         std::string weekStr = ret.substr(fpos, rpos - fpos);
672
673                                         if ("sun" == weekStr) week = 0;
674                                         else if ("mon" == weekStr) week = 1;
675                                         else if ("tue" == weekStr) week = 2;
676                                         else if ("wed" == weekStr) week = 3;
677                                         else if ("thu" == weekStr) week = 4;
678                                         else if ("fri" == weekStr) week = 5;
679                                         else if ("sat" == weekStr) week = 6;
680                                         else {
681                                                 if (LOG_LV_ERROR >= this->getLogLevel(loggerCategory)) {
682                                                         this->putLogError(loggerCategory,38, "Parse Timing Week Error.", __FILE__, __LINE__);
683                                                 }
684                                                 throw std::logic_error("Parse Timing Week Error.");
685                                         }
686                                         fpos = rpos + 1;
687                                         // find hour
688                                         rpos = ret.find_first_of(':', fpos);
689                                         if (std::string::npos != rpos) {
690                                                 std::string hourStr = ret.substr(fpos, rpos - fpos);
691                                                 try {
692                                                         hour = lexical_cast<int>(hourStr);
693                                                 }
694                                                 catch (const l7vs::bad_lexical_cast& bc) {
695                                                         if (LOG_LV_ERROR >= this->getLogLevel(loggerCategory)) {
696                                                                 this->putLogError(loggerCategory,39, "Parse Timing Week Error.", __FILE__, __LINE__);
697                                                         }
698                                                         throw std::logic_error("Parse Timing Week Error.");
699                                                 }
700                                                 if (0 > hour || hour > 23) {
701                                                         if (LOG_LV_ERROR >= this->getLogLevel(loggerCategory)) {
702                                                                 this->putLogError(loggerCategory,40, "Parse Timing Week Error.", __FILE__, __LINE__);
703                                                         }
704                                                         throw std::logic_error("Parse Timing Week Error.");
705                                                 }
706                                                 // minute
707                                                 std::string minuteStr = ret.substr(rpos + 1);
708                                                 try {
709                                                         minute = lexical_cast<int>(minuteStr);
710                                                 }
711                                                 catch (const l7vs::bad_lexical_cast& bc) {
712                                                         if (LOG_LV_ERROR >= this->getLogLevel(loggerCategory)) {
713                                                                 this->putLogError(loggerCategory,41, "Parse Timing Week Error.", __FILE__, __LINE__);
714                                                         }
715                                                         throw std::logic_error("Parse Timing Week Error.");
716                                                 }
717                                                 if (0 > minute || minute > 59) {
718                                                         if (LOG_LV_ERROR >= this->getLogLevel(loggerCategory)) {
719                                                                 this->putLogError(loggerCategory,42, "Parse Timing Week Error.", __FILE__, __LINE__);
720                                                         }
721                                                         throw std::logic_error("Parse Timing Week Error.");
722                                                 }
723                                         }
724                                         else {
725                                                 if (LOG_LV_ERROR >= this->getLogLevel(loggerCategory)) {        
726                                                         this->putLogError(loggerCategory,43, "Parse Timing Week Error.", __FILE__, __LINE__);
727                                                 }
728                                                 throw std::logic_error("Parse Timing Week Error.");
729                                         }
730                                 }
731                                 else {
732                                         if (LOG_LV_ERROR >= this->getLogLevel(loggerCategory)) {
733                                                 this->putLogError(loggerCategory,44, "Parse Timing Week Error.", __FILE__, __LINE__);
734                                         }
735                                         throw std::logic_error("Parse Timing Week Error.");
736                                 }
737
738                                 // format to internal rotation timing value expresson
739                                 std::ostringstream oss;
740                                 oss << std::setfill('0') << std::setw(1) << week
741                                         << std::setfill('0') << std::setw(2) << hour
742                                         << std::setfill('0') << std::setw(2) << minute;
743                                 
744                                 rotationTimingValue = oss.str();
745
746                         }
747                         else {
748                                 if (LOG_LV_ERROR >= this->getLogLevel(loggerCategory)) {
749                                         this->putLogError(loggerCategory,45, "Not Exist Log RotaionTiming Week Setting.", __FILE__, __LINE__);
750                                 }
751                                 throw std::logic_error("Not Exist Log RotaionTiming Week Setting.");
752                         }
753                 }
754
755                 if (LOG_TIM_DATE == rotationTiming) {
756                         if (l7vs::Parameter::getInstance().isStringExist(PARAM_COMP_LOGGER, rotation_timing_value_key)) {
757                                 ret = l7vs::Parameter::getInstance().getStringValue(PARAM_COMP_LOGGER, rotation_timing_value_key);
758
759                                 std::string::size_type fpos = 0;
760                                 std::string::size_type rpos = 0;
761                                 int hour = 0;
762                                 int minute = 0;
763                                 //find time
764                                 rpos = ret.find_first_of(':', fpos);
765                                 if (std::string::npos != rpos) {
766                                         std::string hourStr = ret.substr(fpos, rpos - fpos);
767                                         try {
768                                                 hour = lexical_cast<int>(hourStr);
769                                         }
770                                         catch (const l7vs::bad_lexical_cast& bc) {
771                                                 if (LOG_LV_ERROR >= this->getLogLevel(loggerCategory)) {
772                                                         this->putLogError(loggerCategory,46, "Parse Timing Date Error.", __FILE__, __LINE__);
773                                                 }
774                                                 throw std::logic_error("Parse Timing Date Error.");
775                                         }
776                                         if (0 > hour || hour > 23) {
777                                                 if (LOG_LV_ERROR >= this->getLogLevel(loggerCategory)) {
778                                                         this->putLogError(loggerCategory,47, "Parse Timing Date Error.", __FILE__, __LINE__);
779                                                 }
780                                                 throw std::logic_error("Parse Timing Date Error.");
781                                         }
782                                         // minute
783                                         std::string minuteStr = ret.substr(rpos + 1);
784                                         try {
785                                                 minute = lexical_cast<int>(minuteStr);
786                                         }
787                                         catch (const l7vs::bad_lexical_cast& bc) {
788                                                 if (LOG_LV_ERROR >= this->getLogLevel(loggerCategory)) {
789                                                         this->putLogError(loggerCategory,48, "Parse Timing Date Error.", __FILE__, __LINE__);
790                                                 }
791                                                 throw std::logic_error("Parse Timing Date Error.");
792                                         }
793                                         if (0 > minute || minute > 59) {
794                                                 if (LOG_LV_ERROR >= this->getLogLevel(loggerCategory)) {
795                                                         this->putLogError(loggerCategory,49, "Parse Timing Date Error.", __FILE__, __LINE__);
796                                                 }
797                                                 throw std::logic_error("Parse Timing Date Error.");
798                                         }
799                                 }
800                                 else {
801                                         if (LOG_LV_ERROR >= this->getLogLevel(loggerCategory)) {
802                                                 this->putLogError(loggerCategory,50, "Parse Timing Date Error.", __FILE__, __LINE__);
803                                         }
804                                         throw std::logic_error("Parse Timing Date Error.");
805                                 }
806
807                                 // format to internal rotation timing value expresson
808                                 std::ostringstream oss;
809                                 oss << std::setfill('0') << std::setw(2) << hour
810                                         << std::setfill('0') << std::setw(2) << minute;
811                                 
812                                 rotationTimingValue = oss.str();
813
814                         }
815                         else {
816                                 if (LOG_LV_ERROR >= this->getLogLevel(loggerCategory)) {
817                                         this->putLogError(loggerCategory,51, "Not Exist Log RotaionTiming Date Setting.", __FILE__, __LINE__);
818                                 }
819                                 throw std::logic_error("Not Exist Log RotaionTiming Date Setting.");
820                         }
821                 }
822
823                 if (LOG_TIM_HOUR == rotationTiming) {
824                         if (l7vs::Parameter::getInstance().isStringExist(PARAM_COMP_LOGGER, rotation_timing_value_key)) {
825                                 ret = l7vs::Parameter::getInstance().getStringValue(PARAM_COMP_LOGGER, rotation_timing_value_key);
826
827                                 // minute
828                                 int minute = 0;
829                                 try {
830                                         minute = lexical_cast<int>(ret);
831                                 }
832                                 catch (const l7vs::bad_lexical_cast& bc) {
833                                         if (LOG_LV_ERROR >= this->getLogLevel(loggerCategory)) {
834                                                 this->putLogError(loggerCategory,52, "Parse Timing Hour Error.", __FILE__, __LINE__);
835                                         }
836                                         throw std::logic_error("Parse Timing Hour Error.");
837                                 }
838                                 if (0 > minute || minute > 59) {
839                                         if (LOG_LV_ERROR >= this->getLogLevel(loggerCategory)) {
840                                                 this->putLogError(loggerCategory,53, "Parse Timing Hour Error.", __FILE__, __LINE__);
841                                         }
842                                         throw std::logic_error("Parse Timing Hour Error.");
843                                 }
844
845                                 // format to internal rotation timing value expresson
846                                 std::ostringstream oss;
847                                 oss << std::setfill('0') << std::setw(2) << minute;
848                                 
849                                 rotationTimingValue = oss.str();
850
851                         }
852                         else {
853                                 if (LOG_LV_ERROR >= this->getLogLevel(loggerCategory)) {
854                                         this->putLogError(loggerCategory,54, "Not Exist Log RotaionTiming Hour Setting.", __FILE__, __LINE__);
855                                 }
856                                 throw std::logic_error("Not Exist Log RotaionTiming Hour Setting.");
857                         }
858                 }
859         }
860
861         try {
862                 /*-------- DEBUG LOG for sslproxy --------*/
863                 if (LOG_LV_DEBUG >= this->getLogLevel(loggerCategory) &&
864                     catnum != LOG_CAT_SSLPROXY_LOGGER) {
865                         std::ostringstream oss;
866                         oss << "function : void l7vs::LoggerImpl::loadCategoryLoggerConf("
867                             << "LOG_CATEGORY_TAG catnum) : "
868                             << "Set category Logger appender. "
869                             << "catnum = " << catnum;
870                         this->putLogDebug(loggerCategory, 4, oss.str(), __FILE__, __LINE__);
871                 }
872                 /*------ DEBUG LOG END for sslproxy ------*/
873
874                 // reset current configuration
875                 // when category is LOG_CAT_NONE (first category)
876                 log4cxx::helpers::Pool pool;
877                 if (catnum == LOG_CAT_NONE) {
878                         /*-------- DEBUG LOG for sslproxy --------*/
879                         if (LOG_LV_DEBUG >= this->getLogLevel(loggerCategory) &&
880                             catnum != LOG_CAT_SSLPROXY_LOGGER) {
881                                 std::ostringstream oss;
882                                 oss << "function : l7vs::LoggerImpl::loadCategoryLoggerConf() : "
883                                     << "Reset all Logger configuration. "
884                                     << "catnum = " << catnum;
885                                 this->putLogDebug(loggerCategory, 5, oss.str(), __FILE__, __LINE__);
886                         }
887                         /*------ DEBUG LOG END for sslproxy ------*/
888                         log4cxx::LogManager::resetConfiguration();
889                 }
890                 log4cxx::LoggerPtr catlogger = log4cxx::Logger::getLogger(categoryTable[catnum]);
891                 if (0 == catlogger) {
892                         throw std::logic_error("getLogger Failed.");
893                 }
894                 log4cxx::LayoutPtr layout =
895                         new log4cxx::PatternLayout(LOGGER_LAYOUT);
896
897                 switch (rotation) {
898                 case LOG_ROT_SIZE:
899                         {
900                                 // create FixedWindowRollingPolicy
901                                 log4cxx::rolling::FixedWindowRollingPolicyPtr fixedRollingPolicy =
902                                         new log4cxx::rolling::FixedWindowRollingPolicy();
903         
904                                 // setting minIndex
905                                 fixedRollingPolicy->setMinIndex(1);
906         
907                                 // setting maxIndex
908                                 fixedRollingPolicy->setMaxIndex(maxBackupIndex);
909
910                                 // setting FileNamePattern
911                                 std::ostringstream sizeFile;
912                                 sizeFile << logFilename << "." << LOGGER_FILE_PATTERN;
913                                 fixedRollingPolicy->setFileNamePattern(sizeFile.str());
914         
915                                 // create SizeBasedTriggeringPolicy
916                                 log4cxx::rolling::SizeBasedTriggeringPolicyPtr sizeTriggeringPolicy =
917                                         new log4cxx::rolling::SizeBasedTriggeringPolicy();
918
919                                 // setting maxFileSize
920                                 sizeTriggeringPolicy->setMaxFileSize(maxFileSize);
921         
922                                 // create RollingFileAppender
923                                 log4cxx::rolling::RollingFileAppenderPtr sizeAppender =
924                                         new log4cxx::rolling::RollingFileAppender();
925         
926                                 // set layout
927                                 sizeAppender->setLayout(layout);
928         
929                                 // set RollingPolicy
930                                 sizeAppender->setRollingPolicy(fixedRollingPolicy);
931         
932                                 // set TriggeringPolicy
933                                 sizeAppender->setTriggeringPolicy(sizeTriggeringPolicy);
934
935                                 // set Log Filename
936                                 sizeAppender->setFile(logFilename, true, false, LOGGER_DEFAULT_BUFFER_SIZE, pool);
937         
938                                 // activate appender options
939                                 sizeAppender->activateOptions(pool);
940         
941                                 // add size_base_appender to CategoryLogger
942                                 catlogger->addAppender(sizeAppender);
943
944                                 break;
945                         }
946                 case LOG_ROT_DATE:
947                         {
948                                 // create StrictTimeBasedRollingPolicy
949                                 log4cxx::rolling::StrictTimeBasedRollingPolicyPtr strictRollingPolicy =
950                                         new log4cxx::rolling::StrictTimeBasedRollingPolicy();
951         
952                                 // setting minIndex
953                                 strictRollingPolicy->setMinIndex(1);
954         
955                                 // setting maxIndex
956                                 strictRollingPolicy->setMaxIndex(maxBackupIndex);
957
958                                 // setting FileNamePattern
959                                 std::ostringstream dateFile;
960                                 dateFile << logFilename << "." << LOGGER_FILE_PATTERN;
961                                 strictRollingPolicy->setFileNamePattern(dateFile.str());
962
963                                 // setting Rotation Timing
964                                 strictRollingPolicy->setRotationTiming(rotationTiming);
965         
966                                 // setting Rotation Timing Value
967                                 strictRollingPolicy->setRotationTimingValue(rotationTimingValue);
968         
969                                 //create RollingFileAppender
970                                 log4cxx::rolling::RollingFileAppenderPtr dateAppender =
971                                         new log4cxx::rolling::RollingFileAppender();
972                         
973                                 // set layout
974                                 dateAppender->setLayout(layout);
975
976                                 // set RollingPolicy (TriggeringPolicy also included RollingPolicy)
977                                 dateAppender->setRollingPolicy(strictRollingPolicy);
978         
979                                 // set Log Filename
980                                 dateAppender->setFile(logFilename, true, false, LOGGER_DEFAULT_BUFFER_SIZE, pool);
981         
982                                 // activate appender options
983                                 dateAppender->activateOptions(pool);
984         
985                                 // add date_based_appender to CategoryLogger
986                                 catlogger->addAppender(dateAppender);
987
988                                 break;
989                         }
990                 default:        //LOG_ROT_DATESIZE:
991                         {
992                                 // create TimeAndSizeBasedRollingPolicy
993                                 log4cxx::rolling::TimeAndSizeBasedRollingPolicyPtr timeSizeRollingPolicy =
994                                         new log4cxx::rolling::TimeAndSizeBasedRollingPolicy();
995         
996                                 // setting minIndex
997                                 timeSizeRollingPolicy->setMinIndex(1);
998         
999                                 // setting maxIndex
1000                                 timeSizeRollingPolicy->setMaxIndex(maxBackupIndex);
1001
1002                                 // setting FileNamePattern
1003                                 std::ostringstream dateSizeFile;
1004                                 dateSizeFile << logFilename << "." << LOGGER_FILE_PATTERN;
1005                                 timeSizeRollingPolicy->setFileNamePattern(dateSizeFile.str());
1006         
1007                                 // setting Rotation Timing
1008                                 timeSizeRollingPolicy->setRotationTiming(rotationTiming);
1009         
1010                                 // setting Rotation Timing Value
1011                                 timeSizeRollingPolicy->setRotationTimingValue(rotationTimingValue);
1012         
1013                                 // setting MaxFileSize
1014                                 timeSizeRollingPolicy->setMaxFileSize(maxFileSize);
1015         
1016                                 // create Rolling FileAppender
1017                                 log4cxx::rolling::RollingFileAppenderPtr dateSizeAppender =
1018                                         new log4cxx::rolling::RollingFileAppender();
1019         
1020                                 // set layout
1021                                 dateSizeAppender->setLayout(layout);
1022         
1023                                 // set RollingPolicy (TriggeringPolicy also included RollingPolicy)
1024                                 dateSizeAppender->setRollingPolicy(timeSizeRollingPolicy);
1025         
1026                                 // set Log Filename
1027                                 dateSizeAppender->setFile(logFilename, true, false, LOGGER_DEFAULT_BUFFER_SIZE, pool);
1028         
1029                                 // activate appender options
1030                                 dateSizeAppender->activateOptions(pool);
1031         
1032                                 // add time_and_size_based_appender to CategoryLogger
1033                                 catlogger->addAppender(dateSizeAppender);
1034                         }
1035                 }
1036
1037                 //set default log level
1038                 for (LOG_CATEGORY_TAG cat = LOG_CAT_NONE; cat < LOG_CAT_END; ++cat) {
1039                         log4cxx::Logger::getLogger(categoryTable[cat])->setLevel(categoryLevel[cat]);
1040                 }
1041
1042                 //get category level
1043                 for (LOG_CATEGORY_TAG cat = LOG_CAT_NONE; cat < LOG_CAT_END; ++cat) {
1044                         if (cat == LOG_CAT_NONE) continue;
1045                         if (l7vs::Parameter::getInstance().isStringExist(PARAM_COMP_LOGGER, categoryTable[cat])) {
1046                                 std::string levelStr = l7vs::Parameter::getInstance().getStringValue(PARAM_COMP_LOGGER, categoryTable[cat]);
1047                                 if ("debug" == levelStr) {
1048                                         categoryLevel[cat] = log4cxx::Level::getDebug();
1049                                         log4cxx::Logger::getLogger(categoryTable[cat])->setLevel(categoryLevel[cat]);
1050                                 }
1051                                 else if ("info" == levelStr) {
1052                                         categoryLevel[cat] = log4cxx::Level::getInfo();
1053                                         log4cxx::Logger::getLogger(categoryTable[cat])->setLevel(categoryLevel[cat]);
1054                                 }
1055                                 else if ("warn" == levelStr) {
1056                                         categoryLevel[cat] = log4cxx::Level::getWarn();
1057                                         log4cxx::Logger::getLogger(categoryTable[cat])->setLevel(categoryLevel[cat]);
1058                                 }
1059                                 else if ("error" == levelStr) {
1060                                         categoryLevel[cat] = log4cxx::Level::getError();
1061                                         log4cxx::Logger::getLogger(categoryTable[cat])->setLevel(categoryLevel[cat]);
1062                                 }
1063                                 else if ("fatal" == levelStr) {
1064                                         categoryLevel[cat] = log4cxx::Level::getFatal();
1065                                         log4cxx::Logger::getLogger(categoryTable[cat])->setLevel(categoryLevel[cat]);
1066                                 }
1067                                 else {
1068                                         std::ostringstream oss;
1069                                         oss << "Invalid Log Category Setting : " << categoryTable[cat];
1070                                         if (LOG_LV_WARN >= this->getLogLevel(loggerCategory)) {
1071                                                 this->putLogWarn(loggerCategory,2, oss.str(), __FILE__, __LINE__);
1072                                         }
1073                                         categoryLevel[cat] = log4cxx::Level::getInfo();
1074                                         log4cxx::Logger::getLogger(categoryTable[cat])->setLevel(categoryLevel[cat]);
1075                                 }
1076                         }
1077                         else {
1078                                 std::ostringstream oss;
1079                                 oss << "Not Exist Log Category Setting : " << categoryTable[cat];
1080                                 if (LOG_LV_WARN >= this->getLogLevel(loggerCategory)) {
1081                                         this->putLogWarn(loggerCategory,3, oss.str(), __FILE__, __LINE__);
1082                                 }
1083                                 categoryLevel[cat] = log4cxx::Level::getInfo();
1084                                 log4cxx::Logger::getLogger(categoryTable[cat])->setLevel(categoryLevel[cat]);
1085                         }
1086                 }
1087         }
1088         catch (const std::exception& e) {
1089                 std::ostringstream oss;
1090                 oss <<  "Logger Reload Config Failed : " << e.what();
1091                 errorConf(7, oss.str(), __FILE__, __LINE__);
1092                 throw std::logic_error(oss.str());
1093         }
1094
1095         initLogLevelTable();
1096 }
1097
1098 /*!
1099  * initialize LogLevel table.
1100  * initialize the LogLevel table.
1101  *
1102  * @param   void
1103  * @return  void
1104  */
1105 void l7vs::LoggerImpl::initLogLevelTable(void)
1106 {
1107         int nCounter = 0;
1108
1109         for (;nCounter < LOGGER_CATEGORY_NUM; nCounter++) {
1110                 loglevel[nCounter] = LOG_LV_NONE;
1111         }
1112
1113         return;
1114 }