1 /************************************************************************* 2 * 3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 4 * 5 * Copyright 2000, 2010 Oracle and/or its affiliates. 6 * 7 * OpenOffice.org - a multi-platform office productivity suite 8 * 9 * This file is part of OpenOffice.org. 10 * 11 * OpenOffice.org is free software: you can redistribute it and/or modify 12 * it under the terms of the GNU Lesser General Public License version 3 13 * only, as published by the Free Software Foundation. 14 * 15 * OpenOffice.org is distributed in the hope that it will be useful, 16 * but WITHOUT ANY WARRANTY; without even the implied warranty of 17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 18 * GNU Lesser General Public License version 3 for more details 19 * (a copy is included in the LICENSE file that accompanied this code). 20 * 21 * You should have received a copy of the GNU Lesser General Public License 22 * version 3 along with OpenOffice.org. If not, see 23 * <http://www.openoffice.org/license.html> 24 * for a copy of the LGPLv3 License. 25 * 26 ************************************************************************/ 27 28 #ifndef CONNECTIVITY_CONNECTIONLOG_HXX 29 #define CONNECTIVITY_CONNECTIONLOG_HXX 30 31 /** === begin UNO includes === **/ 32 #include <com/sun/star/logging/LogLevel.hpp> 33 /** === end UNO includes === **/ 34 35 #include <rtl/ustring.hxx> 36 37 // Strange enough, GCC requires the following forward declarations of the various 38 // convertLogArgToString flavors to be *before* the inclusion of comphelper/logging.hxx 39 40 namespace com { namespace sun { namespace star { namespace util 41 { 42 struct Date; 43 struct Time; 44 struct DateTime; 45 } } } } 46 47 //........................................................................ 48 namespace comphelper { namespace log { namespace convert 49 { 50 //........................................................................ 51 52 // helpers for logging more data types than are defined in comphelper/logging.hxx 53 ::rtl::OUString convertLogArgToString( const ::com::sun::star::util::Date& _rDate ); 54 ::rtl::OUString convertLogArgToString( const ::com::sun::star::util::Time& _rTime ); 55 ::rtl::OUString convertLogArgToString( const ::com::sun::star::util::DateTime& _rDateTime ); 56 57 //........................................................................ 58 } } } 59 //........................................................................ 60 61 #include <comphelper/logging.hxx> 62 63 namespace connectivity 64 { 65 namespace LogLevel = ::com::sun::star::logging::LogLevel; 66 } 67 68 //........................................................................ 69 namespace connectivity { namespace java { namespace sql { 70 //........................................................................ 71 72 //==================================================================== 73 //= ConnectionLog 74 //==================================================================== 75 typedef ::comphelper::ResourceBasedEventLogger ConnectionLog_Base; 76 class ConnectionLog : public ConnectionLog_Base 77 { 78 public: 79 enum ObjectType 80 { 81 CONNECTION = 0, 82 STATEMENT, 83 RESULTSET, 84 85 ObjectTypeCount = RESULTSET + 1 86 }; 87 88 private: 89 const sal_Int32 m_nObjectID; 90 91 public: 92 /// will construct an instance of ObjectType CONNECTION 93 ConnectionLog( const ::comphelper::ResourceBasedEventLogger& _rDriverLog ); 94 /// will create an instance with the same object ID / ObjectType as a given source instance 95 ConnectionLog( const ConnectionLog& _rSourceLog ); 96 /// will create an instance of arbitrary ObjectType 97 ConnectionLog( const ConnectionLog& _rSourceLog, ObjectType _eType ); 98 99 sal_Int32 getObjectID() const { return m_nObjectID; } 100 101 /// logs a given message, without any arguments, or source class/method names 102 bool log( const sal_Int32 _nLogLevel, const sal_Int32 _nMessageResID ) 103 { 104 return ConnectionLog_Base::log( _nLogLevel, _nMessageResID, m_nObjectID ); 105 } 106 107 template< typename ARGTYPE1 > 108 bool log( const sal_Int32 _nLogLevel, const sal_Int32 _nMessageResID, ARGTYPE1 _argument1 ) const 109 { 110 return ConnectionLog_Base::log( _nLogLevel, _nMessageResID, m_nObjectID, _argument1 ); 111 } 112 113 template< typename ARGTYPE1, typename ARGTYPE2 > 114 bool log( const sal_Int32 _nLogLevel, const sal_Int32 _nMessageResID, ARGTYPE1 _argument1, ARGTYPE2 _argument2 ) const 115 { 116 return ConnectionLog_Base::log( _nLogLevel, _nMessageResID, m_nObjectID, _argument1, _argument2 ); 117 } 118 119 template< typename ARGTYPE1, typename ARGTYPE2, typename ARGTYPE3 > 120 bool log( const sal_Int32 _nLogLevel, const sal_Int32 _nMessageResID, ARGTYPE1 _argument1, ARGTYPE2 _argument2, ARGTYPE3 _argument3 ) const 121 { 122 return ConnectionLog_Base::log( _nLogLevel, _nMessageResID, m_nObjectID, _argument1, _argument2, _argument3 ); 123 } 124 125 template< typename ARGTYPE1, typename ARGTYPE2, typename ARGTYPE3, typename ARGTYPE4 > 126 bool log( const sal_Int32 _nLogLevel, const sal_Int32 _nMessageResID, ARGTYPE1 _argument1, ARGTYPE2 _argument2, ARGTYPE3 _argument3, ARGTYPE4 _argument4 ) const 127 { 128 return ConnectionLog_Base::log( _nLogLevel, _nMessageResID, m_nObjectID, _argument1, _argument2, _argument3, _argument4 ); 129 } 130 131 template< typename ARGTYPE1, typename ARGTYPE2, typename ARGTYPE3, typename ARGTYPE4, typename ARGTYPE5 > 132 bool log( const sal_Int32 _nLogLevel, const sal_Int32 _nMessageResID, ARGTYPE1 _argument1, ARGTYPE2 _argument2, ARGTYPE3 _argument3, ARGTYPE4 _argument4, ARGTYPE5 _argument5 ) const 133 { 134 return ConnectionLog_Base::log( _nLogLevel, _nMessageResID, m_nObjectID, _argument1, _argument2, _argument3, _argument4, _argument5 ); 135 } 136 }; 137 138 //........................................................................ 139 } } } // namespace connectivity::java::sql 140 //........................................................................ 141 142 #endif // CONNECTIVITY_CONNECTIONLOG_HXX 143