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 COMPHELPER_LOGGING_HXX 29 #define COMPHELPER_LOGGING_HXX 30 31 #include <comphelper/comphelperdllapi.h> 32 33 /** === begin UNO includes === **/ 34 #include <com/sun/star/uno/XComponentContext.hpp> 35 #include <com/sun/star/logging/XLogHandler.hpp> 36 #include <com/sun/star/logging/LogLevel.hpp> 37 /** === end UNO includes === **/ 38 39 #include <boost/shared_ptr.hpp> 40 #include <boost/optional.hpp> 41 42 //........................................................................ 43 namespace comphelper 44 { 45 //........................................................................ 46 47 //==================================================================== 48 //= string conversions, employed by the templatized log* members of 49 //= EventLogger 50 //==================================================================== 51 52 namespace log { namespace convert 53 { 54 inline const ::rtl::OUString& convertLogArgToString( const ::rtl::OUString& _rValue ) 55 { 56 return _rValue; 57 } 58 59 inline ::rtl::OUString convertLogArgToString( const sal_Char* _pAsciiValue ) 60 { 61 return ::rtl::OUString::createFromAscii( _pAsciiValue ); 62 } 63 64 inline ::rtl::OUString convertLogArgToString( double _nValue ) { return ::rtl::OUString::valueOf( _nValue ); } 65 inline ::rtl::OUString convertLogArgToString( float _nValue ) { return ::rtl::OUString::valueOf( _nValue ); } 66 inline ::rtl::OUString convertLogArgToString( sal_Int64 _nValue ) { return ::rtl::OUString::valueOf( _nValue ); } 67 inline ::rtl::OUString convertLogArgToString( sal_Int32 _nValue ) { return ::rtl::OUString::valueOf( _nValue ); } 68 inline ::rtl::OUString convertLogArgToString( sal_Int16 _nValue ) { return ::rtl::OUString::valueOf( (sal_Int32)_nValue ); } 69 inline ::rtl::OUString convertLogArgToString( sal_Unicode _nValue ) { return ::rtl::OUString::valueOf( _nValue ); } 70 inline ::rtl::OUString convertLogArgToString( sal_Bool _nValue ) { return ::rtl::OUString::valueOf( _nValue ); } 71 72 } } // namespace log::convert 73 74 //==================================================================== 75 //= EventLogger 76 //==================================================================== 77 class EventLogger_Impl; 78 typedef ::boost::optional< ::rtl::OUString > OptionalString; 79 80 /** encapsulates an <type scope="com::sun::star::logging">XLogger</type> 81 82 The class silences several (unlikely) errors which could potentially happen 83 when working with a logger. Additionally, it provides some convenience methods 84 for logging events. 85 86 You can use this class as follows 87 <pre> 88 EventLogger aLogger( xContext, sLoggerName ); 89 .... 90 aLogger.log( LogLevel::SEVERE, sSomeMessage ); 91 aLogger.logp( LogLevel::CONFIG, "MyClass", "MyMethod", sSomeMessage, SomeParameter1, SomeParameter2, SomeParameter3 ); 92 </pre> 93 94 The <code>log</code> and <code>logp</code> calls support up to 6 parameters, which can be of 95 arbitrary type. For every parameter, there must exist a function <code>convertLogArgToString</code> 96 which takes an argument of the respective type, and returns a string. 97 98 After a parameter has been converted to a string using the above mentioned 99 <code>convertLogArgToString</code> function, a placeholder $1$ (resp. $2$ resp. $4$ ...) 100 in the message will be replaced with this string, and the resulting message will be logged. 101 */ 102 class COMPHELPER_DLLPUBLIC EventLogger 103 { 104 protected: 105 ::boost::shared_ptr< EventLogger_Impl > m_pImpl; 106 107 public: 108 /** creates an <code>EventLogger</code> instance working with a css.logging.XLogger 109 instance given by name. 110 111 @param _rxContext 112 the component context to create services 113 @param _rLoggerName 114 the name of the logger to create. If empty, the office-wide default logger will be used. 115 */ 116 EventLogger( 117 const ::com::sun::star::uno::Reference< ::com::sun::star::uno::XComponentContext >& _rxContext, 118 const ::rtl::OUString& _rLoggerName = ::rtl::OUString() 119 ); 120 121 /** creates an <code>EventLogger</code> instance working with a css.logging.XLogger 122 instance given by ASCII name. 123 124 @param _rxContext 125 the component context to create services 126 127 @param _rLoggerName 128 the ASCII name of the logger to create. 129 */ 130 EventLogger( 131 const ::com::sun::star::uno::Reference< ::com::sun::star::uno::XComponentContext >& _rxContext, 132 const sal_Char* _pAsciiLoggerName 133 ); 134 135 ~EventLogger(); 136 137 public: 138 /** returns the name of the logger 139 */ 140 const ::rtl::OUString& getName() const; 141 142 /// returns the current log level threshold of the logger 143 sal_Int32 getLogLevel() const; 144 145 /// sets a new log level threshold of the logger 146 void setLogLevel( const sal_Int32 _nLogLevel ) const; 147 148 /// determines whether an event with the given level would be logged 149 bool isLoggable( const sal_Int32 _nLogLevel ) const; 150 151 /** adds the given log handler to the logger's set of handlers. 152 153 Note that normally, you would not use this method: The logger implementations 154 initialize themselves from the configuration, where usually, a default log handler 155 is specified. In this case, the logger will create and use this handler. 156 157 @return 158 <TRUE/> if and only if the addition was successful (as far as this can be detected 159 from outside the <code>XLogger</code>'s implementation. 160 */ 161 bool addLogHandler( const ::com::sun::star::uno::Reference< ::com::sun::star::logging::XLogHandler >& _rxLogHandler ); 162 163 /** removes the given log handler from the logger's set of handlers. 164 165 @return 166 <TRUE/> if and only if the addition was successful (as far as this can be detected 167 from outside the <code>XLogger</code>'s implementation. 168 */ 169 bool removeLogHandler( const ::com::sun::star::uno::Reference< ::com::sun::star::logging::XLogHandler >& _rxLogHandler ); 170 171 //---------------------------------------------------------------- 172 //- XLogger::log equivalents/wrappers 173 //- string messages 174 175 /// logs a given message, without any arguments, or source class/method names 176 bool log( const sal_Int32 _nLogLevel, const ::rtl::OUString& _rMessage ) const 177 { 178 if ( isLoggable( _nLogLevel ) ) 179 return impl_log( _nLogLevel, NULL, NULL, _rMessage ); 180 return false; 181 } 182 183 /** logs a given message, replacing a placeholder in the message with an argument 184 185 The function takes, additionally to the log level and the message, an arbitrary 186 argument. This argument is converted to a string using an overloaded function 187 named <code>convertLogArgToString</code>. Then, a placeholder "$1$" 188 is searched in the message string, and replaced with the argument string. 189 */ 190 template< typename ARGTYPE1 > 191 bool log( const sal_Int32 _nLogLevel, const ::rtl::OUString& _rMessage, ARGTYPE1 _argument1 ) const 192 { 193 if ( isLoggable( _nLogLevel ) ) 194 return impl_log( _nLogLevel, NULL, NULL, _rMessage, 195 OptionalString( log::convert::convertLogArgToString( _argument1 ) ) ); 196 return false; 197 } 198 199 /// logs a given message, replacing 2 placeholders in the message with respective values 200 template< typename ARGTYPE1, typename ARGTYPE2 > 201 bool log( const sal_Int32 _nLogLevel, const ::rtl::OUString& _rMessage, ARGTYPE1 _argument1, ARGTYPE2 _argument2 ) const 202 { 203 if ( isLoggable( _nLogLevel ) ) 204 return impl_log( _nLogLevel, NULL, NULL, _rMessage, 205 OptionalString( log::convert::convertLogArgToString( _argument1 ) ), 206 OptionalString( log::convert::convertLogArgToString( _argument2 ) ) ); 207 return false; 208 } 209 210 /// logs a given message, replacing 3 placeholders in the message with respective values 211 template< typename ARGTYPE1, typename ARGTYPE2, typename ARGTYPE3 > 212 bool log( const sal_Int32 _nLogLevel, const ::rtl::OUString& _rMessage, ARGTYPE1 _argument1, ARGTYPE2 _argument2, ARGTYPE3 _argument3 ) const 213 { 214 if ( isLoggable( _nLogLevel ) ) 215 return impl_log( _nLogLevel, NULL, NULL, _rMessage, 216 OptionalString( log::convert::convertLogArgToString( _argument1 ) ), 217 OptionalString( log::convert::convertLogArgToString( _argument2 ) ), 218 OptionalString( log::convert::convertLogArgToString( _argument3 ) ) ); 219 return false; 220 } 221 222 /// logs a given message, replacing 4 placeholders in the message with respective values 223 template< typename ARGTYPE1, typename ARGTYPE2, typename ARGTYPE3, typename ARGTYPE4 > 224 bool log( const sal_Int32 _nLogLevel, const ::rtl::OUString& _rMessage, ARGTYPE1 _argument1, ARGTYPE2 _argument2, ARGTYPE3 _argument3, ARGTYPE4 _argument4 ) const 225 { 226 if ( isLoggable( _nLogLevel ) ) 227 return impl_log( _nLogLevel, NULL, NULL, _rMessage, 228 OptionalString( log::convert::convertLogArgToString( _argument1 ) ), 229 OptionalString( log::convert::convertLogArgToString( _argument2 ) ), 230 OptionalString( log::convert::convertLogArgToString( _argument3 ) ), 231 OptionalString( log::convert::convertLogArgToString( _argument4 ) ) ); 232 return false; 233 } 234 235 /// logs a given message, replacing 5 placeholders in the message with respective values 236 template< typename ARGTYPE1, typename ARGTYPE2, typename ARGTYPE3, typename ARGTYPE4, typename ARGTYPE5 > 237 bool log( const sal_Int32 _nLogLevel, const ::rtl::OUString& _rMessage, ARGTYPE1 _argument1, ARGTYPE2 _argument2, ARGTYPE3 _argument3, ARGTYPE4 _argument4, ARGTYPE5 _argument5 ) const 238 { 239 if ( isLoggable( _nLogLevel ) ) 240 return impl_log( _nLogLevel, NULL, NULL, _rMessage, 241 OptionalString( log::convert::convertLogArgToString( _argument1 ) ), 242 OptionalString( log::convert::convertLogArgToString( _argument2 ) ), 243 OptionalString( log::convert::convertLogArgToString( _argument3 ) ), 244 OptionalString( log::convert::convertLogArgToString( _argument4 ) ), 245 OptionalString( log::convert::convertLogArgToString( _argument5 ) ) ); 246 return false; 247 } 248 249 /// logs a given message, replacing 6 placeholders in the message with respective values 250 template< typename ARGTYPE1, typename ARGTYPE2, typename ARGTYPE3, typename ARGTYPE4, typename ARGTYPE5, typename ARGTYPE6 > 251 bool log( const sal_Int32 _nLogLevel, const ::rtl::OUString& _rMessage, ARGTYPE1 _argument1, ARGTYPE2 _argument2, ARGTYPE3 _argument3, ARGTYPE4 _argument4, ARGTYPE5 _argument5, ARGTYPE6 _argument6 ) const 252 { 253 if ( isLoggable( _nLogLevel ) ) 254 return impl_log( _nLogLevel, NULL, NULL, _rMessage, 255 OptionalString( log::convert::convertLogArgToString( _argument1 ) ), 256 OptionalString( log::convert::convertLogArgToString( _argument2 ) ), 257 OptionalString( log::convert::convertLogArgToString( _argument3 ) ), 258 OptionalString( log::convert::convertLogArgToString( _argument4 ) ), 259 OptionalString( log::convert::convertLogArgToString( _argument5 ) ), 260 OptionalString( log::convert::convertLogArgToString( _argument6 ) ) ); 261 return false; 262 } 263 264 //---------------------------------------------------------------- 265 //- XLogger::log equivalents/wrappers 266 //- ASCII messages 267 268 /// logs a given message, without any arguments, or source class/method names 269 bool log( const sal_Int32 _nLogLevel, const sal_Char* _pMessage ) const 270 { 271 if ( isLoggable( _nLogLevel ) ) 272 return impl_log( _nLogLevel, NULL, NULL, ::rtl::OUString::createFromAscii( _pMessage ) ); 273 return false; 274 } 275 276 /** logs a given message, replacing a placeholder in the message with an argument 277 278 The function takes, additionally to the log level and the message, an arbitrary 279 argument. This argument is converted to a string using an overloaded function 280 named <code>convertLogArgToString</code>. Then, a placeholder "$1$" 281 is searched in the message string, and replaced with the argument string. 282 */ 283 template< typename ARGTYPE1 > 284 bool log( const sal_Int32 _nLogLevel, const sal_Char* _pMessage, ARGTYPE1 _argument1 ) const 285 { 286 if ( isLoggable( _nLogLevel ) ) 287 return impl_log( _nLogLevel, NULL, NULL, ::rtl::OUString::createFromAscii( _pMessage ), 288 OptionalString( log::convert::convertLogArgToString( _argument1 ) ) ); 289 return false; 290 } 291 292 /// logs a given message, replacing 2 placeholders in the message with respective values 293 template< typename ARGTYPE1, typename ARGTYPE2 > 294 bool log( const sal_Int32 _nLogLevel, const sal_Char* _pMessage, ARGTYPE1 _argument1, ARGTYPE2 _argument2 ) const 295 { 296 if ( isLoggable( _nLogLevel ) ) 297 return impl_log( _nLogLevel, NULL, NULL, ::rtl::OUString::createFromAscii( _pMessage ), 298 OptionalString( log::convert::convertLogArgToString( _argument1 ) ), 299 OptionalString( log::convert::convertLogArgToString( _argument2 ) ) ); 300 return false; 301 } 302 303 /// logs a given message, replacing 3 placeholders in the message with respective values 304 template< typename ARGTYPE1, typename ARGTYPE2, typename ARGTYPE3 > 305 bool log( const sal_Int32 _nLogLevel, const sal_Char* _pMessage, ARGTYPE1 _argument1, ARGTYPE2 _argument2, ARGTYPE3 _argument3 ) const 306 { 307 if ( isLoggable( _nLogLevel ) ) 308 return impl_log( _nLogLevel, NULL, NULL, ::rtl::OUString::createFromAscii( _pMessage ), 309 OptionalString( log::convert::convertLogArgToString( _argument1 ) ), 310 OptionalString( log::convert::convertLogArgToString( _argument2 ) ), 311 OptionalString( log::convert::convertLogArgToString( _argument3 ) ) ); 312 return false; 313 } 314 315 /// logs a given message, replacing 4 placeholders in the message with respective values 316 template< typename ARGTYPE1, typename ARGTYPE2, typename ARGTYPE3, typename ARGTYPE4 > 317 bool log( const sal_Int32 _nLogLevel, const sal_Char* _pMessage, ARGTYPE1 _argument1, ARGTYPE2 _argument2, ARGTYPE3 _argument3, ARGTYPE4 _argument4 ) const 318 { 319 if ( isLoggable( _nLogLevel ) ) 320 return impl_log( _nLogLevel, NULL, NULL, ::rtl::OUString::createFromAscii( _pMessage ), 321 OptionalString( log::convert::convertLogArgToString( _argument1 ) ), 322 OptionalString( log::convert::convertLogArgToString( _argument2 ) ), 323 OptionalString( log::convert::convertLogArgToString( _argument3 ) ), 324 OptionalString( log::convert::convertLogArgToString( _argument4 ) ) ); 325 return false; 326 } 327 328 /// logs a given message, replacing 5 placeholders in the message with respective values 329 template< typename ARGTYPE1, typename ARGTYPE2, typename ARGTYPE3, typename ARGTYPE4, typename ARGTYPE5 > 330 bool log( const sal_Int32 _nLogLevel, const sal_Char* _pMessage, ARGTYPE1 _argument1, ARGTYPE2 _argument2, ARGTYPE3 _argument3, ARGTYPE4 _argument4, ARGTYPE5 _argument5 ) const 331 { 332 if ( isLoggable( _nLogLevel ) ) 333 return impl_log( _nLogLevel, NULL, NULL, ::rtl::OUString::createFromAscii( _pMessage ), 334 OptionalString( log::convert::convertLogArgToString( _argument1 ) ), 335 OptionalString( log::convert::convertLogArgToString( _argument2 ) ), 336 OptionalString( log::convert::convertLogArgToString( _argument3 ) ), 337 OptionalString( log::convert::convertLogArgToString( _argument4 ) ), 338 OptionalString( log::convert::convertLogArgToString( _argument5 ) ) ); 339 return false; 340 } 341 342 /// logs a given message, replacing 6 placeholders in the message with respective values 343 template< typename ARGTYPE1, typename ARGTYPE2, typename ARGTYPE3, typename ARGTYPE4, typename ARGTYPE5, typename ARGTYPE6 > 344 bool log( const sal_Int32 _nLogLevel, const sal_Char* _pMessage, ARGTYPE1 _argument1, ARGTYPE2 _argument2, ARGTYPE3 _argument3, ARGTYPE4 _argument4, ARGTYPE5 _argument5, ARGTYPE6 _argument6 ) const 345 { 346 if ( isLoggable( _nLogLevel ) ) 347 return impl_log( _nLogLevel, NULL, NULL, ::rtl::OUString::createFromAscii( _pMessage ), 348 OptionalString( log::convert::convertLogArgToString( _argument1 ) ), 349 OptionalString( log::convert::convertLogArgToString( _argument2 ) ), 350 OptionalString( log::convert::convertLogArgToString( _argument3 ) ), 351 OptionalString( log::convert::convertLogArgToString( _argument4 ) ), 352 OptionalString( log::convert::convertLogArgToString( _argument5 ) ), 353 OptionalString( log::convert::convertLogArgToString( _argument6 ) ) ); 354 return false; 355 } 356 357 //---------------------------------------------------------------- 358 //- XLogger::logp equivalents/wrappers 359 //- string messages 360 361 /// logs a given message, without any arguments, or source class/method names 362 bool logp( const sal_Int32 _nLogLevel, const sal_Char* _pSourceClass, const sal_Char* _pSourceMethod, const ::rtl::OUString& _rMessage ) const 363 { 364 if ( isLoggable( _nLogLevel ) ) 365 return impl_log( _nLogLevel, _pSourceClass, _pSourceMethod, _rMessage ); 366 return false; 367 } 368 369 /** logs a given message, replacing a placeholder in the message with an argument 370 371 The function takes, additionally to the logp level and the message, an arbitrary 372 argument. This argument is converted to a string using an overloaded function 373 named <code>convertLogArgToString</code>. Then, a placeholder "$1$" 374 is searched in the message string, and replaced with the argument string. 375 */ 376 template< typename ARGTYPE1 > 377 bool logp( const sal_Int32 _nLogLevel, const sal_Char* _pSourceClass, const sal_Char* _pSourceMethod, const ::rtl::OUString& _rMessage, ARGTYPE1 _argument1 ) const 378 { 379 if ( isLoggable( _nLogLevel ) ) 380 return impl_log( _nLogLevel, _pSourceClass, _pSourceMethod, _rMessage, 381 OptionalString( log::convert::convertLogArgToString( _argument1 ) ) ); 382 return false; 383 } 384 385 /// logs a given message, replacing 2 placeholders in the message with respective values 386 template< typename ARGTYPE1, typename ARGTYPE2 > 387 bool logp( const sal_Int32 _nLogLevel, const sal_Char* _pSourceClass, const sal_Char* _pSourceMethod, const ::rtl::OUString& _rMessage, ARGTYPE1 _argument1, ARGTYPE2 _argument2 ) const 388 { 389 if ( isLoggable( _nLogLevel ) ) 390 return impl_log( _nLogLevel, _pSourceClass, _pSourceMethod, _rMessage, 391 OptionalString( log::convert::convertLogArgToString( _argument1 ) ), 392 OptionalString( log::convert::convertLogArgToString( _argument2 ) ) ); 393 return false; 394 } 395 396 /// logs a given message, replacing 3 placeholders in the message with respective values 397 template< typename ARGTYPE1, typename ARGTYPE2, typename ARGTYPE3 > 398 bool logp( const sal_Int32 _nLogLevel, const sal_Char* _pSourceClass, const sal_Char* _pSourceMethod, const ::rtl::OUString& _rMessage, ARGTYPE1 _argument1, ARGTYPE2 _argument2, ARGTYPE3 _argument3 ) const 399 { 400 if ( isLoggable( _nLogLevel ) ) 401 return impl_log( _nLogLevel, _pSourceClass, _pSourceMethod, _rMessage, 402 OptionalString( log::convert::convertLogArgToString( _argument1 ) ), 403 OptionalString( log::convert::convertLogArgToString( _argument2 ) ), 404 OptionalString( log::convert::convertLogArgToString( _argument3 ) ) ); 405 return false; 406 } 407 408 /// logs a given message, replacing 4 placeholders in the message with respective values 409 template< typename ARGTYPE1, typename ARGTYPE2, typename ARGTYPE3, typename ARGTYPE4 > 410 bool logp( const sal_Int32 _nLogLevel, const sal_Char* _pSourceClass, const sal_Char* _pSourceMethod, const ::rtl::OUString& _rMessage, ARGTYPE1 _argument1, ARGTYPE2 _argument2, ARGTYPE3 _argument3, ARGTYPE4 _argument4 ) const 411 { 412 if ( isLoggable( _nLogLevel ) ) 413 return impl_log( _nLogLevel, _pSourceClass, _pSourceMethod, _rMessage, 414 OptionalString( log::convert::convertLogArgToString( _argument1 ) ), 415 OptionalString( log::convert::convertLogArgToString( _argument2 ) ), 416 OptionalString( log::convert::convertLogArgToString( _argument3 ) ), 417 OptionalString( log::convert::convertLogArgToString( _argument4 ) ) ); 418 return false; 419 } 420 421 /// logs a given message, replacing 5 placeholders in the message with respective values 422 template< typename ARGTYPE1, typename ARGTYPE2, typename ARGTYPE3, typename ARGTYPE4, typename ARGTYPE5 > 423 bool logp( const sal_Int32 _nLogLevel, const sal_Char* _pSourceClass, const sal_Char* _pSourceMethod, const ::rtl::OUString& _rMessage, ARGTYPE1 _argument1, ARGTYPE2 _argument2, ARGTYPE3 _argument3, ARGTYPE4 _argument4, ARGTYPE5 _argument5 ) const 424 { 425 if ( isLoggable( _nLogLevel ) ) 426 return impl_log( _nLogLevel, _pSourceClass, _pSourceMethod, _rMessage, 427 OptionalString( log::convert::convertLogArgToString( _argument1 ) ), 428 OptionalString( log::convert::convertLogArgToString( _argument2 ) ), 429 OptionalString( log::convert::convertLogArgToString( _argument3 ) ), 430 OptionalString( log::convert::convertLogArgToString( _argument4 ) ), 431 OptionalString( log::convert::convertLogArgToString( _argument5 ) ) ); 432 return false; 433 } 434 435 /// logs a given message, replacing 6 placeholders in the message with respective values 436 template< typename ARGTYPE1, typename ARGTYPE2, typename ARGTYPE3, typename ARGTYPE4, typename ARGTYPE5, typename ARGTYPE6 > 437 bool logp( const sal_Int32 _nLogLevel, const sal_Char* _pSourceClass, const sal_Char* _pSourceMethod, const ::rtl::OUString& _rMessage, ARGTYPE1 _argument1, ARGTYPE2 _argument2, ARGTYPE3 _argument3, ARGTYPE4 _argument4, ARGTYPE5 _argument5, ARGTYPE6 _argument6 ) const 438 { 439 if ( isLoggable( _nLogLevel ) ) 440 return impl_log( _nLogLevel, _pSourceClass, _pSourceMethod, _rMessage, 441 OptionalString( log::convert::convertLogArgToString( _argument1 ) ), 442 OptionalString( log::convert::convertLogArgToString( _argument2 ) ), 443 OptionalString( log::convert::convertLogArgToString( _argument3 ) ), 444 OptionalString( log::convert::convertLogArgToString( _argument4 ) ), 445 OptionalString( log::convert::convertLogArgToString( _argument5 ) ), 446 OptionalString( log::convert::convertLogArgToString( _argument6 ) ) ); 447 return false; 448 } 449 450 //---------------------------------------------------------------- 451 //- XLogger::logp equivalents/wrappers 452 //- ASCII messages 453 454 /// logs a given ASCII message, without any arguments, or source class/method names 455 bool logp( const sal_Int32 _nLogLevel, const sal_Char* _pSourceClass, const sal_Char* _pSourceMethod, const sal_Char* _pAsciiMessage ) const 456 { 457 if ( isLoggable( _nLogLevel ) ) 458 return impl_log( _nLogLevel, _pSourceClass, _pSourceMethod, ::rtl::OUString::createFromAscii( _pAsciiMessage ) ); 459 return false; 460 } 461 462 /** logs a given ASCII message, replacing a placeholder in the message with an argument 463 464 The function takes, additionally to the logp level and the message, an arbitrary 465 argument. This argument is converted to a string using an overloaded function 466 named <code>convertLogArgToString</code>. Then, a placeholder "$1$" 467 is searched in the message string, and replaced with the argument string. 468 */ 469 template< typename ARGTYPE1 > 470 bool logp( const sal_Int32 _nLogLevel, const sal_Char* _pSourceClass, const sal_Char* _pSourceMethod, const sal_Char* _pAsciiMessage, ARGTYPE1 _argument1 ) const 471 { 472 if ( isLoggable( _nLogLevel ) ) 473 return impl_log( _nLogLevel, _pSourceClass, _pSourceMethod, ::rtl::OUString::createFromAscii( _pAsciiMessage ), 474 OptionalString( log::convert::convertLogArgToString( _argument1 ) ) ); 475 return false; 476 } 477 478 /// logs a given ASCII message, replacing 2 placeholders in the message with respective values 479 template< typename ARGTYPE1, typename ARGTYPE2 > 480 bool logp( const sal_Int32 _nLogLevel, const sal_Char* _pSourceClass, const sal_Char* _pSourceMethod, const sal_Char* _pAsciiMessage, ARGTYPE1 _argument1, ARGTYPE2 _argument2 ) const 481 { 482 if ( isLoggable( _nLogLevel ) ) 483 return impl_log( _nLogLevel, _pSourceClass, _pSourceMethod, ::rtl::OUString::createFromAscii( _pAsciiMessage ), 484 OptionalString( log::convert::convertLogArgToString( _argument1 ) ), 485 OptionalString( log::convert::convertLogArgToString( _argument2 ) ) ); 486 return false; 487 } 488 489 /// logs a given ASCII message, replacing 3 placeholders in the message with respective values 490 template< typename ARGTYPE1, typename ARGTYPE2, typename ARGTYPE3 > 491 bool logp( const sal_Int32 _nLogLevel, const sal_Char* _pSourceClass, const sal_Char* _pSourceMethod, const sal_Char* _pAsciiMessage, ARGTYPE1 _argument1, ARGTYPE2 _argument2, ARGTYPE3 _argument3 ) const 492 { 493 if ( isLoggable( _nLogLevel ) ) 494 return impl_log( _nLogLevel, _pSourceClass, _pSourceMethod, ::rtl::OUString::createFromAscii( _pAsciiMessage ), 495 OptionalString( log::convert::convertLogArgToString( _argument1 ) ), 496 OptionalString( log::convert::convertLogArgToString( _argument2 ) ), 497 OptionalString( log::convert::convertLogArgToString( _argument3 ) ) ); 498 return false; 499 } 500 501 /// logs a given ASCII message, replacing 4 placeholders in the message with respective values 502 template< typename ARGTYPE1, typename ARGTYPE2, typename ARGTYPE3, typename ARGTYPE4 > 503 bool logp( const sal_Int32 _nLogLevel, const sal_Char* _pSourceClass, const sal_Char* _pSourceMethod, const sal_Char* _pAsciiMessage, ARGTYPE1 _argument1, ARGTYPE2 _argument2, ARGTYPE3 _argument3, ARGTYPE4 _argument4 ) const 504 { 505 if ( isLoggable( _nLogLevel ) ) 506 return impl_log( _nLogLevel, _pSourceClass, _pSourceMethod, ::rtl::OUString::createFromAscii( _pAsciiMessage ), 507 OptionalString( log::convert::convertLogArgToString( _argument1 ) ), 508 OptionalString( log::convert::convertLogArgToString( _argument2 ) ), 509 OptionalString( log::convert::convertLogArgToString( _argument3 ) ), 510 OptionalString( log::convert::convertLogArgToString( _argument4 ) ) ); 511 return false; 512 } 513 514 /// logs a given ASCII message, replacing 5 placeholders in the message with respective values 515 template< typename ARGTYPE1, typename ARGTYPE2, typename ARGTYPE3, typename ARGTYPE4, typename ARGTYPE5 > 516 bool logp( const sal_Int32 _nLogLevel, const sal_Char* _pSourceClass, const sal_Char* _pSourceMethod, const sal_Char* _pAsciiMessage, ARGTYPE1 _argument1, ARGTYPE2 _argument2, ARGTYPE3 _argument3, ARGTYPE4 _argument4, ARGTYPE5 _argument5 ) const 517 { 518 if ( isLoggable( _nLogLevel ) ) 519 return impl_log( _nLogLevel, _pSourceClass, _pSourceMethod, ::rtl::OUString::createFromAscii( _pAsciiMessage ), 520 OptionalString( log::convert::convertLogArgToString( _argument1 ) ), 521 OptionalString( log::convert::convertLogArgToString( _argument2 ) ), 522 OptionalString( log::convert::convertLogArgToString( _argument3 ) ), 523 OptionalString( log::convert::convertLogArgToString( _argument4 ) ), 524 OptionalString( log::convert::convertLogArgToString( _argument5 ) ) ); 525 return false; 526 } 527 528 /// logs a given ASCII message, replacing 6 placeholders in the message with respective values 529 template< typename ARGTYPE1, typename ARGTYPE2, typename ARGTYPE3, typename ARGTYPE4, typename ARGTYPE5, typename ARGTYPE6 > 530 bool logp( const sal_Int32 _nLogLevel, const sal_Char* _pSourceClass, const sal_Char* _pSourceMethod, const sal_Char* _pAsciiMessage, ARGTYPE1 _argument1, ARGTYPE2 _argument2, ARGTYPE3 _argument3, ARGTYPE4 _argument4, ARGTYPE5 _argument5, ARGTYPE6 _argument6 ) const 531 { 532 if ( isLoggable( _nLogLevel ) ) 533 return impl_log( _nLogLevel, _pSourceClass, _pSourceMethod, ::rtl::OUString::createFromAscii( _pAsciiMessage ), 534 OptionalString( log::convert::convertLogArgToString( _argument1 ) ), 535 OptionalString( log::convert::convertLogArgToString( _argument2 ) ), 536 OptionalString( log::convert::convertLogArgToString( _argument3 ) ), 537 OptionalString( log::convert::convertLogArgToString( _argument4 ) ), 538 OptionalString( log::convert::convertLogArgToString( _argument5 ) ), 539 OptionalString( log::convert::convertLogArgToString( _argument6 ) ) ); 540 return false; 541 } 542 543 protected: 544 bool impl_log( 545 const sal_Int32 _nLogLevel, 546 const sal_Char* _pSourceClass, 547 const sal_Char* _pSourceMethod, 548 const ::rtl::OUString& _rMessage, 549 const OptionalString& _rArgument1 = OptionalString(), 550 const OptionalString& _rArgument2 = OptionalString(), 551 const OptionalString& _rArgument3 = OptionalString(), 552 const OptionalString& _rArgument4 = OptionalString(), 553 const OptionalString& _rArgument5 = OptionalString(), 554 const OptionalString& _rArgument6 = OptionalString() 555 ) const; 556 }; 557 558 //==================================================================== 559 //= ResourceBasedEventLogger 560 //==================================================================== 561 struct ResourceBasedEventLogger_Data; 562 /** extends the EventLogger class with functionality to load log messages from 563 a resource bundle. 564 */ 565 class COMPHELPER_DLLPUBLIC ResourceBasedEventLogger : public EventLogger 566 { 567 private: 568 ::boost::shared_ptr< ResourceBasedEventLogger_Data > m_pData; 569 570 public: 571 /** creates a resource based event logger 572 @param _rxContext 573 the component context for creating new components 574 @param _rResourceBundleBaseName 575 the base name of the resource bundle to use. Will be used 576 in conjunction with XResourceBundleLoader::loadResource. 577 @param _rLoggerName 578 the name of the logger to work with. If empty, the office-wide 579 default logger will be used. 580 581 */ 582 ResourceBasedEventLogger( 583 const ::com::sun::star::uno::Reference< ::com::sun::star::uno::XComponentContext >& _rxContext, 584 const ::rtl::OUString& _rResourceBundleBaseName, 585 const ::rtl::OUString& _rLoggerName = ::rtl::OUString() 586 ); 587 588 /** creates a resource based event logger 589 @param _rxContext 590 the component context for creating new components 591 @param _pResourceBundleBaseName 592 the ASCII base name of the resource bundle to use. Will be used 593 in conjunction with XResourceBundleLoader::loadResource. 594 @param _pAsciiLoggerName 595 the ASCII name of the logger to work with. If NULL, the office-wide 596 default logger will be used. 597 598 */ 599 ResourceBasedEventLogger( 600 const ::com::sun::star::uno::Reference< ::com::sun::star::uno::XComponentContext >& _rxContext, 601 const sal_Char* _pResourceBundleBaseName, 602 const sal_Char* _pAsciiLoggerName = NULL 603 ); 604 605 //---------------------------------------------------------------- 606 //- XLogger::log equivalents/wrappers 607 //- resource IDs 608 609 /// logs a given message, without any arguments, or source class/method names 610 bool log( const sal_Int32 _nLogLevel, const sal_Int32 _nMessageResID ) const 611 { 612 if ( isLoggable( _nLogLevel ) ) 613 return impl_log( _nLogLevel, NULL, NULL, impl_loadStringMessage_nothrow( _nMessageResID ) ); 614 return false; 615 } 616 617 /** logs a given message, replacing a placeholder in the message with an argument 618 619 The function takes, additionally to the log level and the message, an arbitrary 620 argument. This argument is converted to a string using an overloaded function 621 named <code>convertLogArgToString</code>. Then, a placeholder "$1$" 622 is searched in the message string, and replaced with the argument string. 623 */ 624 template< typename ARGTYPE1 > 625 bool log( const sal_Int32 _nLogLevel, const sal_Int32 _nMessageResID, ARGTYPE1 _argument1 ) const 626 { 627 if ( isLoggable( _nLogLevel ) ) 628 return impl_log( _nLogLevel, NULL, NULL, impl_loadStringMessage_nothrow( _nMessageResID ), 629 OptionalString( log::convert::convertLogArgToString( _argument1 ) ) ); 630 return false; 631 } 632 633 /// logs a given message, replacing 2 placeholders in the message with respective values 634 template< typename ARGTYPE1, typename ARGTYPE2 > 635 bool log( const sal_Int32 _nLogLevel, const sal_Int32 _nMessageResID, ARGTYPE1 _argument1, ARGTYPE2 _argument2 ) const 636 { 637 if ( isLoggable( _nLogLevel ) ) 638 return impl_log( _nLogLevel, NULL, NULL, impl_loadStringMessage_nothrow( _nMessageResID ), 639 OptionalString( log::convert::convertLogArgToString( _argument1 ) ), 640 OptionalString( log::convert::convertLogArgToString( _argument2 ) ) ); 641 return false; 642 } 643 644 /// logs a given message, replacing 3 placeholders in the message with respective values 645 template< typename ARGTYPE1, typename ARGTYPE2, typename ARGTYPE3 > 646 bool log( const sal_Int32 _nLogLevel, const sal_Int32 _nMessageResID, ARGTYPE1 _argument1, ARGTYPE2 _argument2, ARGTYPE3 _argument3 ) const 647 { 648 if ( isLoggable( _nLogLevel ) ) 649 return impl_log( _nLogLevel, NULL, NULL, impl_loadStringMessage_nothrow( _nMessageResID ), 650 OptionalString( log::convert::convertLogArgToString( _argument1 ) ), 651 OptionalString( log::convert::convertLogArgToString( _argument2 ) ), 652 OptionalString( log::convert::convertLogArgToString( _argument3 ) ) ); 653 return false; 654 } 655 656 /// logs a given message, replacing 4 placeholders in the message with respective values 657 template< typename ARGTYPE1, typename ARGTYPE2, typename ARGTYPE3, typename ARGTYPE4 > 658 bool log( const sal_Int32 _nLogLevel, const sal_Int32 _nMessageResID, ARGTYPE1 _argument1, ARGTYPE2 _argument2, ARGTYPE3 _argument3, ARGTYPE4 _argument4 ) const 659 { 660 if ( isLoggable( _nLogLevel ) ) 661 return impl_log( _nLogLevel, NULL, NULL, impl_loadStringMessage_nothrow( _nMessageResID ), 662 OptionalString( log::convert::convertLogArgToString( _argument1 ) ), 663 OptionalString( log::convert::convertLogArgToString( _argument2 ) ), 664 OptionalString( log::convert::convertLogArgToString( _argument3 ) ), 665 OptionalString( log::convert::convertLogArgToString( _argument4 ) ) ); 666 return false; 667 } 668 669 /// logs a given message, replacing 5 placeholders in the message with respective values 670 template< typename ARGTYPE1, typename ARGTYPE2, typename ARGTYPE3, typename ARGTYPE4, typename ARGTYPE5 > 671 bool log( const sal_Int32 _nLogLevel, const sal_Int32 _nMessageResID, ARGTYPE1 _argument1, ARGTYPE2 _argument2, ARGTYPE3 _argument3, ARGTYPE4 _argument4, ARGTYPE5 _argument5 ) const 672 { 673 if ( isLoggable( _nLogLevel ) ) 674 return impl_log( _nLogLevel, NULL, NULL, impl_loadStringMessage_nothrow( _nMessageResID ), 675 OptionalString( log::convert::convertLogArgToString( _argument1 ) ), 676 OptionalString( log::convert::convertLogArgToString( _argument2 ) ), 677 OptionalString( log::convert::convertLogArgToString( _argument3 ) ), 678 OptionalString( log::convert::convertLogArgToString( _argument4 ) ), 679 OptionalString( log::convert::convertLogArgToString( _argument5 ) ) ); 680 return false; 681 } 682 683 /// logs a given message, replacing 6 placeholders in the message with respective values 684 template< typename ARGTYPE1, typename ARGTYPE2, typename ARGTYPE3, typename ARGTYPE4, typename ARGTYPE5, typename ARGTYPE6 > 685 bool log( const sal_Int32 _nLogLevel, const sal_Int32 _nMessageResID, ARGTYPE1 _argument1, ARGTYPE2 _argument2, ARGTYPE3 _argument3, ARGTYPE4 _argument4, ARGTYPE5 _argument5, ARGTYPE6 _argument6 ) const 686 { 687 if ( isLoggable( _nLogLevel ) ) 688 return impl_log( _nLogLevel, NULL, NULL, impl_loadStringMessage_nothrow( _nMessageResID ), 689 OptionalString( log::convert::convertLogArgToString( _argument1 ) ), 690 OptionalString( log::convert::convertLogArgToString( _argument2 ) ), 691 OptionalString( log::convert::convertLogArgToString( _argument3 ) ), 692 OptionalString( log::convert::convertLogArgToString( _argument4 ) ), 693 OptionalString( log::convert::convertLogArgToString( _argument5 ) ), 694 OptionalString( log::convert::convertLogArgToString( _argument6 ) ) ); 695 return false; 696 } 697 698 //---------------------------------------------------------------- 699 //- XLogger::logp equivalents/wrappers 700 //- resource IDs 701 702 /// logs a given ASCII message, without any arguments, or source class/method names 703 bool logp( const sal_Int32 _nLogLevel, const sal_Char* _pSourceClass, const sal_Char* _pSourceMethod, const sal_Int32 _nMessageResID ) const 704 { 705 if ( isLoggable( _nLogLevel ) ) 706 return impl_log( _nLogLevel, _pSourceClass, _pSourceMethod, impl_loadStringMessage_nothrow( _nMessageResID ) ); 707 return false; 708 } 709 710 /** logs a given ASCII message, replacing a placeholder in the message with an argument 711 */ 712 template< typename ARGTYPE1 > 713 bool logp( const sal_Int32 _nLogLevel, const sal_Char* _pSourceClass, const sal_Char* _pSourceMethod, const sal_Int32 _nMessageResID, ARGTYPE1 _argument1 ) const 714 { 715 if ( isLoggable( _nLogLevel ) ) 716 return impl_log( _nLogLevel, _pSourceClass, _pSourceMethod, impl_loadStringMessage_nothrow( _nMessageResID ), 717 OptionalString( log::convert::convertLogArgToString( _argument1 ) ) ); 718 return false; 719 } 720 721 /// logs a given ASCII message, replacing 2 placeholders in the message with respective values 722 template< typename ARGTYPE1, typename ARGTYPE2 > 723 bool logp( const sal_Int32 _nLogLevel, const sal_Char* _pSourceClass, const sal_Char* _pSourceMethod, const sal_Int32 _nMessageResID, ARGTYPE1 _argument1, ARGTYPE2 _argument2 ) const 724 { 725 if ( isLoggable( _nLogLevel ) ) 726 return impl_log( _nLogLevel, _pSourceClass, _pSourceMethod, impl_loadStringMessage_nothrow( _nMessageResID ), 727 OptionalString( log::convert::convertLogArgToString( _argument1 ) ), 728 OptionalString( log::convert::convertLogArgToString( _argument2 ) ) ); 729 return false; 730 } 731 732 /// logs a given ASCII message, replacing 3 placeholders in the message with respective values 733 template< typename ARGTYPE1, typename ARGTYPE2, typename ARGTYPE3 > 734 bool logp( const sal_Int32 _nLogLevel, const sal_Char* _pSourceClass, const sal_Char* _pSourceMethod, const sal_Int32 _nMessageResID, ARGTYPE1 _argument1, ARGTYPE2 _argument2, ARGTYPE3 _argument3 ) const 735 { 736 if ( isLoggable( _nLogLevel ) ) 737 return impl_log( _nLogLevel, _pSourceClass, _pSourceMethod, impl_loadStringMessage_nothrow( _nMessageResID ), 738 OptionalString( log::convert::convertLogArgToString( _argument1 ) ), 739 OptionalString( log::convert::convertLogArgToString( _argument2 ) ), 740 OptionalString( log::convert::convertLogArgToString( _argument3 ) ) ); 741 return false; 742 } 743 744 /// logs a given ASCII message, replacing 4 placeholders in the message with respective values 745 template< typename ARGTYPE1, typename ARGTYPE2, typename ARGTYPE3, typename ARGTYPE4 > 746 bool logp( const sal_Int32 _nLogLevel, const sal_Char* _pSourceClass, const sal_Char* _pSourceMethod, const sal_Int32 _nMessageResID, ARGTYPE1 _argument1, ARGTYPE2 _argument2, ARGTYPE3 _argument3, ARGTYPE4 _argument4 ) const 747 { 748 if ( isLoggable( _nLogLevel ) ) 749 return impl_log( _nLogLevel, _pSourceClass, _pSourceMethod, impl_loadStringMessage_nothrow( _nMessageResID ), 750 OptionalString( log::convert::convertLogArgToString( _argument1 ) ), 751 OptionalString( log::convert::convertLogArgToString( _argument2 ) ), 752 OptionalString( log::convert::convertLogArgToString( _argument3 ) ), 753 OptionalString( log::convert::convertLogArgToString( _argument4 ) ) ); 754 return false; 755 } 756 757 /// logs a given ASCII message, replacing 5 placeholders in the message with respective values 758 template< typename ARGTYPE1, typename ARGTYPE2, typename ARGTYPE3, typename ARGTYPE4, typename ARGTYPE5 > 759 bool logp( const sal_Int32 _nLogLevel, const sal_Char* _pSourceClass, const sal_Char* _pSourceMethod, const sal_Int32 _nMessageResID, ARGTYPE1 _argument1, ARGTYPE2 _argument2, ARGTYPE3 _argument3, ARGTYPE4 _argument4, ARGTYPE5 _argument5 ) const 760 { 761 if ( isLoggable( _nLogLevel ) ) 762 return impl_log( _nLogLevel, _pSourceClass, _pSourceMethod, impl_loadStringMessage_nothrow( _nMessageResID ), 763 OptionalString( log::convert::convertLogArgToString( _argument1 ) ), 764 OptionalString( log::convert::convertLogArgToString( _argument2 ) ), 765 OptionalString( log::convert::convertLogArgToString( _argument3 ) ), 766 OptionalString( log::convert::convertLogArgToString( _argument4 ) ), 767 OptionalString( log::convert::convertLogArgToString( _argument5 ) ) ); 768 return false; 769 } 770 771 /// logs a given ASCII message, replacing 6 placeholders in the message with respective values 772 template< typename ARGTYPE1, typename ARGTYPE2, typename ARGTYPE3, typename ARGTYPE4, typename ARGTYPE5, typename ARGTYPE6 > 773 bool logp( const sal_Int32 _nLogLevel, const sal_Char* _pSourceClass, const sal_Char* _pSourceMethod, const sal_Int32 _nMessageResID, ARGTYPE1 _argument1, ARGTYPE2 _argument2, ARGTYPE3 _argument3, ARGTYPE4 _argument4, ARGTYPE5 _argument5, ARGTYPE6 _argument6 ) const 774 { 775 if ( isLoggable( _nLogLevel ) ) 776 return impl_log( _nLogLevel, _pSourceClass, _pSourceMethod, impl_loadStringMessage_nothrow( _nMessageResID ), 777 OptionalString( log::convert::convertLogArgToString( _argument1 ) ), 778 OptionalString( log::convert::convertLogArgToString( _argument2 ) ), 779 OptionalString( log::convert::convertLogArgToString( _argument3 ) ), 780 OptionalString( log::convert::convertLogArgToString( _argument4 ) ), 781 OptionalString( log::convert::convertLogArgToString( _argument5 ) ), 782 OptionalString( log::convert::convertLogArgToString( _argument6 ) ) ); 783 return false; 784 } 785 786 private: 787 ::rtl::OUString impl_loadStringMessage_nothrow( const sal_Int32 _nMessageResID ) const; 788 }; 789 790 //........................................................................ 791 } // namespace comphelper 792 //........................................................................ 793 794 #endif // COMPHELPER_LOGGING_HXX 795