update emoji autocorrect entries from po-files
[LibreOffice.git] / include / comphelper / logging.hxx
blob0a5e8077fc0def813c1ceb166510f7e5ea244ec5
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
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>
30 #include <memory>
32 namespace comphelper
37 //= string conversions, employed by the templatized log* members of
38 //= EventLogger
41 namespace log { namespace convert
43 inline const OUString& convertLogArgToString( const OUString& _rValue )
45 return _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
65 //= EventLogger
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
74 for logging events.
76 You can use this class as follows
77 <pre>
78 EventLogger aLogger( xContext, sLoggerName );
79 ....
80 aLogger.log( LogLevel::SEVERE, sSomeMessage );
81 aLogger.logp( LogLevel::CONFIG, "MyClass", "MyMethod", sSomeMessage, SomeParameter1, SomeParameter2, SomeParameter3 );
82 </pre>
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
94 protected:
95 std::shared_ptr< EventLogger_Impl > m_pImpl;
97 public:
98 /** creates an <code>EventLogger</code> instance working with a css.logging.XLogger
99 instance given by ASCII name.
101 @param _rxContext
102 the component context to create services
104 @param _rLoggerName
105 the ASCII name of the logger to create.
107 EventLogger(
108 const ::com::sun::star::uno::Reference< ::com::sun::star::uno::XComponentContext >& _rxContext,
109 const sal_Char* _pAsciiLoggerName
112 ~EventLogger();
114 public:
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
120 //- string messages
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 );
127 return false;
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 &quot;$1$&quot;
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 ) ) );
143 return false;
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 ) ) );
154 return false;
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 ) ) );
166 return false;
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 ) ) );
179 return false;
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 ) ) );
193 return false;
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 ) ) );
208 return false;
212 //- XLogger::log equivalents/wrappers
213 //- ASCII messages
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 ) );
220 return false;
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 &quot;$1$&quot;
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 ) ) );
236 return false;
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 ) ) );
247 return false;
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 ) ) );
259 return false;
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 ) ) );
272 return false;
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 ) ) );
286 return false;
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 ) ) );
301 return false;
305 //- XLogger::logp equivalents/wrappers
306 //- string messages
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 );
313 return false;
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 &quot;$1$&quot;
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 ) ) );
329 return false;
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 ) ) );
340 return false;
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 ) ) );
352 return false;
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 ) ) );
365 return false;
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 ) ) );
379 return false;
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 ) ) );
394 return false;
398 //- XLogger::logp equivalents/wrappers
399 //- ASCII messages
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 ) );
406 return false;
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 &quot;$1$&quot;
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 ) ) );
422 return false;
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 ) ) );
433 return false;
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 ) ) );
445 return false;
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 ) ) );
458 return false;
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 ) ) );
472 return false;
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 ) ) );
487 return false;
490 protected:
491 bool impl_log(
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()
502 ) const;
506 //= ResourceBasedEventLogger
508 struct ResourceBasedEventLogger_Data;
509 /** extends the EventLogger class with functionality to load log messages from
510 a resource bundle.
512 class COMPHELPER_DLLPUBLIC ResourceBasedEventLogger : public EventLogger
514 private:
515 std::shared_ptr< ResourceBasedEventLogger_Data > m_pData;
517 public:
518 /** creates a resource based event logger
519 @param _rxContext
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
537 //- resource IDs
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 ) );
544 return false;
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 &quot;$1$&quot;
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 ) ) );
560 return false;
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 ) ) );
571 return false;
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 ) ) );
583 return false;
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 ) ) );
596 return false;
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 ) ) );
610 return false;
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 ) ) );
625 return false;
629 //- XLogger::logp equivalents/wrappers
630 //- resource IDs
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 ) );
637 return false;
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 ) ) );
648 return false;
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 ) ) );
659 return false;
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 ) ) );
671 return false;
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 ) ) );
684 return false;
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 ) ) );
698 return false;
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 ) ) );
713 return false;
716 private:
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: */