1 /**************************************************************
2  *
3  * Licensed to the Apache Software Foundation (ASF) under one
4  * or more contributor license agreements.  See the NOTICE file
5  * distributed with this work for additional information
6  * regarding copyright ownership.  The ASF licenses this file
7  * to you under the Apache License, Version 2.0 (the
8  * "License"); you may not use this file except in compliance
9  * with the License.  You may obtain a copy of the License at
10  *
11  *   http://www.apache.org/licenses/LICENSE-2.0
12  *
13  * Unless required by applicable law or agreed to in writing,
14  * software distributed under the License is distributed on an
15  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16  * KIND, either express or implied.  See the License for the
17  * specific language governing permissions and limitations
18  * under the License.
19  *
20  *************************************************************/
21 
22 
23 
24 #ifndef CONNECTIVITY_CONNECTIONLOG_HXX
25 #define CONNECTIVITY_CONNECTIONLOG_HXX
26 
27 /** === begin UNO includes === **/
28 #include <com/sun/star/logging/LogLevel.hpp>
29 /** === end UNO includes === **/
30 
31 #include <rtl/ustring.hxx>
32 
33 // Strange enough, GCC requires the following forward declarations of the various
34 // convertLogArgToString flavors to be *before* the inclusion of comphelper/logging.hxx
35 
36 namespace com { namespace sun { namespace star { namespace util
37 {
38     struct Date;
39     struct Time;
40     struct DateTime;
41 } } } }
42 
43 //........................................................................
44 namespace comphelper { namespace log { namespace convert
45 {
46 //........................................................................
47 
48     // helpers for logging more data types than are defined in comphelper/logging.hxx
49     ::rtl::OUString convertLogArgToString( const ::com::sun::star::util::Date& _rDate );
50     ::rtl::OUString convertLogArgToString( const ::com::sun::star::util::Time& _rTime );
51     ::rtl::OUString convertLogArgToString( const ::com::sun::star::util::DateTime& _rDateTime );
52 
53 //........................................................................
54 } } }
55 //........................................................................
56 
57 #include <comphelper/logging.hxx>
58 
59 namespace connectivity
60 {
61     namespace LogLevel = ::com::sun::star::logging::LogLevel;
62 }
63 
64 //........................................................................
65 namespace connectivity { namespace java { namespace sql {
66 //........................................................................
67 
68 	//====================================================================
69 	//= ConnectionLog
70 	//====================================================================
71     typedef ::comphelper::ResourceBasedEventLogger  ConnectionLog_Base;
72     class ConnectionLog : public ConnectionLog_Base
73 	{
74     public:
75         enum ObjectType
76         {
77             CONNECTION = 0,
78             STATEMENT,
79             RESULTSET,
80 
81             ObjectTypeCount = RESULTSET + 1
82         };
83 
84     private:
85         const   sal_Int32   m_nObjectID;
86 
87     public:
88         /// will construct an instance of ObjectType CONNECTION
89         ConnectionLog( const ::comphelper::ResourceBasedEventLogger& _rDriverLog );
90         /// will create an instance with the same object ID / ObjectType as a given source instance
91         ConnectionLog( const ConnectionLog& _rSourceLog );
92         /// will create an instance of arbitrary ObjectType
93         ConnectionLog( const ConnectionLog& _rSourceLog, ObjectType _eType );
94 
getObjectID() const95         sal_Int32   getObjectID() const { return m_nObjectID; }
96 
97         /// logs a given message, without any arguments, or source class/method names
log(const sal_Int32 _nLogLevel,const sal_Int32 _nMessageResID)98         bool        log( const sal_Int32 _nLogLevel, const sal_Int32 _nMessageResID )
99         {
100             return ConnectionLog_Base::log( _nLogLevel, _nMessageResID, m_nObjectID );
101         }
102 
103         template< typename ARGTYPE1 >
log(const sal_Int32 _nLogLevel,const sal_Int32 _nMessageResID,ARGTYPE1 _argument1) const104         bool        log( const sal_Int32 _nLogLevel, const sal_Int32 _nMessageResID, ARGTYPE1 _argument1 ) const
105         {
106             return ConnectionLog_Base::log( _nLogLevel, _nMessageResID, m_nObjectID, _argument1 );
107         }
108 
109         template< typename ARGTYPE1, typename ARGTYPE2 >
log(const sal_Int32 _nLogLevel,const sal_Int32 _nMessageResID,ARGTYPE1 _argument1,ARGTYPE2 _argument2) const110         bool        log( const sal_Int32 _nLogLevel, const sal_Int32 _nMessageResID, ARGTYPE1 _argument1, ARGTYPE2 _argument2 ) const
111         {
112             return ConnectionLog_Base::log( _nLogLevel, _nMessageResID, m_nObjectID, _argument1, _argument2 );
113         }
114 
115         template< typename ARGTYPE1, typename ARGTYPE2, typename ARGTYPE3 >
log(const sal_Int32 _nLogLevel,const sal_Int32 _nMessageResID,ARGTYPE1 _argument1,ARGTYPE2 _argument2,ARGTYPE3 _argument3) const116         bool        log( const sal_Int32 _nLogLevel, const sal_Int32 _nMessageResID, ARGTYPE1 _argument1, ARGTYPE2 _argument2, ARGTYPE3 _argument3 ) const
117         {
118             return ConnectionLog_Base::log( _nLogLevel, _nMessageResID, m_nObjectID, _argument1, _argument2, _argument3 );
119         }
120 
121         template< typename ARGTYPE1, typename ARGTYPE2, typename ARGTYPE3, typename ARGTYPE4 >
log(const sal_Int32 _nLogLevel,const sal_Int32 _nMessageResID,ARGTYPE1 _argument1,ARGTYPE2 _argument2,ARGTYPE3 _argument3,ARGTYPE4 _argument4) const122         bool        log( const sal_Int32 _nLogLevel, const sal_Int32 _nMessageResID, ARGTYPE1 _argument1, ARGTYPE2 _argument2, ARGTYPE3 _argument3, ARGTYPE4 _argument4 ) const
123         {
124             return ConnectionLog_Base::log( _nLogLevel, _nMessageResID, m_nObjectID, _argument1, _argument2, _argument3, _argument4 );
125         }
126 
127         template< typename ARGTYPE1, typename ARGTYPE2, typename ARGTYPE3, typename ARGTYPE4, typename ARGTYPE5 >
log(const sal_Int32 _nLogLevel,const sal_Int32 _nMessageResID,ARGTYPE1 _argument1,ARGTYPE2 _argument2,ARGTYPE3 _argument3,ARGTYPE4 _argument4,ARGTYPE5 _argument5) const128         bool        log( const sal_Int32 _nLogLevel, const sal_Int32 _nMessageResID, ARGTYPE1 _argument1, ARGTYPE2 _argument2, ARGTYPE3 _argument3, ARGTYPE4 _argument4, ARGTYPE5 _argument5 ) const
129         {
130             return ConnectionLog_Base::log( _nLogLevel, _nMessageResID, m_nObjectID, _argument1, _argument2, _argument3, _argument4, _argument5 );
131         }
132 	};
133 
134 //........................................................................
135 } } } // namespace connectivity::java::sql
136 //........................................................................
137 
138 #endif // CONNECTIVITY_CONNECTIONLOG_HXX
139