Branch data Line data Source code
1 : : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 : : /*
3 : : * This file is part of the LibreOffice project.
4 : : *
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/.
8 : : *
9 : : * This file incorporates work covered by the following license notice:
10 : : *
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 .
18 : : */
19 : :
20 : : #ifndef COMPHELPER_LOGGING_HXX
21 : : #define COMPHELPER_LOGGING_HXX
22 : :
23 : : #include <comphelper/comphelperdllapi.h>
24 : :
25 : : #include <com/sun/star/uno/XComponentContext.hpp>
26 : : #include <com/sun/star/logging/XLogHandler.hpp>
27 : : #include <com/sun/star/logging/LogLevel.hpp>
28 : :
29 : : #include <boost/shared_ptr.hpp>
30 : : #include <boost/optional.hpp>
31 : :
32 : : //........................................................................
33 : : namespace comphelper
34 : : {
35 : : //........................................................................
36 : :
37 : : //====================================================================
38 : : //= string conversions, employed by the templatized log* members of
39 : : //= EventLogger
40 : : //====================================================================
41 : :
42 : : namespace log { namespace convert
43 : : {
44 : 0 : inline const ::rtl::OUString& convertLogArgToString( const ::rtl::OUString& _rValue )
45 : : {
46 : 0 : return _rValue;
47 : : }
48 : :
49 : 0 : inline ::rtl::OUString convertLogArgToString( const sal_Char* _pAsciiValue )
50 : : {
51 : 0 : return ::rtl::OUString::createFromAscii( _pAsciiValue );
52 : : }
53 : :
54 : 0 : inline ::rtl::OUString convertLogArgToString( double _nValue ) { return ::rtl::OUString::valueOf( _nValue ); }
55 : 0 : inline ::rtl::OUString convertLogArgToString( float _nValue ) { return ::rtl::OUString::valueOf( _nValue ); }
56 : 0 : inline ::rtl::OUString convertLogArgToString( sal_Int64 _nValue ) { return ::rtl::OUString::valueOf( _nValue ); }
57 : 0 : inline ::rtl::OUString convertLogArgToString( sal_Int32 _nValue ) { return ::rtl::OUString::valueOf( _nValue ); }
58 : 0 : inline ::rtl::OUString convertLogArgToString( sal_Int16 _nValue ) { return ::rtl::OUString::valueOf( (sal_Int32)_nValue ); }
59 : : inline ::rtl::OUString convertLogArgToString( sal_Unicode _nValue ) { return ::rtl::OUString::valueOf( _nValue ); }
60 : 0 : inline ::rtl::OUString convertLogArgToString( sal_Bool _nValue ) { return ::rtl::OUString::valueOf( _nValue ); }
61 : :
62 : : } } // namespace log::convert
63 : :
64 : : //====================================================================
65 : : //= EventLogger
66 : : //====================================================================
67 : : class EventLogger_Impl;
68 : : typedef ::boost::optional< ::rtl::OUString > OptionalString;
69 : :
70 : : /** encapsulates an <type scope="com::sun::star::logging">XLogger</type>
71 : :
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.
75 : :
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>
83 : :
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.
87 : :
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.
91 : : */
92 : 0 : class COMPHELPER_DLLPUBLIC EventLogger
93 : : {
94 : : protected:
95 : : ::boost::shared_ptr< EventLogger_Impl > m_pImpl;
96 : :
97 : : public:
98 : : /** creates an <code>EventLogger</code> instance working with a css.logging.XLogger
99 : : instance given by ASCII name.
100 : :
101 : : @param _rxContext
102 : : the component context to create services
103 : :
104 : : @param _rLoggerName
105 : : the ASCII name of the logger to create.
106 : : */
107 : : EventLogger(
108 : : const ::com::sun::star::uno::Reference< ::com::sun::star::uno::XComponentContext >& _rxContext,
109 : : const sal_Char* _pAsciiLoggerName
110 : : );
111 : :
112 : : ~EventLogger();
113 : :
114 : : public:
115 : : /// determines whether an event with the given level would be logged
116 : : bool isLoggable( const sal_Int32 _nLogLevel ) const;
117 : :
118 : : //----------------------------------------------------------------
119 : : //- XLogger::log equivalents/wrappers
120 : : //- string messages
121 : :
122 : : /// logs a given message, without any arguments, or source class/method names
123 : : bool log( const sal_Int32 _nLogLevel, const ::rtl::OUString& _rMessage ) const
124 : : {
125 : : if ( isLoggable( _nLogLevel ) )
126 : : return impl_log( _nLogLevel, NULL, NULL, _rMessage );
127 : : return false;
128 : : }
129 : :
130 : : /** logs a given message, replacing a placeholder in the message with an argument
131 : :
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.
136 : : */
137 : : template< typename ARGTYPE1 >
138 : : bool log( const sal_Int32 _nLogLevel, const ::rtl::OUString& _rMessage, ARGTYPE1 _argument1 ) const
139 : : {
140 : : if ( isLoggable( _nLogLevel ) )
141 : : return impl_log( _nLogLevel, NULL, NULL, _rMessage,
142 : : OptionalString( log::convert::convertLogArgToString( _argument1 ) ) );
143 : : return false;
144 : : }
145 : :
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 ::rtl::OUString& _rMessage, ARGTYPE1 _argument1, ARGTYPE2 _argument2 ) const
149 : : {
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;
155 : : }
156 : :
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 ::rtl::OUString& _rMessage, ARGTYPE1 _argument1, ARGTYPE2 _argument2, ARGTYPE3 _argument3 ) const
160 : : {
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;
167 : : }
168 : :
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 ::rtl::OUString& _rMessage, ARGTYPE1 _argument1, ARGTYPE2 _argument2, ARGTYPE3 _argument3, ARGTYPE4 _argument4 ) const
172 : : {
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;
180 : : }
181 : :
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 ::rtl::OUString& _rMessage, ARGTYPE1 _argument1, ARGTYPE2 _argument2, ARGTYPE3 _argument3, ARGTYPE4 _argument4, ARGTYPE5 _argument5 ) const
185 : : {
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;
194 : : }
195 : :
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 ::rtl::OUString& _rMessage, ARGTYPE1 _argument1, ARGTYPE2 _argument2, ARGTYPE3 _argument3, ARGTYPE4 _argument4, ARGTYPE5 _argument5, ARGTYPE6 _argument6 ) const
199 : : {
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;
209 : : }
210 : :
211 : : //----------------------------------------------------------------
212 : : //- XLogger::log equivalents/wrappers
213 : : //- ASCII messages
214 : :
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
217 : : {
218 : : if ( isLoggable( _nLogLevel ) )
219 : : return impl_log( _nLogLevel, NULL, NULL, ::rtl::OUString::createFromAscii( _pMessage ) );
220 : : return false;
221 : : }
222 : :
223 : : /** logs a given message, replacing a placeholder in the message with an argument
224 : :
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.
229 : : */
230 : : template< typename ARGTYPE1 >
231 : 408 : bool log( const sal_Int32 _nLogLevel, const sal_Char* _pMessage, ARGTYPE1 _argument1 ) const
232 : : {
233 [ - + ]: 408 : if ( isLoggable( _nLogLevel ) )
234 : : return impl_log( _nLogLevel, NULL, NULL, ::rtl::OUString::createFromAscii( _pMessage ),
235 [ # # ][ # # ]: 0 : OptionalString( log::convert::convertLogArgToString( _argument1 ) ) );
[ # # ][ # # ]
[ # # ][ # # ]
[ # # ][ # # ]
[ # # ][ # # ]
[ # # ]
236 : 408 : return false;
237 : : }
238 : :
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
242 : : {
243 : : if ( isLoggable( _nLogLevel ) )
244 : : return impl_log( _nLogLevel, NULL, NULL, ::rtl::OUString::createFromAscii( _pMessage ),
245 : : OptionalString( log::convert::convertLogArgToString( _argument1 ) ),
246 : : OptionalString( log::convert::convertLogArgToString( _argument2 ) ) );
247 : : return false;
248 : : }
249 : :
250 : : /// logs a given message, replacing 3 placeholders in the message with respective values
251 : : template< typename ARGTYPE1, typename ARGTYPE2, typename ARGTYPE3 >
252 : 0 : bool log( const sal_Int32 _nLogLevel, const sal_Char* _pMessage, ARGTYPE1 _argument1, ARGTYPE2 _argument2, ARGTYPE3 _argument3 ) const
253 : : {
254 [ # # ]: 0 : if ( isLoggable( _nLogLevel ) )
255 : : return impl_log( _nLogLevel, NULL, NULL, ::rtl::OUString::createFromAscii( _pMessage ),
256 : : OptionalString( log::convert::convertLogArgToString( _argument1 ) ),
257 : : OptionalString( log::convert::convertLogArgToString( _argument2 ) ),
258 [ # # ][ # # ]: 0 : OptionalString( log::convert::convertLogArgToString( _argument3 ) ) );
[ # # ][ # # ]
[ # # ][ # # ]
[ # # ][ # # ]
[ # # ][ # # ]
[ # # ]
259 : 0 : return false;
260 : : }
261 : :
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
265 : : {
266 : : if ( isLoggable( _nLogLevel ) )
267 : : return impl_log( _nLogLevel, NULL, NULL, ::rtl::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;
273 : : }
274 : :
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
278 : : {
279 : : if ( isLoggable( _nLogLevel ) )
280 : : return impl_log( _nLogLevel, NULL, NULL, ::rtl::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;
287 : : }
288 : :
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
292 : : {
293 : : if ( isLoggable( _nLogLevel ) )
294 : : return impl_log( _nLogLevel, NULL, NULL, ::rtl::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;
302 : : }
303 : :
304 : : //----------------------------------------------------------------
305 : : //- XLogger::logp equivalents/wrappers
306 : : //- string messages
307 : :
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 ::rtl::OUString& _rMessage ) const
310 : : {
311 : : if ( isLoggable( _nLogLevel ) )
312 : : return impl_log( _nLogLevel, _pSourceClass, _pSourceMethod, _rMessage );
313 : : return false;
314 : : }
315 : :
316 : : /** logs a given message, replacing a placeholder in the message with an argument
317 : :
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.
322 : : */
323 : : template< typename ARGTYPE1 >
324 : : bool logp( const sal_Int32 _nLogLevel, const sal_Char* _pSourceClass, const sal_Char* _pSourceMethod, const ::rtl::OUString& _rMessage, ARGTYPE1 _argument1 ) const
325 : : {
326 : : if ( isLoggable( _nLogLevel ) )
327 : : return impl_log( _nLogLevel, _pSourceClass, _pSourceMethod, _rMessage,
328 : : OptionalString( log::convert::convertLogArgToString( _argument1 ) ) );
329 : : return false;
330 : : }
331 : :
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 ::rtl::OUString& _rMessage, ARGTYPE1 _argument1, ARGTYPE2 _argument2 ) const
335 : : {
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;
341 : : }
342 : :
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 ::rtl::OUString& _rMessage, ARGTYPE1 _argument1, ARGTYPE2 _argument2, ARGTYPE3 _argument3 ) const
346 : : {
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;
353 : : }
354 : :
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 ::rtl::OUString& _rMessage, ARGTYPE1 _argument1, ARGTYPE2 _argument2, ARGTYPE3 _argument3, ARGTYPE4 _argument4 ) const
358 : : {
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;
366 : : }
367 : :
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 ::rtl::OUString& _rMessage, ARGTYPE1 _argument1, ARGTYPE2 _argument2, ARGTYPE3 _argument3, ARGTYPE4 _argument4, ARGTYPE5 _argument5 ) const
371 : : {
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;
380 : : }
381 : :
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 ::rtl::OUString& _rMessage, ARGTYPE1 _argument1, ARGTYPE2 _argument2, ARGTYPE3 _argument3, ARGTYPE4 _argument4, ARGTYPE5 _argument5, ARGTYPE6 _argument6 ) const
385 : : {
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;
395 : : }
396 : :
397 : : //----------------------------------------------------------------
398 : : //- XLogger::logp equivalents/wrappers
399 : : //- ASCII messages
400 : :
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
403 : : {
404 : : if ( isLoggable( _nLogLevel ) )
405 : : return impl_log( _nLogLevel, _pSourceClass, _pSourceMethod, ::rtl::OUString::createFromAscii( _pAsciiMessage ) );
406 : : return false;
407 : : }
408 : :
409 : : /** logs a given ASCII message, replacing a placeholder in the message with an argument
410 : :
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.
415 : : */
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
418 : : {
419 : : if ( isLoggable( _nLogLevel ) )
420 : : return impl_log( _nLogLevel, _pSourceClass, _pSourceMethod, ::rtl::OUString::createFromAscii( _pAsciiMessage ),
421 : : OptionalString( log::convert::convertLogArgToString( _argument1 ) ) );
422 : : return false;
423 : : }
424 : :
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
428 : : {
429 : : if ( isLoggable( _nLogLevel ) )
430 : : return impl_log( _nLogLevel, _pSourceClass, _pSourceMethod, ::rtl::OUString::createFromAscii( _pAsciiMessage ),
431 : : OptionalString( log::convert::convertLogArgToString( _argument1 ) ),
432 : : OptionalString( log::convert::convertLogArgToString( _argument2 ) ) );
433 : : return false;
434 : : }
435 : :
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
439 : : {
440 : : if ( isLoggable( _nLogLevel ) )
441 : : return impl_log( _nLogLevel, _pSourceClass, _pSourceMethod, ::rtl::OUString::createFromAscii( _pAsciiMessage ),
442 : : OptionalString( log::convert::convertLogArgToString( _argument1 ) ),
443 : : OptionalString( log::convert::convertLogArgToString( _argument2 ) ),
444 : : OptionalString( log::convert::convertLogArgToString( _argument3 ) ) );
445 : : return false;
446 : : }
447 : :
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
451 : : {
452 : : if ( isLoggable( _nLogLevel ) )
453 : : return impl_log( _nLogLevel, _pSourceClass, _pSourceMethod, ::rtl::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;
459 : : }
460 : :
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
464 : : {
465 : : if ( isLoggable( _nLogLevel ) )
466 : : return impl_log( _nLogLevel, _pSourceClass, _pSourceMethod, ::rtl::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;
473 : : }
474 : :
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
478 : : {
479 : : if ( isLoggable( _nLogLevel ) )
480 : : return impl_log( _nLogLevel, _pSourceClass, _pSourceMethod, ::rtl::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;
488 : : }
489 : :
490 : : protected:
491 : : bool impl_log(
492 : : const sal_Int32 _nLogLevel,
493 : : const sal_Char* _pSourceClass,
494 : : const sal_Char* _pSourceMethod,
495 : : const ::rtl::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;
503 : : };
504 : :
505 : : //====================================================================
506 : : //= ResourceBasedEventLogger
507 : : //====================================================================
508 : : struct ResourceBasedEventLogger_Data;
509 : : /** extends the EventLogger class with functionality to load log messages from
510 : : a resource bundle.
511 : : */
512 : 0 : class COMPHELPER_DLLPUBLIC ResourceBasedEventLogger : public EventLogger
513 : : {
514 : : private:
515 : : ::boost::shared_ptr< ResourceBasedEventLogger_Data > m_pData;
516 : :
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.
527 : :
528 : : */
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
533 : : );
534 : :
535 : : //----------------------------------------------------------------
536 : : //- XLogger::log equivalents/wrappers
537 : : //- resource IDs
538 : :
539 : : /// logs a given message, without any arguments, or source class/method names
540 : 0 : bool log( const sal_Int32 _nLogLevel, const sal_Int32 _nMessageResID ) const
541 : : {
542 : 0 : if ( isLoggable( _nLogLevel ) )
543 : 0 : return impl_log( _nLogLevel, NULL, NULL, impl_loadStringMessage_nothrow( _nMessageResID ) );
544 : 0 : return false;
545 : : }
546 : :
547 : : /** logs a given message, replacing a placeholder in the message with an argument
548 : :
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.
553 : : */
554 : : template< typename ARGTYPE1 >
555 : 0 : bool log( const sal_Int32 _nLogLevel, const sal_Int32 _nMessageResID, ARGTYPE1 _argument1 ) const
556 : : {
557 : 0 : if ( isLoggable( _nLogLevel ) )
558 : : return impl_log( _nLogLevel, NULL, NULL, impl_loadStringMessage_nothrow( _nMessageResID ),
559 : 0 : OptionalString( log::convert::convertLogArgToString( _argument1 ) ) );
560 : 0 : return false;
561 : : }
562 : :
563 : : /// logs a given message, replacing 2 placeholders in the message with respective values
564 : : template< typename ARGTYPE1, typename ARGTYPE2 >
565 : 0 : bool log( const sal_Int32 _nLogLevel, const sal_Int32 _nMessageResID, ARGTYPE1 _argument1, ARGTYPE2 _argument2 ) const
566 : : {
567 : 0 : if ( isLoggable( _nLogLevel ) )
568 : : return impl_log( _nLogLevel, NULL, NULL, impl_loadStringMessage_nothrow( _nMessageResID ),
569 : : OptionalString( log::convert::convertLogArgToString( _argument1 ) ),
570 : 0 : OptionalString( log::convert::convertLogArgToString( _argument2 ) ) );
571 : 0 : return false;
572 : : }
573 : :
574 : : /// logs a given message, replacing 3 placeholders in the message with respective values
575 : : template< typename ARGTYPE1, typename ARGTYPE2, typename ARGTYPE3 >
576 : 0 : bool log( const sal_Int32 _nLogLevel, const sal_Int32 _nMessageResID, ARGTYPE1 _argument1, ARGTYPE2 _argument2, ARGTYPE3 _argument3 ) const
577 : : {
578 : 0 : 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 : 0 : OptionalString( log::convert::convertLogArgToString( _argument3 ) ) );
583 : 0 : return false;
584 : : }
585 : :
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 : 0 : bool log( const sal_Int32 _nLogLevel, const sal_Int32 _nMessageResID, ARGTYPE1 _argument1, ARGTYPE2 _argument2, ARGTYPE3 _argument3, ARGTYPE4 _argument4 ) const
589 : : {
590 : 0 : 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 : 0 : OptionalString( log::convert::convertLogArgToString( _argument4 ) ) );
596 : 0 : return false;
597 : : }
598 : :
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 : 0 : bool log( const sal_Int32 _nLogLevel, const sal_Int32 _nMessageResID, ARGTYPE1 _argument1, ARGTYPE2 _argument2, ARGTYPE3 _argument3, ARGTYPE4 _argument4, ARGTYPE5 _argument5 ) const
602 : : {
603 : 0 : 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 : 0 : OptionalString( log::convert::convertLogArgToString( _argument5 ) ) );
610 : 0 : return false;
611 : : }
612 : :
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 : 0 : bool log( const sal_Int32 _nLogLevel, const sal_Int32 _nMessageResID, ARGTYPE1 _argument1, ARGTYPE2 _argument2, ARGTYPE3 _argument3, ARGTYPE4 _argument4, ARGTYPE5 _argument5, ARGTYPE6 _argument6 ) const
616 : : {
617 : 0 : 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 : 0 : OptionalString( log::convert::convertLogArgToString( _argument6 ) ) );
625 : 0 : return false;
626 : : }
627 : :
628 : : //----------------------------------------------------------------
629 : : //- XLogger::logp equivalents/wrappers
630 : : //- resource IDs
631 : :
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
634 : : {
635 : : if ( isLoggable( _nLogLevel ) )
636 : : return impl_log( _nLogLevel, _pSourceClass, _pSourceMethod, impl_loadStringMessage_nothrow( _nMessageResID ) );
637 : : return false;
638 : : }
639 : :
640 : : /** logs a given ASCII message, replacing a placeholder in the message with an argument
641 : : */
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
644 : : {
645 : : if ( isLoggable( _nLogLevel ) )
646 : : return impl_log( _nLogLevel, _pSourceClass, _pSourceMethod, impl_loadStringMessage_nothrow( _nMessageResID ),
647 : : OptionalString( log::convert::convertLogArgToString( _argument1 ) ) );
648 : : return false;
649 : : }
650 : :
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
654 : : {
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;
660 : : }
661 : :
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
665 : : {
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;
672 : : }
673 : :
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
677 : : {
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;
685 : : }
686 : :
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
690 : : {
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;
699 : : }
700 : :
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
704 : : {
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;
714 : : }
715 : :
716 : : private:
717 : : ::rtl::OUString impl_loadStringMessage_nothrow( const sal_Int32 _nMessageResID ) const;
718 : : };
719 : :
720 : : //........................................................................
721 : : } // namespace comphelper
722 : : //........................................................................
723 : :
724 : : #endif // COMPHELPER_LOGGING_HXX
725 : :
726 : : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|