23 #include <com/sun/star/logging/LoggerPool.hpp>
25 #include <osl/diagnose.h>
30 using ::com::sun::star::uno::Reference;
31 using ::com::sun::star::uno::XComponentContext;
32 using ::com::sun::star::logging::XLoggerPool;
33 using ::com::sun::star::logging::LoggerPool;
34 using ::com::sun::star::logging::XLogger;
35 using ::com::sun::star::uno::Exception;
46 bool isValid()
const {
return m_xLogger.is(); }
55 Reference< XLoggerPool > xPool( LoggerPool::get(
m_aContext ) );
56 if ( !_rLoggerName.isEmpty() )
57 m_xLogger = xPool->getNamedLogger( _rLoggerName );
63 OSL_FAIL(
"EventLogger_Impl::impl_createLogger_nothrow: caught an exception!" );
79 return m_pImpl->getLogger()->isLoggable( _nLogLevel );
83 OSL_FAIL(
"EventLogger::isLoggable: caught an exception!" );
97 void lcl_replaceParameter( OUString& _inout_Message,
const char* _rPlaceHolder,
const OUString& _rReplacement )
99 sal_Int32 nPlaceholderPosition = _inout_Message.indexOfAsciiL( _rPlaceHolder, strlen(_rPlaceHolder) );
100 OSL_ENSURE( nPlaceholderPosition >= 0,
"lcl_replaceParameter: placeholder not found!" );
101 if ( nPlaceholderPosition < 0 )
104 _inout_Message = _inout_Message.replaceAt( nPlaceholderPosition, strlen(_rPlaceHolder), _rReplacement );
110 const char* _pSourceClass,
const char* _pSourceMethod,
const OUString& _rMessage,
117 lcl_replaceParameter( sMessage,
"$1$", *_rArgument1 );
120 lcl_replaceParameter( sMessage,
"$2$", *_rArgument2 );
123 lcl_replaceParameter( sMessage,
"$3$", *_rArgument3 );
126 lcl_replaceParameter( sMessage,
"$4$", *_rArgument4 );
129 lcl_replaceParameter( sMessage,
"$5$", *_rArgument5 );
132 lcl_replaceParameter( sMessage,
"$6$", *_rArgument6 );
136 Reference< XLogger > xLogger(
m_pImpl->getLogger() );
137 OSL_PRECOND( xLogger.is(),
"EventLogger::impl_log: should never be called without a logger!" );
138 if ( _pSourceClass && _pSourceMethod )
142 OUString::createFromAscii( _pSourceClass ),
143 OUString::createFromAscii( _pSourceMethod ),
149 xLogger->log( _nLogLevel, sMessage );
154 OSL_FAIL(
"EventLogger::impl_log: caught an exception!" );
const css::uno::Reference< css::logging::XLogger > & getLogger() const
EventLogger(const css::uno::Reference< css::uno::XComponentContext > &_rxContext, const char *_pAsciiLoggerName)
creates an EventLogger instance working with a css.logging.XLogger instance given by ASCII name...
bool isLoggable(const sal_Int32 _nLogLevel) const
determines whether an event with the given level would be logged
std::shared_ptr< T > make_shared(Args &&...args)
std::shared_ptr< EventLogger_Impl > m_pImpl
::std::optional< OUString > OptionalString
void impl_log(const sal_Int32 _nLogLevel, const char *_pSourceClass, const char *_pSourceMethod, const OUString &_rMessage, const OptionalString &_rArgument1=OptionalString(), const OptionalString &_rArgument2=OptionalString(), const OptionalString &_rArgument3=OptionalString(), const OptionalString &_rArgument4=OptionalString(), const OptionalString &_rArgument5=OptionalString(), const OptionalString &_rArgument6=OptionalString()) const
Reference< XComponentContext > m_aContext
Reference< XLogger > m_xLogger
const Reference< XLogger > & getLogger() const
EventLogger_Impl(const Reference< XComponentContext > &_rxContext, const OUString &_rLoggerName)
Reference< XComponentContext > m_aContext