OSDN Git Service

Logger用テストコード追加
[ultramonkey-l7/ultramonkey-l7-v3.git] / l7vsd / unit_tests / l7vs_logger / logger_implement_access_stub / logger_implement_access.cpp
1 /*!
2  * @file  logger_implement_access.cpp
3  * @brief logger module implementation class For access log.
4  *
5  * L7VSD: Linux Virtual Server for Layer7 Load Balancing
6  * Copyright (C) 2009  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
26 #include <iostream>
27 #include <sstream>
28 #include <iomanip>
29 #include <limits.h>
30 #include <log4cxx/logmanager.h>
31 #include <log4cxx/helpers/loglog.h>
32 #include <log4cxx/rolling/rollingfileappender.h>
33 #include <log4cxx/rolling/fixedwindowrollingpolicy.h>
34 #include <log4cxx/rolling/sizebasedtriggeringpolicy.h>
35 #include <log4cxx/rolling/timebasedrollingpolicy.h>
36 #include <log4cxx/consoleappender.h>
37 #include <errno.h>
38 #include <stdexcept>
39 #include <boost/lexical_cast.hpp>
40
41 #include "logger_implement_access.h"
42
43
44 bool l7vs::logger_implement_access::rtn_init_flag;
45
46 bool l7vs::logger_implement_access::rtn_checkRotateParameterComp_flag;
47
48 bool l7vs::logger_implement_access::rtn_setAcLoggerConf_flag;
49
50
51 l7vs::logger_implement_access::logger_implement_access(const std::string &access_log_file_name)
52             :rotate_default_flag( false ),
53             access_cnt(1)
54 {
55     access_log_file_name_ = access_log_file_name;
56     aclog_args.clear();
57     
58 }
59
60
61 bool l7vs::logger_implement_access::init(const bool rotate_default_flag,const appender_property& access_log_default_property,accesslog_rotate_map_type& rotatedata)
62 {
63     bool rtn = l7vs::logger_implement_access::rtn_init_flag;
64     
65     return (rtn);
66
67 }
68
69
70 bool l7vs::logger_implement_access::setAcLoggerConf(const appender_property& access_log_default_property,accesslog_rotate_map_type& rotatedata)
71 {
72     bool rtn = l7vs::logger_implement_access::rtn_setAcLoggerConf_flag;
73
74     return(rtn);
75
76 }
77
78
79 void l7vs::logger_implement_access::addRef()
80 {
81     access_cnt++;
82 }
83
84
85 void l7vs::logger_implement_access::releaseRef()
86 {
87     access_cnt--;
88 }
89
90
91 bool l7vs::logger_implement_access::operator<=(const int access_num )
92 {
93     return( access_cnt <= access_num );
94 }
95
96 std::string l7vs::logger_implement_access::getAcLogFileName()
97 {
98     return( access_log_file_name_ ); 
99 }
100
101
102 bool l7vs::logger_implement_access::checkRotateParameterComp(accesslog_rotate_map_type &rotatedata)
103 {
104     bool rtn = l7vs::logger_implement_access::rtn_checkRotateParameterComp_flag;
105     
106     return(rtn);
107 }
108
109 bool l7vs::logger_implement_access::is_rotate_default_flag()
110 {
111     bool rtn = rotate_default_flag;
112
113     return(rtn);
114 }
115
116 // \83\8d\83O\83t\83H\81[\83}\83b\83g 2008/12/07 20:08:31 [INFO] [[AccessLog] (CL)192.168.2.1 --> 192.168.2.2 --UM-- 192.168.1.101:37259 --> (RS-DST)192.168.1.106:80 ]
117 /*!
118  * output access info log.
119  *
120  * @param   virtualservice endpoint info
121  * @param   client endpoint info
122  * @param   realserver connect origin info
123  * @param   realserver connect destination info
124  * @param   add msg
125  * @retrun  void
126  */
127 void l7vs::logger_implement_access::putLog(
128                             const std::string& vsinfo,
129                             const std::string& cl_con_org,
130                             const std::string& rs_con_org,
131                             const std::string& rs_con_dest,
132                             const std::string& msg){
133
134     std::stringstream    buf;
135     buf << boost::format( "[ [AccessLog] (CL)%s --> %s --UM-- %s --> (RS-DST)%s %s]" )
136         % LOGGER_ACCESS_PROCESS_ID
137         % vsinfo
138         % cl_con_org
139         % rs_con_org
140         % rs_con_dest
141         % msg;
142
143     try {
144         log4cxx::Logger::getLogger( access_log_file_name_ )->forcedLog(    log4cxx::Level::getInfo(),
145                                                                     buf.str(),
146                                                                     log4cxx::spi::LocationInfo("", "", 0));
147     }
148     catch (const std::exception& ex) {
149         std::ostringstream oss;
150         oss << "Logging Error (Access Log) : " << ex.what();
151         std::cout << oss.str() << "\n";\r
152     }
153
154 }