1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
3 * This file is part of the LibreOffice project.
5 * This Source Code Form is subject to the terms of the Mozilla Public
6 * License, v. 2.0. If a copy of the MPL was not distributed with this
7 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
9 * This file incorporates work covered by the following license notice:
11 * Licensed to the Apache Software Foundation (ASF) under one or more
12 * contributor license agreements. See the NOTICE file distributed
13 * with this work for additional information regarding copyright
14 * ownership. The ASF licenses this file to you under the Apache
15 * License, Version 2.0 (the "License"); you may not use this file
16 * except in compliance with the License. You may obtain a copy of
17 * the License at http://www.apache.org/licenses/LICENSE-2.0 .
20 #ifndef INCLUDED_COMPHELPER_LOGGING_HXX
21 #define INCLUDED_COMPHELPER_LOGGING_HXX
23 #include <comphelper/comphelperdllapi.h>
25 #include <com/sun/star/uno/XComponentContext.hpp>
26 #include <com/sun/star/logging/XLogHandler.hpp>
27 #include <com/sun/star/logging/LogLevel.hpp>
29 #include <boost/optional.hpp>
37 //= string conversions, employed by the templatized log* members of
41 namespace log
{ namespace convert
43 inline const OUString
& convertLogArgToString( const OUString
& _rValue
)
48 inline OUString
convertLogArgToString( const sal_Char
* _pAsciiValue
)
50 return OUString::createFromAscii( _pAsciiValue
);
53 inline OUString
convertLogArgToString( double _nValue
) { return OUString::number( _nValue
); }
54 inline OUString
convertLogArgToString( float _nValue
) { return OUString::number( _nValue
); }
55 inline OUString
convertLogArgToString( sal_Int64 _nValue
) { return OUString::number( _nValue
); }
56 inline OUString
convertLogArgToString( sal_Int32 _nValue
) { return OUString::number( _nValue
); }
57 inline OUString
convertLogArgToString( sal_Int16 _nValue
) { return OUString::number( _nValue
); }
58 inline OUString
convertLogArgToString( sal_Unicode _nValue
) { return OUString( _nValue
); }
59 inline OUString
convertLogArgToString( bool _bValue
) { return OUString::boolean( _bValue
); }
60 void convertLogArgToString(sal_Bool
) SAL_DELETED_FUNCTION
;
62 } } // namespace log::convert
67 class EventLogger_Impl
;
68 typedef ::boost::optional
< OUString
> OptionalString
;
70 /** encapsulates an com::sun::star::logging::XLogger
72 The class silences several (unlikely) errors which could potentially happen
73 when working with a logger. Additionally, it provides some convenience methods
76 You can use this class as follows
78 EventLogger aLogger( xContext, sLoggerName );
80 aLogger.log( LogLevel::SEVERE, sSomeMessage );
81 aLogger.logp( LogLevel::CONFIG, "MyClass", "MyMethod", sSomeMessage, SomeParameter1, SomeParameter2, SomeParameter3 );
84 The <code>log</code> and <code>logp</code> calls support up to 6 parameters, which can be of
85 arbitrary type. For every parameter, there must exist a function <code>convertLogArgToString</code>
86 which takes an argument of the respective type, and returns a string.
88 After a parameter has been converted to a string using the above mentioned
89 <code>convertLogArgToString</code> function, a placeholder $1$ (resp. $2$ resp. $4$ ...)
90 in the message will be replaced with this string, and the resulting message will be logged.
92 class COMPHELPER_DLLPUBLIC EventLogger
95 std::shared_ptr
< EventLogger_Impl
> m_pImpl
;
98 /** creates an <code>EventLogger</code> instance working with a css.logging.XLogger
99 instance given by ASCII name.
102 the component context to create services
105 the ASCII name of the logger to create.
108 const ::com::sun::star::uno::Reference
< ::com::sun::star::uno::XComponentContext
>& _rxContext
,
109 const sal_Char
* _pAsciiLoggerName
115 /// determines whether an event with the given level would be logged
116 bool isLoggable( const sal_Int32 _nLogLevel
) const;
119 //- XLogger::log equivalents/wrappers
122 /// logs a given message, without any arguments, or source class/method names
123 bool log( const sal_Int32 _nLogLevel
, const OUString
& _rMessage
) const
125 if ( isLoggable( _nLogLevel
) )
126 return impl_log( _nLogLevel
, NULL
, NULL
, _rMessage
);
130 /** logs a given message, replacing a placeholder in the message with an argument
132 The function takes, additionally to the log level and the message, an arbitrary
133 argument. This argument is converted to a string using an overloaded function
134 named <code>convertLogArgToString</code>. Then, a placeholder "$1$"
135 is searched in the message string, and replaced with the argument string.
137 template< typename ARGTYPE1
>
138 bool log( const sal_Int32 _nLogLevel
, const OUString
& _rMessage
, ARGTYPE1 _argument1
) const
140 if ( isLoggable( _nLogLevel
) )
141 return impl_log( _nLogLevel
, NULL
, NULL
, _rMessage
,
142 OptionalString( log::convert::convertLogArgToString( _argument1
) ) );
146 /// logs a given message, replacing 2 placeholders in the message with respective values
147 template< typename ARGTYPE1
, typename ARGTYPE2
>
148 bool log( const sal_Int32 _nLogLevel
, const OUString
& _rMessage
, ARGTYPE1 _argument1
, ARGTYPE2 _argument2
) const
150 if ( isLoggable( _nLogLevel
) )
151 return impl_log( _nLogLevel
, NULL
, NULL
, _rMessage
,
152 OptionalString( log::convert::convertLogArgToString( _argument1
) ),
153 OptionalString( log::convert::convertLogArgToString( _argument2
) ) );
157 /// logs a given message, replacing 3 placeholders in the message with respective values
158 template< typename ARGTYPE1
, typename ARGTYPE2
, typename ARGTYPE3
>
159 bool log( const sal_Int32 _nLogLevel
, const OUString
& _rMessage
, ARGTYPE1 _argument1
, ARGTYPE2 _argument2
, ARGTYPE3 _argument3
) const
161 if ( isLoggable( _nLogLevel
) )
162 return impl_log( _nLogLevel
, NULL
, NULL
, _rMessage
,
163 OptionalString( log::convert::convertLogArgToString( _argument1
) ),
164 OptionalString( log::convert::convertLogArgToString( _argument2
) ),
165 OptionalString( log::convert::convertLogArgToString( _argument3
) ) );
169 /// logs a given message, replacing 4 placeholders in the message with respective values
170 template< typename ARGTYPE1
, typename ARGTYPE2
, typename ARGTYPE3
, typename ARGTYPE4
>
171 bool log( const sal_Int32 _nLogLevel
, const OUString
& _rMessage
, ARGTYPE1 _argument1
, ARGTYPE2 _argument2
, ARGTYPE3 _argument3
, ARGTYPE4 _argument4
) const
173 if ( isLoggable( _nLogLevel
) )
174 return impl_log( _nLogLevel
, NULL
, NULL
, _rMessage
,
175 OptionalString( log::convert::convertLogArgToString( _argument1
) ),
176 OptionalString( log::convert::convertLogArgToString( _argument2
) ),
177 OptionalString( log::convert::convertLogArgToString( _argument3
) ),
178 OptionalString( log::convert::convertLogArgToString( _argument4
) ) );
182 /// logs a given message, replacing 5 placeholders in the message with respective values
183 template< typename ARGTYPE1
, typename ARGTYPE2
, typename ARGTYPE3
, typename ARGTYPE4
, typename ARGTYPE5
>
184 bool log( const sal_Int32 _nLogLevel
, const OUString
& _rMessage
, ARGTYPE1 _argument1
, ARGTYPE2 _argument2
, ARGTYPE3 _argument3
, ARGTYPE4 _argument4
, ARGTYPE5 _argument5
) const
186 if ( isLoggable( _nLogLevel
) )
187 return impl_log( _nLogLevel
, NULL
, NULL
, _rMessage
,
188 OptionalString( log::convert::convertLogArgToString( _argument1
) ),
189 OptionalString( log::convert::convertLogArgToString( _argument2
) ),
190 OptionalString( log::convert::convertLogArgToString( _argument3
) ),
191 OptionalString( log::convert::convertLogArgToString( _argument4
) ),
192 OptionalString( log::convert::convertLogArgToString( _argument5
) ) );
196 /// logs a given message, replacing 6 placeholders in the message with respective values
197 template< typename ARGTYPE1
, typename ARGTYPE2
, typename ARGTYPE3
, typename ARGTYPE4
, typename ARGTYPE5
, typename ARGTYPE6
>
198 bool log( const sal_Int32 _nLogLevel
, const OUString
& _rMessage
, ARGTYPE1 _argument1
, ARGTYPE2 _argument2
, ARGTYPE3 _argument3
, ARGTYPE4 _argument4
, ARGTYPE5 _argument5
, ARGTYPE6 _argument6
) const
200 if ( isLoggable( _nLogLevel
) )
201 return impl_log( _nLogLevel
, NULL
, NULL
, _rMessage
,
202 OptionalString( log::convert::convertLogArgToString( _argument1
) ),
203 OptionalString( log::convert::convertLogArgToString( _argument2
) ),
204 OptionalString( log::convert::convertLogArgToString( _argument3
) ),
205 OptionalString( log::convert::convertLogArgToString( _argument4
) ),
206 OptionalString( log::convert::convertLogArgToString( _argument5
) ),
207 OptionalString( log::convert::convertLogArgToString( _argument6
) ) );
212 //- XLogger::log equivalents/wrappers
215 /// logs a given message, without any arguments, or source class/method names
216 bool log( const sal_Int32 _nLogLevel
, const sal_Char
* _pMessage
) const
218 if ( isLoggable( _nLogLevel
) )
219 return impl_log( _nLogLevel
, NULL
, NULL
, OUString::createFromAscii( _pMessage
) );
223 /** logs a given message, replacing a placeholder in the message with an argument
225 The function takes, additionally to the log level and the message, an arbitrary
226 argument. This argument is converted to a string using an overloaded function
227 named <code>convertLogArgToString</code>. Then, a placeholder "$1$"
228 is searched in the message string, and replaced with the argument string.
230 template< typename ARGTYPE1
>
231 bool log( const sal_Int32 _nLogLevel
, const sal_Char
* _pMessage
, ARGTYPE1 _argument1
) const
233 if ( isLoggable( _nLogLevel
) )
234 return impl_log( _nLogLevel
, NULL
, NULL
, OUString::createFromAscii( _pMessage
),
235 OptionalString( log::convert::convertLogArgToString( _argument1
) ) );
239 /// logs a given message, replacing 2 placeholders in the message with respective values
240 template< typename ARGTYPE1
, typename ARGTYPE2
>
241 bool log( const sal_Int32 _nLogLevel
, const sal_Char
* _pMessage
, ARGTYPE1 _argument1
, ARGTYPE2 _argument2
) const
243 if ( isLoggable( _nLogLevel
) )
244 return impl_log( _nLogLevel
, NULL
, NULL
, OUString::createFromAscii( _pMessage
),
245 OptionalString( log::convert::convertLogArgToString( _argument1
) ),
246 OptionalString( log::convert::convertLogArgToString( _argument2
) ) );
250 /// logs a given message, replacing 3 placeholders in the message with respective values
251 template< typename ARGTYPE1
, typename ARGTYPE2
, typename ARGTYPE3
>
252 bool log( const sal_Int32 _nLogLevel
, const sal_Char
* _pMessage
, ARGTYPE1 _argument1
, ARGTYPE2 _argument2
, ARGTYPE3 _argument3
) const
254 if ( isLoggable( _nLogLevel
) )
255 return impl_log( _nLogLevel
, NULL
, NULL
, OUString::createFromAscii( _pMessage
),
256 OptionalString( log::convert::convertLogArgToString( _argument1
) ),
257 OptionalString( log::convert::convertLogArgToString( _argument2
) ),
258 OptionalString( log::convert::convertLogArgToString( _argument3
) ) );
262 /// logs a given message, replacing 4 placeholders in the message with respective values
263 template< typename ARGTYPE1
, typename ARGTYPE2
, typename ARGTYPE3
, typename ARGTYPE4
>
264 bool log( const sal_Int32 _nLogLevel
, const sal_Char
* _pMessage
, ARGTYPE1 _argument1
, ARGTYPE2 _argument2
, ARGTYPE3 _argument3
, ARGTYPE4 _argument4
) const
266 if ( isLoggable( _nLogLevel
) )
267 return impl_log( _nLogLevel
, NULL
, NULL
, OUString::createFromAscii( _pMessage
),
268 OptionalString( log::convert::convertLogArgToString( _argument1
) ),
269 OptionalString( log::convert::convertLogArgToString( _argument2
) ),
270 OptionalString( log::convert::convertLogArgToString( _argument3
) ),
271 OptionalString( log::convert::convertLogArgToString( _argument4
) ) );
275 /// logs a given message, replacing 5 placeholders in the message with respective values
276 template< typename ARGTYPE1
, typename ARGTYPE2
, typename ARGTYPE3
, typename ARGTYPE4
, typename ARGTYPE5
>
277 bool log( const sal_Int32 _nLogLevel
, const sal_Char
* _pMessage
, ARGTYPE1 _argument1
, ARGTYPE2 _argument2
, ARGTYPE3 _argument3
, ARGTYPE4 _argument4
, ARGTYPE5 _argument5
) const
279 if ( isLoggable( _nLogLevel
) )
280 return impl_log( _nLogLevel
, NULL
, NULL
, OUString::createFromAscii( _pMessage
),
281 OptionalString( log::convert::convertLogArgToString( _argument1
) ),
282 OptionalString( log::convert::convertLogArgToString( _argument2
) ),
283 OptionalString( log::convert::convertLogArgToString( _argument3
) ),
284 OptionalString( log::convert::convertLogArgToString( _argument4
) ),
285 OptionalString( log::convert::convertLogArgToString( _argument5
) ) );
289 /// logs a given message, replacing 6 placeholders in the message with respective values
290 template< typename ARGTYPE1
, typename ARGTYPE2
, typename ARGTYPE3
, typename ARGTYPE4
, typename ARGTYPE5
, typename ARGTYPE6
>
291 bool log( const sal_Int32 _nLogLevel
, const sal_Char
* _pMessage
, ARGTYPE1 _argument1
, ARGTYPE2 _argument2
, ARGTYPE3 _argument3
, ARGTYPE4 _argument4
, ARGTYPE5 _argument5
, ARGTYPE6 _argument6
) const
293 if ( isLoggable( _nLogLevel
) )
294 return impl_log( _nLogLevel
, NULL
, NULL
, OUString::createFromAscii( _pMessage
),
295 OptionalString( log::convert::convertLogArgToString( _argument1
) ),
296 OptionalString( log::convert::convertLogArgToString( _argument2
) ),
297 OptionalString( log::convert::convertLogArgToString( _argument3
) ),
298 OptionalString( log::convert::convertLogArgToString( _argument4
) ),
299 OptionalString( log::convert::convertLogArgToString( _argument5
) ),
300 OptionalString( log::convert::convertLogArgToString( _argument6
) ) );
305 //- XLogger::logp equivalents/wrappers
308 /// logs a given message, without any arguments, or source class/method names
309 bool logp( const sal_Int32 _nLogLevel
, const sal_Char
* _pSourceClass
, const sal_Char
* _pSourceMethod
, const OUString
& _rMessage
) const
311 if ( isLoggable( _nLogLevel
) )
312 return impl_log( _nLogLevel
, _pSourceClass
, _pSourceMethod
, _rMessage
);
316 /** logs a given message, replacing a placeholder in the message with an argument
318 The function takes, additionally to the logp level and the message, an arbitrary
319 argument. This argument is converted to a string using an overloaded function
320 named <code>convertLogArgToString</code>. Then, a placeholder "$1$"
321 is searched in the message string, and replaced with the argument string.
323 template< typename ARGTYPE1
>
324 bool logp( const sal_Int32 _nLogLevel
, const sal_Char
* _pSourceClass
, const sal_Char
* _pSourceMethod
, const OUString
& _rMessage
, ARGTYPE1 _argument1
) const
326 if ( isLoggable( _nLogLevel
) )
327 return impl_log( _nLogLevel
, _pSourceClass
, _pSourceMethod
, _rMessage
,
328 OptionalString( log::convert::convertLogArgToString( _argument1
) ) );
332 /// logs a given message, replacing 2 placeholders in the message with respective values
333 template< typename ARGTYPE1
, typename ARGTYPE2
>
334 bool logp( const sal_Int32 _nLogLevel
, const sal_Char
* _pSourceClass
, const sal_Char
* _pSourceMethod
, const OUString
& _rMessage
, ARGTYPE1 _argument1
, ARGTYPE2 _argument2
) const
336 if ( isLoggable( _nLogLevel
) )
337 return impl_log( _nLogLevel
, _pSourceClass
, _pSourceMethod
, _rMessage
,
338 OptionalString( log::convert::convertLogArgToString( _argument1
) ),
339 OptionalString( log::convert::convertLogArgToString( _argument2
) ) );
343 /// logs a given message, replacing 3 placeholders in the message with respective values
344 template< typename ARGTYPE1
, typename ARGTYPE2
, typename ARGTYPE3
>
345 bool logp( const sal_Int32 _nLogLevel
, const sal_Char
* _pSourceClass
, const sal_Char
* _pSourceMethod
, const OUString
& _rMessage
, ARGTYPE1 _argument1
, ARGTYPE2 _argument2
, ARGTYPE3 _argument3
) const
347 if ( isLoggable( _nLogLevel
) )
348 return impl_log( _nLogLevel
, _pSourceClass
, _pSourceMethod
, _rMessage
,
349 OptionalString( log::convert::convertLogArgToString( _argument1
) ),
350 OptionalString( log::convert::convertLogArgToString( _argument2
) ),
351 OptionalString( log::convert::convertLogArgToString( _argument3
) ) );
355 /// logs a given message, replacing 4 placeholders in the message with respective values
356 template< typename ARGTYPE1
, typename ARGTYPE2
, typename ARGTYPE3
, typename ARGTYPE4
>
357 bool logp( const sal_Int32 _nLogLevel
, const sal_Char
* _pSourceClass
, const sal_Char
* _pSourceMethod
, const OUString
& _rMessage
, ARGTYPE1 _argument1
, ARGTYPE2 _argument2
, ARGTYPE3 _argument3
, ARGTYPE4 _argument4
) const
359 if ( isLoggable( _nLogLevel
) )
360 return impl_log( _nLogLevel
, _pSourceClass
, _pSourceMethod
, _rMessage
,
361 OptionalString( log::convert::convertLogArgToString( _argument1
) ),
362 OptionalString( log::convert::convertLogArgToString( _argument2
) ),
363 OptionalString( log::convert::convertLogArgToString( _argument3
) ),
364 OptionalString( log::convert::convertLogArgToString( _argument4
) ) );
368 /// logs a given message, replacing 5 placeholders in the message with respective values
369 template< typename ARGTYPE1
, typename ARGTYPE2
, typename ARGTYPE3
, typename ARGTYPE4
, typename ARGTYPE5
>
370 bool logp( const sal_Int32 _nLogLevel
, const sal_Char
* _pSourceClass
, const sal_Char
* _pSourceMethod
, const OUString
& _rMessage
, ARGTYPE1 _argument1
, ARGTYPE2 _argument2
, ARGTYPE3 _argument3
, ARGTYPE4 _argument4
, ARGTYPE5 _argument5
) const
372 if ( isLoggable( _nLogLevel
) )
373 return impl_log( _nLogLevel
, _pSourceClass
, _pSourceMethod
, _rMessage
,
374 OptionalString( log::convert::convertLogArgToString( _argument1
) ),
375 OptionalString( log::convert::convertLogArgToString( _argument2
) ),
376 OptionalString( log::convert::convertLogArgToString( _argument3
) ),
377 OptionalString( log::convert::convertLogArgToString( _argument4
) ),
378 OptionalString( log::convert::convertLogArgToString( _argument5
) ) );
382 /// logs a given message, replacing 6 placeholders in the message with respective values
383 template< typename ARGTYPE1
, typename ARGTYPE2
, typename ARGTYPE3
, typename ARGTYPE4
, typename ARGTYPE5
, typename ARGTYPE6
>
384 bool logp( const sal_Int32 _nLogLevel
, const sal_Char
* _pSourceClass
, const sal_Char
* _pSourceMethod
, const OUString
& _rMessage
, ARGTYPE1 _argument1
, ARGTYPE2 _argument2
, ARGTYPE3 _argument3
, ARGTYPE4 _argument4
, ARGTYPE5 _argument5
, ARGTYPE6 _argument6
) const
386 if ( isLoggable( _nLogLevel
) )
387 return impl_log( _nLogLevel
, _pSourceClass
, _pSourceMethod
, _rMessage
,
388 OptionalString( log::convert::convertLogArgToString( _argument1
) ),
389 OptionalString( log::convert::convertLogArgToString( _argument2
) ),
390 OptionalString( log::convert::convertLogArgToString( _argument3
) ),
391 OptionalString( log::convert::convertLogArgToString( _argument4
) ),
392 OptionalString( log::convert::convertLogArgToString( _argument5
) ),
393 OptionalString( log::convert::convertLogArgToString( _argument6
) ) );
398 //- XLogger::logp equivalents/wrappers
401 /// logs a given ASCII message, without any arguments, or source class/method names
402 bool logp( const sal_Int32 _nLogLevel
, const sal_Char
* _pSourceClass
, const sal_Char
* _pSourceMethod
, const sal_Char
* _pAsciiMessage
) const
404 if ( isLoggable( _nLogLevel
) )
405 return impl_log( _nLogLevel
, _pSourceClass
, _pSourceMethod
, OUString::createFromAscii( _pAsciiMessage
) );
409 /** logs a given ASCII message, replacing a placeholder in the message with an argument
411 The function takes, additionally to the logp level and the message, an arbitrary
412 argument. This argument is converted to a string using an overloaded function
413 named <code>convertLogArgToString</code>. Then, a placeholder "$1$"
414 is searched in the message string, and replaced with the argument string.
416 template< typename ARGTYPE1
>
417 bool logp( const sal_Int32 _nLogLevel
, const sal_Char
* _pSourceClass
, const sal_Char
* _pSourceMethod
, const sal_Char
* _pAsciiMessage
, ARGTYPE1 _argument1
) const
419 if ( isLoggable( _nLogLevel
) )
420 return impl_log( _nLogLevel
, _pSourceClass
, _pSourceMethod
, OUString::createFromAscii( _pAsciiMessage
),
421 OptionalString( log::convert::convertLogArgToString( _argument1
) ) );
425 /// logs a given ASCII message, replacing 2 placeholders in the message with respective values
426 template< typename ARGTYPE1
, typename ARGTYPE2
>
427 bool logp( const sal_Int32 _nLogLevel
, const sal_Char
* _pSourceClass
, const sal_Char
* _pSourceMethod
, const sal_Char
* _pAsciiMessage
, ARGTYPE1 _argument1
, ARGTYPE2 _argument2
) const
429 if ( isLoggable( _nLogLevel
) )
430 return impl_log( _nLogLevel
, _pSourceClass
, _pSourceMethod
, OUString::createFromAscii( _pAsciiMessage
),
431 OptionalString( log::convert::convertLogArgToString( _argument1
) ),
432 OptionalString( log::convert::convertLogArgToString( _argument2
) ) );
436 /// logs a given ASCII message, replacing 3 placeholders in the message with respective values
437 template< typename ARGTYPE1
, typename ARGTYPE2
, typename ARGTYPE3
>
438 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
440 if ( isLoggable( _nLogLevel
) )
441 return impl_log( _nLogLevel
, _pSourceClass
, _pSourceMethod
, OUString::createFromAscii( _pAsciiMessage
),
442 OptionalString( log::convert::convertLogArgToString( _argument1
) ),
443 OptionalString( log::convert::convertLogArgToString( _argument2
) ),
444 OptionalString( log::convert::convertLogArgToString( _argument3
) ) );
448 /// logs a given ASCII message, replacing 4 placeholders in the message with respective values
449 template< typename ARGTYPE1
, typename ARGTYPE2
, typename ARGTYPE3
, typename ARGTYPE4
>
450 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
452 if ( isLoggable( _nLogLevel
) )
453 return impl_log( _nLogLevel
, _pSourceClass
, _pSourceMethod
, OUString::createFromAscii( _pAsciiMessage
),
454 OptionalString( log::convert::convertLogArgToString( _argument1
) ),
455 OptionalString( log::convert::convertLogArgToString( _argument2
) ),
456 OptionalString( log::convert::convertLogArgToString( _argument3
) ),
457 OptionalString( log::convert::convertLogArgToString( _argument4
) ) );
461 /// logs a given ASCII message, replacing 5 placeholders in the message with respective values
462 template< typename ARGTYPE1
, typename ARGTYPE2
, typename ARGTYPE3
, typename ARGTYPE4
, typename ARGTYPE5
>
463 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
465 if ( isLoggable( _nLogLevel
) )
466 return impl_log( _nLogLevel
, _pSourceClass
, _pSourceMethod
, OUString::createFromAscii( _pAsciiMessage
),
467 OptionalString( log::convert::convertLogArgToString( _argument1
) ),
468 OptionalString( log::convert::convertLogArgToString( _argument2
) ),
469 OptionalString( log::convert::convertLogArgToString( _argument3
) ),
470 OptionalString( log::convert::convertLogArgToString( _argument4
) ),
471 OptionalString( log::convert::convertLogArgToString( _argument5
) ) );
475 /// logs a given ASCII message, replacing 6 placeholders in the message with respective values
476 template< typename ARGTYPE1
, typename ARGTYPE2
, typename ARGTYPE3
, typename ARGTYPE4
, typename ARGTYPE5
, typename ARGTYPE6
>
477 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
479 if ( isLoggable( _nLogLevel
) )
480 return impl_log( _nLogLevel
, _pSourceClass
, _pSourceMethod
, OUString::createFromAscii( _pAsciiMessage
),
481 OptionalString( log::convert::convertLogArgToString( _argument1
) ),
482 OptionalString( log::convert::convertLogArgToString( _argument2
) ),
483 OptionalString( log::convert::convertLogArgToString( _argument3
) ),
484 OptionalString( log::convert::convertLogArgToString( _argument4
) ),
485 OptionalString( log::convert::convertLogArgToString( _argument5
) ),
486 OptionalString( log::convert::convertLogArgToString( _argument6
) ) );
492 const sal_Int32 _nLogLevel
,
493 const sal_Char
* _pSourceClass
,
494 const sal_Char
* _pSourceMethod
,
495 const OUString
& _rMessage
,
496 const OptionalString
& _rArgument1
= OptionalString(),
497 const OptionalString
& _rArgument2
= OptionalString(),
498 const OptionalString
& _rArgument3
= OptionalString(),
499 const OptionalString
& _rArgument4
= OptionalString(),
500 const OptionalString
& _rArgument5
= OptionalString(),
501 const OptionalString
& _rArgument6
= OptionalString()
506 //= ResourceBasedEventLogger
508 struct ResourceBasedEventLogger_Data
;
509 /** extends the EventLogger class with functionality to load log messages from
512 class COMPHELPER_DLLPUBLIC ResourceBasedEventLogger
: public EventLogger
515 std::shared_ptr
< ResourceBasedEventLogger_Data
> m_pData
;
518 /** creates a resource based event logger
520 the component context for creating new components
521 @param _pResourceBundleBaseName
522 the ASCII base name of the resource bundle to use. Will be used
523 in conjunction with XResourceBundleLoader::loadResource.
524 @param _pAsciiLoggerName
525 the ASCII name of the logger to work with. If NULL, the office-wide
526 default logger will be used.
529 ResourceBasedEventLogger(
530 const ::com::sun::star::uno::Reference
< ::com::sun::star::uno::XComponentContext
>& _rxContext
,
531 const sal_Char
* _pResourceBundleBaseName
,
532 const sal_Char
* _pAsciiLoggerName
= NULL
536 //- XLogger::log equivalents/wrappers
539 /// logs a given message, without any arguments, or source class/method names
540 bool log( const sal_Int32 _nLogLevel
, const sal_Int32 _nMessageResID
) const
542 if ( isLoggable( _nLogLevel
) )
543 return impl_log( _nLogLevel
, NULL
, NULL
, impl_loadStringMessage_nothrow( _nMessageResID
) );
547 /** logs a given message, replacing a placeholder in the message with an argument
549 The function takes, additionally to the log level and the message, an arbitrary
550 argument. This argument is converted to a string using an overloaded function
551 named <code>convertLogArgToString</code>. Then, a placeholder "$1$"
552 is searched in the message string, and replaced with the argument string.
554 template< typename ARGTYPE1
>
555 bool log( const sal_Int32 _nLogLevel
, const sal_Int32 _nMessageResID
, ARGTYPE1 _argument1
) const
557 if ( isLoggable( _nLogLevel
) )
558 return impl_log( _nLogLevel
, NULL
, NULL
, impl_loadStringMessage_nothrow( _nMessageResID
),
559 OptionalString( log::convert::convertLogArgToString( _argument1
) ) );
563 /// logs a given message, replacing 2 placeholders in the message with respective values
564 template< typename ARGTYPE1
, typename ARGTYPE2
>
565 bool log( const sal_Int32 _nLogLevel
, const sal_Int32 _nMessageResID
, ARGTYPE1 _argument1
, ARGTYPE2 _argument2
) const
567 if ( isLoggable( _nLogLevel
) )
568 return impl_log( _nLogLevel
, NULL
, NULL
, impl_loadStringMessage_nothrow( _nMessageResID
),
569 OptionalString( log::convert::convertLogArgToString( _argument1
) ),
570 OptionalString( log::convert::convertLogArgToString( _argument2
) ) );
574 /// logs a given message, replacing 3 placeholders in the message with respective values
575 template< typename ARGTYPE1
, typename ARGTYPE2
, typename ARGTYPE3
>
576 bool log( const sal_Int32 _nLogLevel
, const sal_Int32 _nMessageResID
, ARGTYPE1 _argument1
, ARGTYPE2 _argument2
, ARGTYPE3 _argument3
) const
578 if ( isLoggable( _nLogLevel
) )
579 return impl_log( _nLogLevel
, NULL
, NULL
, impl_loadStringMessage_nothrow( _nMessageResID
),
580 OptionalString( log::convert::convertLogArgToString( _argument1
) ),
581 OptionalString( log::convert::convertLogArgToString( _argument2
) ),
582 OptionalString( log::convert::convertLogArgToString( _argument3
) ) );
586 /// logs a given message, replacing 4 placeholders in the message with respective values
587 template< typename ARGTYPE1
, typename ARGTYPE2
, typename ARGTYPE3
, typename ARGTYPE4
>
588 bool log( const sal_Int32 _nLogLevel
, const sal_Int32 _nMessageResID
, ARGTYPE1 _argument1
, ARGTYPE2 _argument2
, ARGTYPE3 _argument3
, ARGTYPE4 _argument4
) const
590 if ( isLoggable( _nLogLevel
) )
591 return impl_log( _nLogLevel
, NULL
, NULL
, impl_loadStringMessage_nothrow( _nMessageResID
),
592 OptionalString( log::convert::convertLogArgToString( _argument1
) ),
593 OptionalString( log::convert::convertLogArgToString( _argument2
) ),
594 OptionalString( log::convert::convertLogArgToString( _argument3
) ),
595 OptionalString( log::convert::convertLogArgToString( _argument4
) ) );
599 /// logs a given message, replacing 5 placeholders in the message with respective values
600 template< typename ARGTYPE1
, typename ARGTYPE2
, typename ARGTYPE3
, typename ARGTYPE4
, typename ARGTYPE5
>
601 bool log( const sal_Int32 _nLogLevel
, const sal_Int32 _nMessageResID
, ARGTYPE1 _argument1
, ARGTYPE2 _argument2
, ARGTYPE3 _argument3
, ARGTYPE4 _argument4
, ARGTYPE5 _argument5
) const
603 if ( isLoggable( _nLogLevel
) )
604 return impl_log( _nLogLevel
, NULL
, NULL
, impl_loadStringMessage_nothrow( _nMessageResID
),
605 OptionalString( log::convert::convertLogArgToString( _argument1
) ),
606 OptionalString( log::convert::convertLogArgToString( _argument2
) ),
607 OptionalString( log::convert::convertLogArgToString( _argument3
) ),
608 OptionalString( log::convert::convertLogArgToString( _argument4
) ),
609 OptionalString( log::convert::convertLogArgToString( _argument5
) ) );
613 /// logs a given message, replacing 6 placeholders in the message with respective values
614 template< typename ARGTYPE1
, typename ARGTYPE2
, typename ARGTYPE3
, typename ARGTYPE4
, typename ARGTYPE5
, typename ARGTYPE6
>
615 bool log( const sal_Int32 _nLogLevel
, const sal_Int32 _nMessageResID
, ARGTYPE1 _argument1
, ARGTYPE2 _argument2
, ARGTYPE3 _argument3
, ARGTYPE4 _argument4
, ARGTYPE5 _argument5
, ARGTYPE6 _argument6
) const
617 if ( isLoggable( _nLogLevel
) )
618 return impl_log( _nLogLevel
, NULL
, NULL
, impl_loadStringMessage_nothrow( _nMessageResID
),
619 OptionalString( log::convert::convertLogArgToString( _argument1
) ),
620 OptionalString( log::convert::convertLogArgToString( _argument2
) ),
621 OptionalString( log::convert::convertLogArgToString( _argument3
) ),
622 OptionalString( log::convert::convertLogArgToString( _argument4
) ),
623 OptionalString( log::convert::convertLogArgToString( _argument5
) ),
624 OptionalString( log::convert::convertLogArgToString( _argument6
) ) );
629 //- XLogger::logp equivalents/wrappers
632 /// logs a given ASCII message, without any arguments, or source class/method names
633 bool logp( const sal_Int32 _nLogLevel
, const sal_Char
* _pSourceClass
, const sal_Char
* _pSourceMethod
, const sal_Int32 _nMessageResID
) const
635 if ( isLoggable( _nLogLevel
) )
636 return impl_log( _nLogLevel
, _pSourceClass
, _pSourceMethod
, impl_loadStringMessage_nothrow( _nMessageResID
) );
640 /** logs a given ASCII message, replacing a placeholder in the message with an argument
642 template< typename ARGTYPE1
>
643 bool logp( const sal_Int32 _nLogLevel
, const sal_Char
* _pSourceClass
, const sal_Char
* _pSourceMethod
, const sal_Int32 _nMessageResID
, ARGTYPE1 _argument1
) const
645 if ( isLoggable( _nLogLevel
) )
646 return impl_log( _nLogLevel
, _pSourceClass
, _pSourceMethod
, impl_loadStringMessage_nothrow( _nMessageResID
),
647 OptionalString( log::convert::convertLogArgToString( _argument1
) ) );
651 /// logs a given ASCII message, replacing 2 placeholders in the message with respective values
652 template< typename ARGTYPE1
, typename ARGTYPE2
>
653 bool logp( const sal_Int32 _nLogLevel
, const sal_Char
* _pSourceClass
, const sal_Char
* _pSourceMethod
, const sal_Int32 _nMessageResID
, ARGTYPE1 _argument1
, ARGTYPE2 _argument2
) const
655 if ( isLoggable( _nLogLevel
) )
656 return impl_log( _nLogLevel
, _pSourceClass
, _pSourceMethod
, impl_loadStringMessage_nothrow( _nMessageResID
),
657 OptionalString( log::convert::convertLogArgToString( _argument1
) ),
658 OptionalString( log::convert::convertLogArgToString( _argument2
) ) );
662 /// logs a given ASCII message, replacing 3 placeholders in the message with respective values
663 template< typename ARGTYPE1
, typename ARGTYPE2
, typename ARGTYPE3
>
664 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
666 if ( isLoggable( _nLogLevel
) )
667 return impl_log( _nLogLevel
, _pSourceClass
, _pSourceMethod
, impl_loadStringMessage_nothrow( _nMessageResID
),
668 OptionalString( log::convert::convertLogArgToString( _argument1
) ),
669 OptionalString( log::convert::convertLogArgToString( _argument2
) ),
670 OptionalString( log::convert::convertLogArgToString( _argument3
) ) );
674 /// logs a given ASCII message, replacing 4 placeholders in the message with respective values
675 template< typename ARGTYPE1
, typename ARGTYPE2
, typename ARGTYPE3
, typename ARGTYPE4
>
676 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
678 if ( isLoggable( _nLogLevel
) )
679 return impl_log( _nLogLevel
, _pSourceClass
, _pSourceMethod
, impl_loadStringMessage_nothrow( _nMessageResID
),
680 OptionalString( log::convert::convertLogArgToString( _argument1
) ),
681 OptionalString( log::convert::convertLogArgToString( _argument2
) ),
682 OptionalString( log::convert::convertLogArgToString( _argument3
) ),
683 OptionalString( log::convert::convertLogArgToString( _argument4
) ) );
687 /// logs a given ASCII message, replacing 5 placeholders in the message with respective values
688 template< typename ARGTYPE1
, typename ARGTYPE2
, typename ARGTYPE3
, typename ARGTYPE4
, typename ARGTYPE5
>
689 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
691 if ( isLoggable( _nLogLevel
) )
692 return impl_log( _nLogLevel
, _pSourceClass
, _pSourceMethod
, impl_loadStringMessage_nothrow( _nMessageResID
),
693 OptionalString( log::convert::convertLogArgToString( _argument1
) ),
694 OptionalString( log::convert::convertLogArgToString( _argument2
) ),
695 OptionalString( log::convert::convertLogArgToString( _argument3
) ),
696 OptionalString( log::convert::convertLogArgToString( _argument4
) ),
697 OptionalString( log::convert::convertLogArgToString( _argument5
) ) );
701 /// logs a given ASCII message, replacing 6 placeholders in the message with respective values
702 template< typename ARGTYPE1
, typename ARGTYPE2
, typename ARGTYPE3
, typename ARGTYPE4
, typename ARGTYPE5
, typename ARGTYPE6
>
703 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
705 if ( isLoggable( _nLogLevel
) )
706 return impl_log( _nLogLevel
, _pSourceClass
, _pSourceMethod
, impl_loadStringMessage_nothrow( _nMessageResID
),
707 OptionalString( log::convert::convertLogArgToString( _argument1
) ),
708 OptionalString( log::convert::convertLogArgToString( _argument2
) ),
709 OptionalString( log::convert::convertLogArgToString( _argument3
) ),
710 OptionalString( log::convert::convertLogArgToString( _argument4
) ),
711 OptionalString( log::convert::convertLogArgToString( _argument5
) ),
712 OptionalString( log::convert::convertLogArgToString( _argument6
) ) );
717 OUString
impl_loadStringMessage_nothrow( const sal_Int32 _nMessageResID
) const;
721 } // namespace comphelper
724 #endif // INCLUDED_COMPHELPER_LOGGING_HXX
726 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */