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