24#include <com/sun/star/logging/XLogger.hpp>
25#include <com/sun/star/logging/LogLevel.hpp>
26#include <com/sun/star/uno/XComponentContext.hpp>
27#include <com/sun/star/lang/XServiceInfo.hpp>
28#include <com/sun/star/logging/XLoggerPool.hpp>
42 using ::com::sun::star::logging::XLogger;
43 using ::com::sun::star::uno::Reference;
44 using ::com::sun::star::uno::XComponentContext;
45 using ::com::sun::star::lang::XServiceInfo;
46 using ::com::sun::star::uno::Sequence;
47 using ::com::sun::star::uno::XInterface;
48 using ::com::sun::star::uno::WeakReference;
49 using ::com::sun::star::logging::XLogHandler;
50 using ::com::sun::star::logging::LogRecord;
55 public cppu::WeakImplHelper<css::logging::XLogger>
67 EventLogger(
const Reference< XComponentContext >& _rxContext, OUString _aName );
70 virtual OUString SAL_CALL getName()
override;
71 virtual ::sal_Int32 SAL_CALL getLevel()
override;
72 virtual void SAL_CALL setLevel( ::sal_Int32 _level )
override;
73 virtual void SAL_CALL addLogHandler(
const Reference< XLogHandler >& LogHandler )
override;
74 virtual void SAL_CALL removeLogHandler(
const Reference< XLogHandler >& LogHandler )
override;
75 virtual sal_Bool SAL_CALL isLoggable( ::sal_Int32 _nLevel )
override;
76 virtual void SAL_CALL
log( ::sal_Int32 Level,
const OUString& Message )
override;
77 virtual void SAL_CALL logp( ::sal_Int32 Level,
const OUString& SourceClass,
const OUString& SourceMethod,
const OUString& Message )
override;
80 virtual ~EventLogger()
override;
85 void impl_ts_logEvent_nothrow(
const LogRecord& _rRecord );
89 bool impl_nts_isLoggable_nothrow( ::sal_Int32 _nLevel );
95 class LoggerPool :
public cppu::WeakImplHelper<css::logging::XLoggerPool, XServiceInfo>
103 explicit LoggerPool(
const Reference< XComponentContext >& _rxContext );
111 virtual Reference< XLogger > SAL_CALL getNamedLogger(
const OUString& Name )
override;
112 virtual Reference< XLogger > SAL_CALL getDefaultLogger( )
override;
117 EventLogger::EventLogger(
const Reference< XComponentContext >& _rxContext, OUString _aName )
123 osl_atomic_increment( &m_refCount );
127 osl_atomic_decrement( &m_refCount );
130 EventLogger::~EventLogger()
134 bool EventLogger::impl_nts_isLoggable_nothrow( ::sal_Int32 _nLevel )
145 void EventLogger::impl_ts_logEvent_nothrow(
const LogRecord& _rRecord )
147 ::osl::MutexGuard aGuard(
m_aMutex );
149 if ( !impl_nts_isLoggable_nothrow( _rRecord.Level ) )
153 [&_rRecord] (Reference<XLogHandler>
const& rxListener) { rxListener->publish(_rRecord); } );
155 [] (Reference<XLogHandler>
const& rxListener) { rxListener->flush(); } );
158 OUString SAL_CALL EventLogger::getName()
163 ::sal_Int32 SAL_CALL EventLogger::getLevel()
165 ::osl::MutexGuard aGuard(
m_aMutex );
169 void SAL_CALL EventLogger::setLevel( ::sal_Int32 _level )
171 ::osl::MutexGuard aGuard(
m_aMutex );
175 void SAL_CALL EventLogger::addLogHandler(
const Reference< XLogHandler >& _rxLogHandler )
177 if ( _rxLogHandler.is() )
181 void SAL_CALL EventLogger::removeLogHandler(
const Reference< XLogHandler >& _rxLogHandler )
183 if ( _rxLogHandler.is() )
187 sal_Bool SAL_CALL EventLogger::isLoggable( ::sal_Int32 _nLevel )
189 ::osl::MutexGuard aGuard(
m_aMutex );
190 return impl_nts_isLoggable_nothrow( _nLevel );
193 void SAL_CALL EventLogger::log( ::sal_Int32 _nLevel,
const OUString& _rMessage )
203 void SAL_CALL EventLogger::logp( ::sal_Int32 _nLevel,
const OUString& _rSourceClass,
const OUString& _rSourceMethod,
const OUString& _rMessage )
215 LoggerPool::LoggerPool(
const Reference< XComponentContext >& _rxContext )
220 OUString SAL_CALL LoggerPool::getImplementationName()
222 return "com.sun.star.comp.extensions.LoggerPool";
225 sal_Bool SAL_CALL LoggerPool::supportsService(
const OUString& _rServiceName )
230 Sequence< OUString > SAL_CALL LoggerPool::getSupportedServiceNames()
232 return {
"com.sun.star.logging.LoggerPool" };
235 Reference< XLogger > SAL_CALL LoggerPool::getNamedLogger(
const OUString& _rName )
237 ::osl::MutexGuard aGuard(
m_aMutex );
239 WeakReference< XLogger >& rLogger(
m_aLoggerMap[ _rName ] );
240 Reference< XLogger > xLogger( rLogger );
244 xLogger =
new EventLogger(
m_xContext, _rName );
251 Reference< XLogger > SAL_CALL LoggerPool::getDefaultLogger( )
253 return getNamedLogger(
"org.openoffice.logging.DefaultLogger" );
258extern "C" SAL_DLLPUBLIC_EXPORT css::uno::XInterface *
260 css::uno::XComponentContext *context,
261 css::uno::Sequence<css::uno::Any>
const &)
263 return cppu::acquire(
new logging::LoggerPool(context));
void forEach(FuncT const &func)
sal_Int32 getLength() const
sal_Int32 removeInterface(const css::uno::Reference< css::uno::XInterface > &rxIFace)
sal_Int32 addInterface(const css::uno::Reference< css::uno::XInterface > &rxIFace)
oslInterlockedCount m_nEventNumber
comphelper::OInterfaceContainerHelper2 m_aHandlers
Reference< XComponentContext > m_xContext
SAL_DLLPUBLIC_EXPORT css::uno::XInterface * com_sun_star_comp_extensions_LoggerPool(css::uno::XComponentContext *context, css::uno::Sequence< css::uno::Any > const &)
std::map< OUString, WeakReference< XLogger > > m_aLoggerMap
css::uno::Sequence< OUString > getSupportedServiceNames()
OUString getImplementationName()
bool CPPUHELPER_DLLPUBLIC supportsService(css::lang::XServiceInfo *implementation, rtl::OUString const &name)
LogRecord createLogRecord(const OUString &_rLoggerName, const OUString &_rClassName, const OUString &_rMethodName, const OUString &_rMessage, sal_Int32 _nLogLevel, oslInterlockedCount _nEventNumber)
void initializeLoggerFromConfiguration(const Reference< XComponentContext > &_rContext, const Reference< XLogger > &_rxLogger)