1*2a97ec55SAndrew Rist /**************************************************************
2cdf0e10cSrcweir  *
3*2a97ec55SAndrew Rist  * Licensed to the Apache Software Foundation (ASF) under one
4*2a97ec55SAndrew Rist  * or more contributor license agreements.  See the NOTICE file
5*2a97ec55SAndrew Rist  * distributed with this work for additional information
6*2a97ec55SAndrew Rist  * regarding copyright ownership.  The ASF licenses this file
7*2a97ec55SAndrew Rist  * to you under the Apache License, Version 2.0 (the
8*2a97ec55SAndrew Rist  * "License"); you may not use this file except in compliance
9*2a97ec55SAndrew Rist  * with the License.  You may obtain a copy of the License at
10*2a97ec55SAndrew Rist  *
11*2a97ec55SAndrew Rist  *   http://www.apache.org/licenses/LICENSE-2.0
12*2a97ec55SAndrew Rist  *
13*2a97ec55SAndrew Rist  * Unless required by applicable law or agreed to in writing,
14*2a97ec55SAndrew Rist  * software distributed under the License is distributed on an
15*2a97ec55SAndrew Rist  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16*2a97ec55SAndrew Rist  * KIND, either express or implied.  See the License for the
17*2a97ec55SAndrew Rist  * specific language governing permissions and limitations
18*2a97ec55SAndrew Rist  * under the License.
19*2a97ec55SAndrew Rist  *
20*2a97ec55SAndrew Rist  *************************************************************/
21*2a97ec55SAndrew Rist 
22*2a97ec55SAndrew Rist 
23cdf0e10cSrcweir 
24cdf0e10cSrcweir // MARKER(update_precomp.py): autogen include statement, do not remove
25cdf0e10cSrcweir #include "precompiled_extensions.hxx"
26cdf0e10cSrcweir 
27cdf0e10cSrcweir #include "log_module.hxx"
28cdf0e10cSrcweir #include "logrecord.hxx"
29cdf0e10cSrcweir #include "loggerconfig.hxx"
30cdf0e10cSrcweir 
31cdf0e10cSrcweir /** === begin UNO includes === **/
32cdf0e10cSrcweir #include <com/sun/star/logging/XLogger.hpp>
33cdf0e10cSrcweir #include <com/sun/star/logging/LogLevel.hpp>
34cdf0e10cSrcweir #include <com/sun/star/uno/XComponentContext.hpp>
35cdf0e10cSrcweir #include <com/sun/star/lang/XServiceInfo.hpp>
36cdf0e10cSrcweir #include <com/sun/star/logging/XLoggerPool.hpp>
37cdf0e10cSrcweir /** === end UNO includes === **/
38cdf0e10cSrcweir 
39cdf0e10cSrcweir #include <tools/diagnose_ex.h>
40cdf0e10cSrcweir 
41cdf0e10cSrcweir #include <comphelper/componentcontext.hxx>
42cdf0e10cSrcweir 
43cdf0e10cSrcweir #include <cppuhelper/basemutex.hxx>
44cdf0e10cSrcweir #include <cppuhelper/interfacecontainer.hxx>
45cdf0e10cSrcweir #include <cppuhelper/implbase2.hxx>
46cdf0e10cSrcweir #include <cppuhelper/weakref.hxx>
47cdf0e10cSrcweir 
48cdf0e10cSrcweir #include <boost/bind.hpp>
49cdf0e10cSrcweir 
50cdf0e10cSrcweir #include <map>
51cdf0e10cSrcweir 
52cdf0e10cSrcweir //........................................................................
53cdf0e10cSrcweir namespace logging
54cdf0e10cSrcweir {
55cdf0e10cSrcweir //........................................................................
56cdf0e10cSrcweir 
57cdf0e10cSrcweir 	/** === begin UNO using === **/
58cdf0e10cSrcweir     using ::com::sun::star::logging::XLogger;
59cdf0e10cSrcweir     using ::com::sun::star::uno::Reference;
60cdf0e10cSrcweir     using ::com::sun::star::uno::XComponentContext;
61cdf0e10cSrcweir     using ::com::sun::star::lang::XServiceInfo;
62cdf0e10cSrcweir     using ::com::sun::star::uno::RuntimeException;
63cdf0e10cSrcweir     using ::com::sun::star::uno::Sequence;
64cdf0e10cSrcweir     using ::com::sun::star::uno::XInterface;
65cdf0e10cSrcweir     using ::com::sun::star::uno::UNO_QUERY_THROW;
66cdf0e10cSrcweir     using ::com::sun::star::uno::Any;
67cdf0e10cSrcweir     using ::com::sun::star::uno::Exception;
68cdf0e10cSrcweir     using ::com::sun::star::uno::WeakReference;
69cdf0e10cSrcweir     using ::com::sun::star::logging::XLogHandler;
70cdf0e10cSrcweir     using ::com::sun::star::logging::XLoggerPool;
71cdf0e10cSrcweir     using ::com::sun::star::logging::LogRecord;
72cdf0e10cSrcweir 	/** === end UNO using === **/
73cdf0e10cSrcweir     namespace LogLevel = ::com::sun::star::logging::LogLevel;
74cdf0e10cSrcweir 
75cdf0e10cSrcweir 	//====================================================================
76cdf0e10cSrcweir 	//= helper
77cdf0e10cSrcweir 	//====================================================================
78cdf0e10cSrcweir     namespace
79cdf0e10cSrcweir     {
lcl_supportsService_nothrow(XServiceInfo & _rSI,const::rtl::OUString & _rServiceName)80cdf0e10cSrcweir         sal_Bool lcl_supportsService_nothrow( XServiceInfo& _rSI, const ::rtl::OUString& _rServiceName )
81cdf0e10cSrcweir         {
82cdf0e10cSrcweir             const Sequence< ::rtl::OUString > aServiceNames( _rSI.getSupportedServiceNames() );
83cdf0e10cSrcweir             for (   const ::rtl::OUString* pServiceNames = aServiceNames.getConstArray();
84cdf0e10cSrcweir                     pServiceNames != aServiceNames.getConstArray() + aServiceNames.getLength();
85cdf0e10cSrcweir                     ++pServiceNames
86cdf0e10cSrcweir                 )
87cdf0e10cSrcweir                 if ( _rServiceName == *pServiceNames )
88cdf0e10cSrcweir                     return sal_True;
89cdf0e10cSrcweir             return sal_False;
90cdf0e10cSrcweir         }
91cdf0e10cSrcweir     }
92cdf0e10cSrcweir 
93cdf0e10cSrcweir 	//====================================================================
94cdf0e10cSrcweir 	//= EventLogger - declaration
95cdf0e10cSrcweir 	//====================================================================
96cdf0e10cSrcweir     typedef ::cppu::WeakImplHelper2 <   XLogger
97cdf0e10cSrcweir                                     ,   XServiceInfo
98cdf0e10cSrcweir                                     >   EventLogger_Base;
99cdf0e10cSrcweir     class EventLogger   :public ::cppu::BaseMutex
100cdf0e10cSrcweir                         ,public EventLogger_Base
101cdf0e10cSrcweir     {
102cdf0e10cSrcweir     private:
103cdf0e10cSrcweir         ::comphelper::ComponentContext      m_aContext;
104cdf0e10cSrcweir         ::cppu::OInterfaceContainerHelper   m_aHandlers;
105cdf0e10cSrcweir         oslInterlockedCount                 m_nEventNumber;
106cdf0e10cSrcweir 
107cdf0e10cSrcweir         // <attributes>
108cdf0e10cSrcweir         sal_Int32       m_nLogLevel;
109cdf0e10cSrcweir         ::rtl::OUString m_sName;
110cdf0e10cSrcweir         // </attributes>
111cdf0e10cSrcweir 
112cdf0e10cSrcweir     public:
113cdf0e10cSrcweir         EventLogger( const Reference< XComponentContext >& _rxContext, const ::rtl::OUString& _rName );
114cdf0e10cSrcweir 
115cdf0e10cSrcweir         // XServiceInfo
116cdf0e10cSrcweir 		virtual ::rtl::OUString SAL_CALL getImplementationName() throw(RuntimeException);
117cdf0e10cSrcweir         virtual ::sal_Bool SAL_CALL supportsService( const ::rtl::OUString& _rServiceName ) throw(RuntimeException);
118cdf0e10cSrcweir         virtual Sequence< ::rtl::OUString > SAL_CALL getSupportedServiceNames() throw(RuntimeException);
119cdf0e10cSrcweir 
120cdf0e10cSrcweir         // XLogger
121cdf0e10cSrcweir         virtual ::rtl::OUString SAL_CALL getName() throw (RuntimeException);
122cdf0e10cSrcweir         virtual ::sal_Int32 SAL_CALL getLevel() throw (RuntimeException);
123cdf0e10cSrcweir         virtual void SAL_CALL setLevel( ::sal_Int32 _level ) throw (RuntimeException);
124cdf0e10cSrcweir         virtual void SAL_CALL addLogHandler( const Reference< XLogHandler >& LogHandler ) throw (RuntimeException);
125cdf0e10cSrcweir         virtual void SAL_CALL removeLogHandler( const Reference< XLogHandler >& LogHandler ) throw (RuntimeException);
126cdf0e10cSrcweir         virtual ::sal_Bool SAL_CALL isLoggable( ::sal_Int32 _nLevel ) throw (RuntimeException);
127cdf0e10cSrcweir         virtual void SAL_CALL log( ::sal_Int32 Level, const ::rtl::OUString& Message ) throw (RuntimeException);
128cdf0e10cSrcweir         virtual void SAL_CALL logp( ::sal_Int32 Level, const ::rtl::OUString& SourceClass, const ::rtl::OUString& SourceMethod, const ::rtl::OUString& Message ) throw (RuntimeException);
129cdf0e10cSrcweir 
130cdf0e10cSrcweir     protected:
131cdf0e10cSrcweir         ~EventLogger();
132cdf0e10cSrcweir 
133cdf0e10cSrcweir     private:
134cdf0e10cSrcweir         /** logs the given log record
135cdf0e10cSrcweir         */
136cdf0e10cSrcweir         void    impl_ts_logEvent_nothrow( const LogRecord& _rRecord );
137cdf0e10cSrcweir 
138cdf0e10cSrcweir         /** non-threadsafe impl-version of isLoggable
139cdf0e10cSrcweir         */
140cdf0e10cSrcweir         bool    impl_nts_isLoggable_nothrow( ::sal_Int32 _nLevel );
141cdf0e10cSrcweir     };
142cdf0e10cSrcweir 
143cdf0e10cSrcweir 	//====================================================================
144cdf0e10cSrcweir 	//= LoggerPool - declaration
145cdf0e10cSrcweir 	//====================================================================
146cdf0e10cSrcweir     typedef ::cppu::WeakImplHelper2 <   XLoggerPool
147cdf0e10cSrcweir                                     ,   XServiceInfo
148cdf0e10cSrcweir                                     >   LoggerPool_Base;
149cdf0e10cSrcweir     /** administrates a pool of XLogger instances, where a logger is keyed by its name,
150cdf0e10cSrcweir         and subsequent requests for a logger with the same name return the same instance.
151cdf0e10cSrcweir     */
152cdf0e10cSrcweir     class LoggerPool : public LoggerPool_Base
153cdf0e10cSrcweir     {
154cdf0e10cSrcweir     private:
155cdf0e10cSrcweir         typedef ::std::map< ::rtl::OUString, WeakReference< XLogger > > ImplPool;
156cdf0e10cSrcweir 
157cdf0e10cSrcweir     private:
158cdf0e10cSrcweir         ::osl::Mutex                    m_aMutex;
159cdf0e10cSrcweir         ::comphelper::ComponentContext  m_aContext;
160cdf0e10cSrcweir         ImplPool                        m_aImpl;
161cdf0e10cSrcweir 
162cdf0e10cSrcweir     public:
163cdf0e10cSrcweir         LoggerPool( const Reference< XComponentContext >& _rxContext );
164cdf0e10cSrcweir 
165cdf0e10cSrcweir         // XServiceInfo
166cdf0e10cSrcweir 		virtual ::rtl::OUString SAL_CALL getImplementationName() throw(RuntimeException);
167cdf0e10cSrcweir         virtual ::sal_Bool SAL_CALL supportsService( const ::rtl::OUString& _rServiceName ) throw(RuntimeException);
168cdf0e10cSrcweir         virtual Sequence< ::rtl::OUString > SAL_CALL getSupportedServiceNames() throw(RuntimeException);
169cdf0e10cSrcweir 
170cdf0e10cSrcweir         // helper for factories
171cdf0e10cSrcweir         static Sequence< ::rtl::OUString > getSupportedServiceNames_static();
172cdf0e10cSrcweir         static ::rtl::OUString  getImplementationName_static();
173cdf0e10cSrcweir         static ::rtl::OUString  getSingletonName_static();
174cdf0e10cSrcweir         static Reference< XInterface > Create( const Reference< XComponentContext >& _rxContext );
175cdf0e10cSrcweir 
176cdf0e10cSrcweir         // XLoggerPool
177cdf0e10cSrcweir         virtual Reference< XLogger > SAL_CALL getNamedLogger( const ::rtl::OUString& Name ) throw (RuntimeException);
178cdf0e10cSrcweir         virtual Reference< XLogger > SAL_CALL getDefaultLogger(  ) throw (RuntimeException);
179cdf0e10cSrcweir     };
180cdf0e10cSrcweir 
181cdf0e10cSrcweir 	//====================================================================
182cdf0e10cSrcweir 	//= EventLogger - implementation
183cdf0e10cSrcweir 	//====================================================================
184cdf0e10cSrcweir 	//--------------------------------------------------------------------
EventLogger(const Reference<XComponentContext> & _rxContext,const::rtl::OUString & _rName)185cdf0e10cSrcweir     EventLogger::EventLogger( const Reference< XComponentContext >& _rxContext, const ::rtl::OUString& _rName )
186cdf0e10cSrcweir         :m_aContext( _rxContext )
187cdf0e10cSrcweir         ,m_aHandlers( m_aMutex )
188cdf0e10cSrcweir         ,m_nEventNumber( 0 )
189cdf0e10cSrcweir         ,m_nLogLevel( LogLevel::OFF )
190cdf0e10cSrcweir         ,m_sName( _rName )
191cdf0e10cSrcweir     {
192cdf0e10cSrcweir         osl_incrementInterlockedCount( &m_refCount );
193cdf0e10cSrcweir         {
194cdf0e10cSrcweir             initializeLoggerFromConfiguration( m_aContext, this );
195cdf0e10cSrcweir         }
196cdf0e10cSrcweir         osl_decrementInterlockedCount( &m_refCount );
197cdf0e10cSrcweir     }
198cdf0e10cSrcweir 
199cdf0e10cSrcweir 	//--------------------------------------------------------------------
~EventLogger()200cdf0e10cSrcweir     EventLogger::~EventLogger()
201cdf0e10cSrcweir     {
202cdf0e10cSrcweir     }
203cdf0e10cSrcweir 
204cdf0e10cSrcweir     //--------------------------------------------------------------------
impl_nts_isLoggable_nothrow(::sal_Int32 _nLevel)205cdf0e10cSrcweir     bool EventLogger::impl_nts_isLoggable_nothrow( ::sal_Int32 _nLevel )
206cdf0e10cSrcweir     {
207cdf0e10cSrcweir         if ( _nLevel < m_nLogLevel )
208cdf0e10cSrcweir             return false;
209cdf0e10cSrcweir 
210cdf0e10cSrcweir         if ( !m_aHandlers.getLength() )
211cdf0e10cSrcweir             return false;
212cdf0e10cSrcweir 
213cdf0e10cSrcweir         return true;
214cdf0e10cSrcweir     }
215cdf0e10cSrcweir 
216cdf0e10cSrcweir     //--------------------------------------------------------------------
impl_ts_logEvent_nothrow(const LogRecord & _rRecord)217cdf0e10cSrcweir     void EventLogger::impl_ts_logEvent_nothrow( const LogRecord& _rRecord )
218cdf0e10cSrcweir     {
219cdf0e10cSrcweir         ::osl::MutexGuard aGuard( m_aMutex );
220cdf0e10cSrcweir 
221cdf0e10cSrcweir         if ( !impl_nts_isLoggable_nothrow( _rRecord.Level ) )
222cdf0e10cSrcweir             return;
223cdf0e10cSrcweir 
224cdf0e10cSrcweir         m_aHandlers.forEach< XLogHandler >(
225cdf0e10cSrcweir             ::boost::bind( &XLogHandler::publish, _1, ::boost::cref( _rRecord ) ) );
226cdf0e10cSrcweir         m_aHandlers.forEach< XLogHandler >(
227cdf0e10cSrcweir             ::boost::bind( &XLogHandler::flush, _1 ) );
228cdf0e10cSrcweir     }
229cdf0e10cSrcweir 
230cdf0e10cSrcweir     //--------------------------------------------------------------------
getName()231cdf0e10cSrcweir     ::rtl::OUString SAL_CALL EventLogger::getName() throw (RuntimeException)
232cdf0e10cSrcweir     {
233cdf0e10cSrcweir         return m_sName;
234cdf0e10cSrcweir     }
235cdf0e10cSrcweir 
236cdf0e10cSrcweir     //--------------------------------------------------------------------
getLevel()237cdf0e10cSrcweir     ::sal_Int32 SAL_CALL EventLogger::getLevel() throw (RuntimeException)
238cdf0e10cSrcweir     {
239cdf0e10cSrcweir         ::osl::MutexGuard aGuard( m_aMutex );
240cdf0e10cSrcweir         return m_nLogLevel;
241cdf0e10cSrcweir     }
242cdf0e10cSrcweir 
243cdf0e10cSrcweir     //--------------------------------------------------------------------
setLevel(::sal_Int32 _level)244cdf0e10cSrcweir     void SAL_CALL EventLogger::setLevel( ::sal_Int32 _level ) throw (RuntimeException)
245cdf0e10cSrcweir     {
246cdf0e10cSrcweir         ::osl::MutexGuard aGuard( m_aMutex );
247cdf0e10cSrcweir         m_nLogLevel = _level;
248cdf0e10cSrcweir     }
249cdf0e10cSrcweir 
250cdf0e10cSrcweir     //--------------------------------------------------------------------
addLogHandler(const Reference<XLogHandler> & _rxLogHandler)251cdf0e10cSrcweir     void SAL_CALL EventLogger::addLogHandler( const Reference< XLogHandler >& _rxLogHandler ) throw (RuntimeException)
252cdf0e10cSrcweir     {
253cdf0e10cSrcweir         if ( _rxLogHandler.is() )
254cdf0e10cSrcweir             m_aHandlers.addInterface( _rxLogHandler );
255cdf0e10cSrcweir     }
256cdf0e10cSrcweir 
257cdf0e10cSrcweir     //--------------------------------------------------------------------
removeLogHandler(const Reference<XLogHandler> & _rxLogHandler)258cdf0e10cSrcweir     void SAL_CALL EventLogger::removeLogHandler( const Reference< XLogHandler >& _rxLogHandler ) throw (RuntimeException)
259cdf0e10cSrcweir     {
260cdf0e10cSrcweir         if ( _rxLogHandler.is() )
261cdf0e10cSrcweir             m_aHandlers.removeInterface( _rxLogHandler );
262cdf0e10cSrcweir     }
263cdf0e10cSrcweir 
264cdf0e10cSrcweir     //--------------------------------------------------------------------
isLoggable(::sal_Int32 _nLevel)265cdf0e10cSrcweir     ::sal_Bool SAL_CALL EventLogger::isLoggable( ::sal_Int32 _nLevel ) throw (RuntimeException)
266cdf0e10cSrcweir     {
267cdf0e10cSrcweir         ::osl::MutexGuard aGuard( m_aMutex );
268cdf0e10cSrcweir         return impl_nts_isLoggable_nothrow( _nLevel );
269cdf0e10cSrcweir     }
270cdf0e10cSrcweir 
271cdf0e10cSrcweir     //--------------------------------------------------------------------
log(::sal_Int32 _nLevel,const::rtl::OUString & _rMessage)272cdf0e10cSrcweir     void SAL_CALL EventLogger::log( ::sal_Int32 _nLevel, const ::rtl::OUString& _rMessage ) throw (RuntimeException)
273cdf0e10cSrcweir     {
274cdf0e10cSrcweir         impl_ts_logEvent_nothrow( createLogRecord(
275cdf0e10cSrcweir             m_sName,
276cdf0e10cSrcweir             _rMessage,
277cdf0e10cSrcweir             _nLevel,
278cdf0e10cSrcweir             osl_incrementInterlockedCount( &m_nEventNumber )
279cdf0e10cSrcweir         ) );
280cdf0e10cSrcweir     }
281cdf0e10cSrcweir 
282cdf0e10cSrcweir     //--------------------------------------------------------------------
logp(::sal_Int32 _nLevel,const::rtl::OUString & _rSourceClass,const::rtl::OUString & _rSourceMethod,const::rtl::OUString & _rMessage)283cdf0e10cSrcweir     void SAL_CALL EventLogger::logp( ::sal_Int32 _nLevel, const ::rtl::OUString& _rSourceClass, const ::rtl::OUString& _rSourceMethod, const ::rtl::OUString& _rMessage ) throw (RuntimeException)
284cdf0e10cSrcweir     {
285cdf0e10cSrcweir         impl_ts_logEvent_nothrow( createLogRecord(
286cdf0e10cSrcweir             m_sName,
287cdf0e10cSrcweir             _rSourceClass,
288cdf0e10cSrcweir             _rSourceMethod,
289cdf0e10cSrcweir             _rMessage,
290cdf0e10cSrcweir             _nLevel,
291cdf0e10cSrcweir             osl_incrementInterlockedCount( &m_nEventNumber )
292cdf0e10cSrcweir         ) );
293cdf0e10cSrcweir     }
294cdf0e10cSrcweir 
295cdf0e10cSrcweir     //--------------------------------------------------------------------
getImplementationName()296cdf0e10cSrcweir     ::rtl::OUString SAL_CALL EventLogger::getImplementationName() throw(RuntimeException)
297cdf0e10cSrcweir     {
298cdf0e10cSrcweir         return ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "com.sun.star.comp.extensions.EventLogger" ) );
299cdf0e10cSrcweir     }
300cdf0e10cSrcweir 
301cdf0e10cSrcweir     //--------------------------------------------------------------------
supportsService(const::rtl::OUString & _rServiceName)302cdf0e10cSrcweir     ::sal_Bool EventLogger::supportsService( const ::rtl::OUString& _rServiceName ) throw(RuntimeException)
303cdf0e10cSrcweir     {
304cdf0e10cSrcweir         return lcl_supportsService_nothrow( *this, _rServiceName );
305cdf0e10cSrcweir     }
306cdf0e10cSrcweir 
307cdf0e10cSrcweir     //--------------------------------------------------------------------
getSupportedServiceNames()308cdf0e10cSrcweir     Sequence< ::rtl::OUString > SAL_CALL EventLogger::getSupportedServiceNames() throw(RuntimeException)
309cdf0e10cSrcweir     {
310cdf0e10cSrcweir         Sequence< ::rtl::OUString > aServiceNames(1);
311cdf0e10cSrcweir         aServiceNames[0] = ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "com.sun.star.logging.Logger" ) );
312cdf0e10cSrcweir         return aServiceNames;
313cdf0e10cSrcweir     }
314cdf0e10cSrcweir 
315cdf0e10cSrcweir 	//====================================================================
316cdf0e10cSrcweir 	//= LoggerPool - implementation
317cdf0e10cSrcweir 	//====================================================================
318cdf0e10cSrcweir     //--------------------------------------------------------------------
LoggerPool(const Reference<XComponentContext> & _rxContext)319cdf0e10cSrcweir     LoggerPool::LoggerPool( const Reference< XComponentContext >& _rxContext )
320cdf0e10cSrcweir         :m_aContext( _rxContext )
321cdf0e10cSrcweir     {
322cdf0e10cSrcweir     }
323cdf0e10cSrcweir 
324cdf0e10cSrcweir     //--------------------------------------------------------------------
getImplementationName()325cdf0e10cSrcweir     ::rtl::OUString SAL_CALL LoggerPool::getImplementationName() throw(RuntimeException)
326cdf0e10cSrcweir     {
327cdf0e10cSrcweir         return getImplementationName_static();
328cdf0e10cSrcweir     }
329cdf0e10cSrcweir 
330cdf0e10cSrcweir     //--------------------------------------------------------------------
supportsService(const::rtl::OUString & _rServiceName)331cdf0e10cSrcweir     ::sal_Bool SAL_CALL LoggerPool::supportsService( const ::rtl::OUString& _rServiceName ) throw(RuntimeException)
332cdf0e10cSrcweir     {
333cdf0e10cSrcweir         return lcl_supportsService_nothrow( *this, _rServiceName );
334cdf0e10cSrcweir     }
335cdf0e10cSrcweir 
336cdf0e10cSrcweir     //--------------------------------------------------------------------
getSupportedServiceNames()337cdf0e10cSrcweir     Sequence< ::rtl::OUString > SAL_CALL LoggerPool::getSupportedServiceNames() throw(RuntimeException)
338cdf0e10cSrcweir     {
339cdf0e10cSrcweir         return getSupportedServiceNames_static();
340cdf0e10cSrcweir     }
341cdf0e10cSrcweir 
342cdf0e10cSrcweir     //--------------------------------------------------------------------
getImplementationName_static()343cdf0e10cSrcweir     ::rtl::OUString SAL_CALL LoggerPool::getImplementationName_static()
344cdf0e10cSrcweir     {
345cdf0e10cSrcweir         return ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "com.sun.star.comp.extensions.LoggerPool" ) );
346cdf0e10cSrcweir     }
347cdf0e10cSrcweir 
348cdf0e10cSrcweir     //--------------------------------------------------------------------
getSupportedServiceNames_static()349cdf0e10cSrcweir     Sequence< ::rtl::OUString > SAL_CALL LoggerPool::getSupportedServiceNames_static()
350cdf0e10cSrcweir     {
351cdf0e10cSrcweir         Sequence< ::rtl::OUString > aServiceNames(1);
352cdf0e10cSrcweir         aServiceNames[0] = getSingletonName_static();
353cdf0e10cSrcweir         return aServiceNames;
354cdf0e10cSrcweir     }
355cdf0e10cSrcweir 
356cdf0e10cSrcweir     //--------------------------------------------------------------------
getSingletonName_static()357cdf0e10cSrcweir     ::rtl::OUString LoggerPool::getSingletonName_static()
358cdf0e10cSrcweir     {
359cdf0e10cSrcweir         return ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "com.sun.star.logging.LoggerPool" ) );
360cdf0e10cSrcweir     }
361cdf0e10cSrcweir 
362cdf0e10cSrcweir     //--------------------------------------------------------------------
Create(const Reference<XComponentContext> & _rxContext)363cdf0e10cSrcweir     Reference< XInterface > SAL_CALL LoggerPool::Create( const Reference< XComponentContext >& _rxContext )
364cdf0e10cSrcweir     {
365cdf0e10cSrcweir         return *( new LoggerPool( _rxContext ) );
366cdf0e10cSrcweir     }
367cdf0e10cSrcweir 
368cdf0e10cSrcweir     //--------------------------------------------------------------------
getNamedLogger(const::rtl::OUString & _rName)369cdf0e10cSrcweir     Reference< XLogger > SAL_CALL LoggerPool::getNamedLogger( const ::rtl::OUString& _rName ) throw (RuntimeException)
370cdf0e10cSrcweir     {
371cdf0e10cSrcweir         ::osl::MutexGuard aGuard( m_aMutex );
372cdf0e10cSrcweir 
373cdf0e10cSrcweir         WeakReference< XLogger >& rLogger( m_aImpl[ _rName ] );
374cdf0e10cSrcweir         Reference< XLogger > xLogger( (Reference< XLogger >)rLogger );
375cdf0e10cSrcweir         if ( !xLogger.is() )
376cdf0e10cSrcweir         {
377cdf0e10cSrcweir             // never requested before, or already dead
378cdf0e10cSrcweir             xLogger = new EventLogger( m_aContext.getUNOContext(), _rName );
379cdf0e10cSrcweir             rLogger = xLogger;
380cdf0e10cSrcweir         }
381cdf0e10cSrcweir 
382cdf0e10cSrcweir         return xLogger;
383cdf0e10cSrcweir     }
384cdf0e10cSrcweir 
385cdf0e10cSrcweir     //--------------------------------------------------------------------
getDefaultLogger()386cdf0e10cSrcweir     Reference< XLogger > SAL_CALL LoggerPool::getDefaultLogger(  ) throw (RuntimeException)
387cdf0e10cSrcweir     {
388cdf0e10cSrcweir         return getNamedLogger( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "org.openoffice.logging.DefaultLogger" ) ) );
389cdf0e10cSrcweir     }
390cdf0e10cSrcweir 
391cdf0e10cSrcweir     //--------------------------------------------------------------------
createRegistryInfo_LoggerPool()392cdf0e10cSrcweir     void createRegistryInfo_LoggerPool()
393cdf0e10cSrcweir     {
394cdf0e10cSrcweir         static OSingletonRegistration< LoggerPool > aAutoRegistration;
395cdf0e10cSrcweir     }
396cdf0e10cSrcweir 
397cdf0e10cSrcweir //........................................................................
398cdf0e10cSrcweir } // namespace logging
399cdf0e10cSrcweir //........................................................................
400cdf0e10cSrcweir 
401