xref: /aoo42x/main/comphelper/source/misc/logging.cxx (revision 49b34792)
1dde7d3faSAndrew Rist /**************************************************************
2cdf0e10cSrcweir  *
3dde7d3faSAndrew Rist  * Licensed to the Apache Software Foundation (ASF) under one
4dde7d3faSAndrew Rist  * or more contributor license agreements.  See the NOTICE file
5dde7d3faSAndrew Rist  * distributed with this work for additional information
6dde7d3faSAndrew Rist  * regarding copyright ownership.  The ASF licenses this file
7dde7d3faSAndrew Rist  * to you under the Apache License, Version 2.0 (the
8dde7d3faSAndrew Rist  * "License"); you may not use this file except in compliance
9dde7d3faSAndrew Rist  * with the License.  You may obtain a copy of the License at
10dde7d3faSAndrew Rist  *
11dde7d3faSAndrew Rist  *   http://www.apache.org/licenses/LICENSE-2.0
12dde7d3faSAndrew Rist  *
13dde7d3faSAndrew Rist  * Unless required by applicable law or agreed to in writing,
14dde7d3faSAndrew Rist  * software distributed under the License is distributed on an
15dde7d3faSAndrew Rist  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16dde7d3faSAndrew Rist  * KIND, either express or implied.  See the License for the
17dde7d3faSAndrew Rist  * specific language governing permissions and limitations
18dde7d3faSAndrew Rist  * under the License.
19dde7d3faSAndrew Rist  *
20dde7d3faSAndrew Rist  *************************************************************/
21dde7d3faSAndrew Rist 
22dde7d3faSAndrew Rist 
23cdf0e10cSrcweir 
24cdf0e10cSrcweir // MARKER(update_precomp.py): autogen include statement, do not remove
25cdf0e10cSrcweir #include "precompiled_comphelper.hxx"
26cdf0e10cSrcweir 
27cdf0e10cSrcweir #include <comphelper/logging.hxx>
28cdf0e10cSrcweir #include <comphelper/componentcontext.hxx>
29cdf0e10cSrcweir 
30cdf0e10cSrcweir /** === begin UNO includes === **/
31cdf0e10cSrcweir #include <com/sun/star/logging/LoggerPool.hpp>
32cdf0e10cSrcweir #include <com/sun/star/logging/LogLevel.hpp>
33cdf0e10cSrcweir #include <com/sun/star/resource/XResourceBundle.hpp>
34cdf0e10cSrcweir #include <com/sun/star/resource/XResourceBundleLoader.hpp>
35cdf0e10cSrcweir /** === end UNO includes === **/
36cdf0e10cSrcweir 
37cdf0e10cSrcweir #include <rtl/ustrbuf.hxx>
38cdf0e10cSrcweir 
39cdf0e10cSrcweir //........................................................................
40cdf0e10cSrcweir namespace comphelper
41cdf0e10cSrcweir {
42cdf0e10cSrcweir //........................................................................
43cdf0e10cSrcweir 
44cdf0e10cSrcweir 	/** === begin UNO using === **/
45cdf0e10cSrcweir     using ::com::sun::star::uno::Reference;
46cdf0e10cSrcweir     using ::com::sun::star::uno::XComponentContext;
47cdf0e10cSrcweir     using ::com::sun::star::logging::XLoggerPool;
48cdf0e10cSrcweir     using ::com::sun::star::logging::LoggerPool;
49cdf0e10cSrcweir     using ::com::sun::star::logging::XLogger;
50cdf0e10cSrcweir     using ::com::sun::star::uno::UNO_QUERY_THROW;
51cdf0e10cSrcweir     using ::com::sun::star::uno::Exception;
52cdf0e10cSrcweir     using ::com::sun::star::logging::XLogHandler;
53cdf0e10cSrcweir     using ::com::sun::star::resource::XResourceBundle;
54cdf0e10cSrcweir     using ::com::sun::star::resource::XResourceBundleLoader;
55cdf0e10cSrcweir 	/** === end UNO using === **/
56cdf0e10cSrcweir     namespace LogLevel = ::com::sun::star::logging::LogLevel;
57cdf0e10cSrcweir 
58cdf0e10cSrcweir 	//====================================================================
59cdf0e10cSrcweir 	//= EventLogger_Impl - declaration
60cdf0e10cSrcweir 	//====================================================================
61cdf0e10cSrcweir     class EventLogger_Impl
62cdf0e10cSrcweir     {
63cdf0e10cSrcweir     private:
64cdf0e10cSrcweir         ::comphelper::ComponentContext  m_aContext;
65cdf0e10cSrcweir         ::rtl::OUString                 m_sLoggerName;
66cdf0e10cSrcweir         Reference< XLogger >            m_xLogger;
67cdf0e10cSrcweir 
68cdf0e10cSrcweir     public:
EventLogger_Impl(const Reference<XComponentContext> & _rxContext,const::rtl::OUString & _rLoggerName)69cdf0e10cSrcweir         EventLogger_Impl( const Reference< XComponentContext >& _rxContext, const ::rtl::OUString& _rLoggerName )
70cdf0e10cSrcweir             :m_aContext( _rxContext )
71cdf0e10cSrcweir             ,m_sLoggerName( _rLoggerName )
72cdf0e10cSrcweir         {
73cdf0e10cSrcweir             impl_createLogger_nothrow();
74cdf0e10cSrcweir         }
75cdf0e10cSrcweir 
isValid() const76cdf0e10cSrcweir         inline bool isValid() const { return m_xLogger.is(); }
getName() const77cdf0e10cSrcweir         inline const ::rtl::OUString&  getName() const { return m_sLoggerName; }
getLogger() const78cdf0e10cSrcweir         inline const Reference< XLogger >& getLogger() const { return m_xLogger; }
getContext() const79cdf0e10cSrcweir         inline const ::comphelper::ComponentContext& getContext() const { return m_aContext; }
80cdf0e10cSrcweir 
81cdf0e10cSrcweir     private:
82cdf0e10cSrcweir         void    impl_createLogger_nothrow();
83cdf0e10cSrcweir     };
84cdf0e10cSrcweir 
85cdf0e10cSrcweir 	//====================================================================
86cdf0e10cSrcweir 	//= EventLogger_Impl - implementation
87cdf0e10cSrcweir 	//====================================================================
88cdf0e10cSrcweir 	//--------------------------------------------------------------------
impl_createLogger_nothrow()89cdf0e10cSrcweir     void EventLogger_Impl::impl_createLogger_nothrow()
90cdf0e10cSrcweir     {
91cdf0e10cSrcweir         try
92cdf0e10cSrcweir         {
93cdf0e10cSrcweir             Reference< XLoggerPool > xPool( LoggerPool::get( m_aContext.getUNOContext() ), UNO_QUERY_THROW );
94*49b34792SHerbert Dürr             if ( !m_sLoggerName.isEmpty() )
95cdf0e10cSrcweir                 m_xLogger = xPool->getNamedLogger( m_sLoggerName );
96cdf0e10cSrcweir             else
97cdf0e10cSrcweir                 m_xLogger = xPool->getDefaultLogger();
98cdf0e10cSrcweir         }
99cdf0e10cSrcweir         catch( const Exception& e )
100cdf0e10cSrcweir         {
101cdf0e10cSrcweir             (void)e;
102cdf0e10cSrcweir             OSL_ENSURE( false, "EventLogger_Impl::impl_createLogger_nothrow: caught an exception!" );
103cdf0e10cSrcweir         }
104cdf0e10cSrcweir     }
105cdf0e10cSrcweir 
106cdf0e10cSrcweir 	//====================================================================
107cdf0e10cSrcweir 	//= EventLogger
108cdf0e10cSrcweir 	//====================================================================
109cdf0e10cSrcweir 	//--------------------------------------------------------------------
EventLogger(const Reference<XComponentContext> & _rxContext,const::rtl::OUString & _rLoggerName)110cdf0e10cSrcweir     EventLogger::EventLogger( const Reference< XComponentContext >& _rxContext, const ::rtl::OUString& _rLoggerName )
111cdf0e10cSrcweir         :m_pImpl( new EventLogger_Impl( _rxContext, _rLoggerName ) )
112cdf0e10cSrcweir     {
113cdf0e10cSrcweir     }
114cdf0e10cSrcweir 
115cdf0e10cSrcweir 	//--------------------------------------------------------------------
EventLogger(const Reference<XComponentContext> & _rxContext,const sal_Char * _pAsciiLoggerName)116cdf0e10cSrcweir     EventLogger::EventLogger( const Reference< XComponentContext >& _rxContext, const sal_Char* _pAsciiLoggerName )
117cdf0e10cSrcweir         :m_pImpl( new EventLogger_Impl( _rxContext, ::rtl::OUString::createFromAscii( _pAsciiLoggerName ) ) )
118cdf0e10cSrcweir     {
119cdf0e10cSrcweir     }
120cdf0e10cSrcweir 
121cdf0e10cSrcweir 	//--------------------------------------------------------------------
~EventLogger()122cdf0e10cSrcweir     EventLogger::~EventLogger()
123cdf0e10cSrcweir     {
124cdf0e10cSrcweir     }
125cdf0e10cSrcweir 
126cdf0e10cSrcweir 	//--------------------------------------------------------------------
getName() const127cdf0e10cSrcweir     const ::rtl::OUString& EventLogger::getName() const
128cdf0e10cSrcweir     {
129cdf0e10cSrcweir         return m_pImpl->getName();
130cdf0e10cSrcweir     }
131cdf0e10cSrcweir 
132cdf0e10cSrcweir 	//--------------------------------------------------------------------
getLogLevel() const133cdf0e10cSrcweir     sal_Int32 EventLogger::getLogLevel() const
134cdf0e10cSrcweir     {
135cdf0e10cSrcweir         try
136cdf0e10cSrcweir         {
137cdf0e10cSrcweir             if ( m_pImpl->isValid() )
138cdf0e10cSrcweir                 return m_pImpl->getLogger()->getLevel();
139cdf0e10cSrcweir         }
140cdf0e10cSrcweir         catch( const Exception& e )
141cdf0e10cSrcweir         {
142cdf0e10cSrcweir             (void)e;
143cdf0e10cSrcweir             OSL_ENSURE( false, "EventLogger::getLogLevel: caught an exception!" );
144cdf0e10cSrcweir         }
145cdf0e10cSrcweir 
146cdf0e10cSrcweir         return LogLevel::OFF;
147cdf0e10cSrcweir     }
148cdf0e10cSrcweir 
149cdf0e10cSrcweir 	//--------------------------------------------------------------------
setLogLevel(const sal_Int32 _nLogLevel) const150cdf0e10cSrcweir     void EventLogger::setLogLevel( const sal_Int32 _nLogLevel ) const
151cdf0e10cSrcweir     {
152cdf0e10cSrcweir         try
153cdf0e10cSrcweir         {
154cdf0e10cSrcweir             if ( m_pImpl->isValid() )
155cdf0e10cSrcweir                 m_pImpl->getLogger()->setLevel( _nLogLevel );
156cdf0e10cSrcweir         }
157cdf0e10cSrcweir         catch( const Exception& e )
158cdf0e10cSrcweir         {
159cdf0e10cSrcweir             (void)e;
160cdf0e10cSrcweir             OSL_ENSURE( false, "EventLogger::setLogLevel: caught an exception!" );
161cdf0e10cSrcweir         }
162cdf0e10cSrcweir     }
163cdf0e10cSrcweir 
164cdf0e10cSrcweir 	//--------------------------------------------------------------------
isLoggable(const sal_Int32 _nLogLevel) const165cdf0e10cSrcweir     bool EventLogger::isLoggable( const sal_Int32 _nLogLevel ) const
166cdf0e10cSrcweir     {
167cdf0e10cSrcweir         if ( !m_pImpl->isValid() )
168cdf0e10cSrcweir             return false;
169cdf0e10cSrcweir 
170cdf0e10cSrcweir         try
171cdf0e10cSrcweir         {
172cdf0e10cSrcweir             return m_pImpl->getLogger()->isLoggable( _nLogLevel );
173cdf0e10cSrcweir         }
174cdf0e10cSrcweir         catch( const Exception& e )
175cdf0e10cSrcweir         {
176cdf0e10cSrcweir             (void)e;
177cdf0e10cSrcweir             OSL_ENSURE( false, "EventLogger::isLoggable: caught an exception!" );
178cdf0e10cSrcweir         }
179cdf0e10cSrcweir 
180cdf0e10cSrcweir         return false;
181cdf0e10cSrcweir     }
182cdf0e10cSrcweir 
183cdf0e10cSrcweir 	//--------------------------------------------------------------------
addLogHandler(const Reference<XLogHandler> & _rxLogHandler)184cdf0e10cSrcweir     bool EventLogger::addLogHandler( const Reference< XLogHandler >& _rxLogHandler )
185cdf0e10cSrcweir     {
186cdf0e10cSrcweir         try
187cdf0e10cSrcweir         {
188cdf0e10cSrcweir             if ( m_pImpl->isValid() )
189cdf0e10cSrcweir             {
190cdf0e10cSrcweir                 m_pImpl->getLogger()->addLogHandler( _rxLogHandler );
191cdf0e10cSrcweir                 return true;
192cdf0e10cSrcweir             }
193cdf0e10cSrcweir         }
194cdf0e10cSrcweir         catch( const Exception& e )
195cdf0e10cSrcweir         {
196cdf0e10cSrcweir             (void)e;
197cdf0e10cSrcweir             OSL_ENSURE( false, "EventLogger::addLogHandler: caught an exception!" );
198cdf0e10cSrcweir         }
199cdf0e10cSrcweir         return false;
200cdf0e10cSrcweir     }
201cdf0e10cSrcweir 
202cdf0e10cSrcweir 	//--------------------------------------------------------------------
removeLogHandler(const Reference<XLogHandler> & _rxLogHandler)203cdf0e10cSrcweir     bool EventLogger::removeLogHandler( const Reference< XLogHandler >& _rxLogHandler )
204cdf0e10cSrcweir     {
205cdf0e10cSrcweir         try
206cdf0e10cSrcweir         {
207cdf0e10cSrcweir             if ( m_pImpl->isValid() )
208cdf0e10cSrcweir             {
209cdf0e10cSrcweir                 m_pImpl->getLogger()->removeLogHandler( _rxLogHandler );
210cdf0e10cSrcweir                 return true;
211cdf0e10cSrcweir             }
212cdf0e10cSrcweir         }
213cdf0e10cSrcweir         catch( const Exception& e )
214cdf0e10cSrcweir         {
215cdf0e10cSrcweir             (void)e;
216cdf0e10cSrcweir             OSL_ENSURE( false, "EventLogger::removeLogHandler: caught an exception!" );
217cdf0e10cSrcweir         }
218cdf0e10cSrcweir         return false;
219cdf0e10cSrcweir     }
220cdf0e10cSrcweir 
221cdf0e10cSrcweir     //--------------------------------------------------------------------
222cdf0e10cSrcweir     namespace
223cdf0e10cSrcweir     {
lcl_replaceParameter(::rtl::OUString & _inout_Message,const::rtl::OUString & _rPlaceHolder,const::rtl::OUString & _rReplacement)224cdf0e10cSrcweir         void    lcl_replaceParameter( ::rtl::OUString& _inout_Message, const ::rtl::OUString& _rPlaceHolder, const ::rtl::OUString& _rReplacement )
225cdf0e10cSrcweir         {
226cdf0e10cSrcweir             sal_Int32 nPlaceholderPosition = _inout_Message.indexOf( _rPlaceHolder );
227cdf0e10cSrcweir             OSL_ENSURE( nPlaceholderPosition >= 0, "lcl_replaceParameter: placeholder not found!" );
228cdf0e10cSrcweir             if ( nPlaceholderPosition < 0 )
229cdf0e10cSrcweir                 return;
230cdf0e10cSrcweir 
231cdf0e10cSrcweir             _inout_Message = _inout_Message.replaceAt( nPlaceholderPosition, _rPlaceHolder.getLength(), _rReplacement );
232cdf0e10cSrcweir         }
233cdf0e10cSrcweir     }
234cdf0e10cSrcweir 
235cdf0e10cSrcweir 	//--------------------------------------------------------------------
impl_log(const sal_Int32 _nLogLevel,const sal_Char * _pSourceClass,const sal_Char * _pSourceMethod,const::rtl::OUString & _rMessage,const OptionalString & _rArgument1,const OptionalString & _rArgument2,const OptionalString & _rArgument3,const OptionalString & _rArgument4,const OptionalString & _rArgument5,const OptionalString & _rArgument6) const236cdf0e10cSrcweir     bool EventLogger::impl_log( const sal_Int32 _nLogLevel,
237cdf0e10cSrcweir         const sal_Char* _pSourceClass, const sal_Char* _pSourceMethod, const ::rtl::OUString& _rMessage,
238cdf0e10cSrcweir         const OptionalString& _rArgument1, const OptionalString& _rArgument2,
239cdf0e10cSrcweir         const OptionalString& _rArgument3, const OptionalString& _rArgument4,
240cdf0e10cSrcweir         const OptionalString& _rArgument5, const OptionalString& _rArgument6 ) const
241cdf0e10cSrcweir     {
242cdf0e10cSrcweir         // (if ::rtl::OUString had an indexOfAscii, we could save those ugly statics ...)
243cdf0e10cSrcweir         static ::rtl::OUString sPH1( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "$1$" ) ) );
244cdf0e10cSrcweir         static ::rtl::OUString sPH2( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "$2$" ) ) );
245cdf0e10cSrcweir         static ::rtl::OUString sPH3( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "$3$" ) ) );
246cdf0e10cSrcweir         static ::rtl::OUString sPH4( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "$4$" ) ) );
247cdf0e10cSrcweir         static ::rtl::OUString sPH5( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "$5$" ) ) );
248cdf0e10cSrcweir         static ::rtl::OUString sPH6( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "$6$" ) ) );
249cdf0e10cSrcweir 
250cdf0e10cSrcweir         ::rtl::OUString sMessage( _rMessage );
251cdf0e10cSrcweir         if ( !!_rArgument1 )
252cdf0e10cSrcweir             lcl_replaceParameter( sMessage, sPH1, *_rArgument1 );
253cdf0e10cSrcweir 
254cdf0e10cSrcweir         if ( !!_rArgument2 )
255cdf0e10cSrcweir             lcl_replaceParameter( sMessage, sPH2, *_rArgument2 );
256cdf0e10cSrcweir 
257cdf0e10cSrcweir         if ( !!_rArgument3 )
258cdf0e10cSrcweir             lcl_replaceParameter( sMessage, sPH3, *_rArgument3 );
259cdf0e10cSrcweir 
260cdf0e10cSrcweir         if ( !!_rArgument4 )
261cdf0e10cSrcweir             lcl_replaceParameter( sMessage, sPH4, *_rArgument4 );
262cdf0e10cSrcweir 
263cdf0e10cSrcweir         if ( !!_rArgument5 )
264cdf0e10cSrcweir             lcl_replaceParameter( sMessage, sPH5, *_rArgument5 );
265cdf0e10cSrcweir 
266cdf0e10cSrcweir         if ( !!_rArgument6 )
267cdf0e10cSrcweir             lcl_replaceParameter( sMessage, sPH6, *_rArgument6 );
268cdf0e10cSrcweir 
269cdf0e10cSrcweir         try
270cdf0e10cSrcweir         {
271cdf0e10cSrcweir             Reference< XLogger > xLogger( m_pImpl->getLogger() );
272cdf0e10cSrcweir             OSL_PRECOND( xLogger.is(), "EventLogger::impl_log: should never be called without a logger!" );
273cdf0e10cSrcweir             if ( _pSourceClass && _pSourceMethod )
274cdf0e10cSrcweir             {
275cdf0e10cSrcweir                 xLogger->logp(
276cdf0e10cSrcweir                     _nLogLevel,
277cdf0e10cSrcweir                     ::rtl::OUString::createFromAscii( _pSourceClass ),
278cdf0e10cSrcweir                     ::rtl::OUString::createFromAscii( _pSourceMethod ),
279cdf0e10cSrcweir                     sMessage
280cdf0e10cSrcweir                 );
281cdf0e10cSrcweir             }
282cdf0e10cSrcweir             else
283cdf0e10cSrcweir             {
284cdf0e10cSrcweir                 xLogger->log( _nLogLevel, sMessage );
285cdf0e10cSrcweir             }
286cdf0e10cSrcweir         }
287cdf0e10cSrcweir         catch( const Exception& e )
288cdf0e10cSrcweir         {
289cdf0e10cSrcweir             (void)e;
290cdf0e10cSrcweir             OSL_ENSURE( false, "EventLogger::impl_log: caught an exception!" );
291cdf0e10cSrcweir         }
292cdf0e10cSrcweir 
293cdf0e10cSrcweir         return false;
294cdf0e10cSrcweir     }
295cdf0e10cSrcweir 
296cdf0e10cSrcweir 	//====================================================================
297cdf0e10cSrcweir 	//= ResourceBasedEventLogger_Data
298cdf0e10cSrcweir 	//====================================================================
299cdf0e10cSrcweir     struct ResourceBasedEventLogger_Data
300cdf0e10cSrcweir     {
301cdf0e10cSrcweir         /// the base name of the resource bundle
302cdf0e10cSrcweir         ::rtl::OUString                 sBundleBaseName;
303cdf0e10cSrcweir         /// did we already attempt to load the bundle?
304cdf0e10cSrcweir         bool                            bBundleLoaded;
305cdf0e10cSrcweir         /// the lazily loaded bundle
306cdf0e10cSrcweir         Reference< XResourceBundle >    xBundle;
307cdf0e10cSrcweir 
ResourceBasedEventLogger_Datacomphelper::ResourceBasedEventLogger_Data308cdf0e10cSrcweir         ResourceBasedEventLogger_Data()
309cdf0e10cSrcweir             :sBundleBaseName()
310cdf0e10cSrcweir             ,bBundleLoaded( false )
311cdf0e10cSrcweir             ,xBundle()
312cdf0e10cSrcweir         {
313cdf0e10cSrcweir         }
314cdf0e10cSrcweir     };
315cdf0e10cSrcweir 
316cdf0e10cSrcweir     //--------------------------------------------------------------------
lcl_loadBundle_nothrow(const ComponentContext & _rContext,ResourceBasedEventLogger_Data & _rLoggerData)317cdf0e10cSrcweir     bool    lcl_loadBundle_nothrow( const ComponentContext& _rContext, ResourceBasedEventLogger_Data& _rLoggerData )
318cdf0e10cSrcweir     {
319cdf0e10cSrcweir         if ( _rLoggerData.bBundleLoaded )
320cdf0e10cSrcweir             return _rLoggerData.xBundle.is();
321cdf0e10cSrcweir 
322cdf0e10cSrcweir         // no matter what happens below, don't attempt creation ever again
323cdf0e10cSrcweir         _rLoggerData.bBundleLoaded = true;
324cdf0e10cSrcweir 
325cdf0e10cSrcweir         try
326cdf0e10cSrcweir         {
327cdf0e10cSrcweir             Reference< XResourceBundleLoader > xLoader( _rContext.getSingleton( "com.sun.star.resource.OfficeResourceLoader" ), UNO_QUERY_THROW );
328cdf0e10cSrcweir             _rLoggerData.xBundle = Reference< XResourceBundle >( xLoader->loadBundle_Default( _rLoggerData.sBundleBaseName ), UNO_QUERY_THROW );
329cdf0e10cSrcweir         }
330cdf0e10cSrcweir         catch( const Exception& e )
331cdf0e10cSrcweir         {
332cdf0e10cSrcweir             (void)e;
333cdf0e10cSrcweir             OSL_ENSURE( false, "lcl_loadBundle_nothrow: caught an exception!" );
334cdf0e10cSrcweir         }
335cdf0e10cSrcweir 
336cdf0e10cSrcweir         return _rLoggerData.xBundle.is();
337cdf0e10cSrcweir     }
338cdf0e10cSrcweir 
339cdf0e10cSrcweir     //--------------------------------------------------------------------
lcl_loadString_nothrow(const Reference<XResourceBundle> & _rxBundle,const sal_Int32 _nMessageResID)340cdf0e10cSrcweir     ::rtl::OUString lcl_loadString_nothrow( const Reference< XResourceBundle >& _rxBundle, const sal_Int32 _nMessageResID )
341cdf0e10cSrcweir     {
342cdf0e10cSrcweir         OSL_PRECOND( _rxBundle.is(), "lcl_loadString_nothrow: this will crash!" );
343cdf0e10cSrcweir         ::rtl::OUString sMessage;
344cdf0e10cSrcweir         try
345cdf0e10cSrcweir         {
346cdf0e10cSrcweir             ::rtl::OUStringBuffer aBuffer;
347cdf0e10cSrcweir             aBuffer.appendAscii( "string:" );
348cdf0e10cSrcweir             aBuffer.append( _nMessageResID );
349cdf0e10cSrcweir             OSL_VERIFY( _rxBundle->getDirectElement( aBuffer.makeStringAndClear() ) >>= sMessage );
350cdf0e10cSrcweir         }
351cdf0e10cSrcweir         catch( const Exception& e )
352cdf0e10cSrcweir         {
353cdf0e10cSrcweir             (void)e;
354cdf0e10cSrcweir             OSL_ENSURE( false, "lcl_loadString_nothrow: caught an exception!" );
355cdf0e10cSrcweir         }
356cdf0e10cSrcweir         return sMessage;
357cdf0e10cSrcweir     }
358cdf0e10cSrcweir 
359cdf0e10cSrcweir 	//====================================================================
360cdf0e10cSrcweir 	//= ResourceBasedEventLogger
361cdf0e10cSrcweir 	//====================================================================
362cdf0e10cSrcweir 	//--------------------------------------------------------------------
ResourceBasedEventLogger(const Reference<XComponentContext> & _rxContext,const::rtl::OUString & _rResourceBundleBaseName,const::rtl::OUString & _rLoggerName)363cdf0e10cSrcweir     ResourceBasedEventLogger::ResourceBasedEventLogger( const Reference< XComponentContext >& _rxContext, const ::rtl::OUString& _rResourceBundleBaseName,
364cdf0e10cSrcweir         const ::rtl::OUString& _rLoggerName )
365cdf0e10cSrcweir         :EventLogger( _rxContext, _rLoggerName )
366cdf0e10cSrcweir         ,m_pData( new ResourceBasedEventLogger_Data )
367cdf0e10cSrcweir     {
368cdf0e10cSrcweir         m_pData->sBundleBaseName = _rResourceBundleBaseName;
369cdf0e10cSrcweir     }
370cdf0e10cSrcweir 
371cdf0e10cSrcweir 	//--------------------------------------------------------------------
ResourceBasedEventLogger(const Reference<XComponentContext> & _rxContext,const sal_Char * _pResourceBundleBaseName,const sal_Char * _pAsciiLoggerName)372cdf0e10cSrcweir     ResourceBasedEventLogger::ResourceBasedEventLogger( const Reference< XComponentContext >& _rxContext, const sal_Char* _pResourceBundleBaseName,
373cdf0e10cSrcweir         const sal_Char* _pAsciiLoggerName )
374cdf0e10cSrcweir         :EventLogger( _rxContext, _pAsciiLoggerName )
375cdf0e10cSrcweir         ,m_pData( new ResourceBasedEventLogger_Data )
376cdf0e10cSrcweir     {
377cdf0e10cSrcweir         m_pData->sBundleBaseName = ::rtl::OUString::createFromAscii( _pResourceBundleBaseName );
378cdf0e10cSrcweir     }
379cdf0e10cSrcweir 
380cdf0e10cSrcweir 	//--------------------------------------------------------------------
impl_loadStringMessage_nothrow(const sal_Int32 _nMessageResID) const381cdf0e10cSrcweir     ::rtl::OUString ResourceBasedEventLogger::impl_loadStringMessage_nothrow( const sal_Int32 _nMessageResID ) const
382cdf0e10cSrcweir     {
383cdf0e10cSrcweir         ::rtl::OUString sMessage;
384cdf0e10cSrcweir         if ( lcl_loadBundle_nothrow( m_pImpl->getContext(), *m_pData ) )
385cdf0e10cSrcweir             sMessage = lcl_loadString_nothrow( m_pData->xBundle, _nMessageResID );
386*49b34792SHerbert Dürr         if ( sMessage.isEmpty() )
387cdf0e10cSrcweir         {
388cdf0e10cSrcweir             ::rtl::OUStringBuffer aBuffer;
389cdf0e10cSrcweir             aBuffer.appendAscii( "<invalid event resource: '" );
390cdf0e10cSrcweir             aBuffer.append( m_pData->sBundleBaseName );
391cdf0e10cSrcweir             aBuffer.appendAscii( ":" );
392cdf0e10cSrcweir             aBuffer.append( _nMessageResID );
393cdf0e10cSrcweir             aBuffer.appendAscii( "'>" );
394cdf0e10cSrcweir             sMessage = aBuffer.makeStringAndClear();
395cdf0e10cSrcweir         }
396cdf0e10cSrcweir         return sMessage;
397cdf0e10cSrcweir     }
398cdf0e10cSrcweir 
399cdf0e10cSrcweir //........................................................................
400cdf0e10cSrcweir } // namespace comphelper
401cdf0e10cSrcweir //........................................................................
402