23#include <com/sun/star/logging/LoggerPool.hpp>
26#include <osl/diagnose.h>
31 using ::com::sun::star::uno::Reference;
32 using ::com::sun::star::uno::XComponentContext;
33 using ::com::sun::star::logging::XLoggerPool;
34 using ::com::sun::star::logging::LoggerPool;
35 using ::com::sun::star::logging::XLogger;
36 using ::com::sun::star::uno::Exception;
45 EventLogger_Impl(
const Reference< XComponentContext >& _rxContext,
const OUString& _rLoggerName );
56 Reference< XLoggerPool > xPool( LoggerPool::get(
m_aContext ) );
57 if ( !_rLoggerName.isEmpty() )
58 m_xLogger = xPool->getNamedLogger( _rLoggerName );
65 "comphelper",
"EventLogger_Impl::impl_createLogger_nothrow: caught an exception!" );
81 return m_pImpl->getLogger()->isLoggable( _nLogLevel );
99 void lcl_replaceParameter( OUString& _inout_Message,
const char* _rPlaceHolder, std::u16string_view _rReplacement )
101 sal_Int32 nPlaceholderPosition = _inout_Message.indexOfAsciiL( _rPlaceHolder, strlen(_rPlaceHolder) );
102 OSL_ENSURE( nPlaceholderPosition >= 0,
"lcl_replaceParameter: placeholder not found!" );
103 if ( nPlaceholderPosition < 0 )
106 _inout_Message = _inout_Message.replaceAt( nPlaceholderPosition, strlen(_rPlaceHolder), _rReplacement );
112 const char* _pSourceClass,
const char* _pSourceMethod,
const OUString& _rMessage,
119 lcl_replaceParameter(
sMessage,
"$1$", *_rArgument1 );
122 lcl_replaceParameter(
sMessage,
"$2$", *_rArgument2 );
125 lcl_replaceParameter(
sMessage,
"$3$", *_rArgument3 );
128 lcl_replaceParameter(
sMessage,
"$4$", *_rArgument4 );
131 lcl_replaceParameter(
sMessage,
"$5$", *_rArgument5 );
134 lcl_replaceParameter(
sMessage,
"$6$", *_rArgument6 );
138 Reference< XLogger > xLogger(
m_pImpl->getLogger() );
139 OSL_PRECOND( xLogger.is(),
"EventLogger::impl_log: should never be called without a logger!" );
140 if ( _pSourceClass && _pSourceMethod )
144 OUString::createFromAscii( _pSourceClass ),
145 OUString::createFromAscii( _pSourceMethod ),
151 xLogger->log( _nLogLevel,
sMessage );
Reference< XLogger > m_xLogger
EventLogger_Impl(const Reference< XComponentContext > &_rxContext, const OUString &_rLoggerName)
Reference< XComponentContext > m_aContext
const Reference< XLogger > & getLogger() const
bool isLoggable(const sal_Int32 _nLogLevel) const
determines whether an event with the given level would be logged
std::shared_ptr< EventLogger_Impl > m_pImpl
const css::uno::Reference< css::logging::XLogger > & getLogger() const
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
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.
Reference< XComponentContext > m_aContext
#define TOOLS_WARN_EXCEPTION(area, stream)
Logs an message along with a nicely formatted version of the current exception.
::std::optional< OUString > OptionalString
std::shared_ptr< T > make_shared(Args &&... args)