summaryrefslogtreecommitdiff
path: root/extensions/source/logging
diff options
context:
space:
mode:
Diffstat (limited to 'extensions/source/logging')
-rw-r--r--extensions/source/logging/csvformatter.cxx43
-rw-r--r--extensions/source/logging/filehandler.cxx4
-rw-r--r--extensions/source/logging/log.component3
-rw-r--r--extensions/source/logging/logger.cxx29
-rw-r--r--extensions/source/logging/loggerconfig.cxx22
-rw-r--r--extensions/source/logging/loggerconfig.hxx5
-rw-r--r--extensions/source/logging/loghandler.cxx3
-rw-r--r--extensions/source/logging/loghandler.hxx5
-rw-r--r--extensions/source/logging/logrecord.hxx5
-rw-r--r--extensions/source/logging/methodguard.hxx5
-rw-r--r--extensions/source/logging/plaintextformatter.cxx9
-rw-r--r--extensions/source/logging/simpletextformatter.cxx15
12 files changed, 50 insertions, 98 deletions
diff --git a/extensions/source/logging/csvformatter.cxx b/extensions/source/logging/csvformatter.cxx
index 0d0ec6479c5e..a9ea13f208ca 100644
--- a/extensions/source/logging/csvformatter.cxx
+++ b/extensions/source/logging/csvformatter.cxx
@@ -28,6 +28,8 @@
#include <cppuhelper/supportsservice.hxx>
#include <rtl/ustrbuf.hxx>
+#include <sal/macros.h>
+#include <sal/types.h>
#include <stdio.h>
#include <string_view>
@@ -88,32 +90,34 @@ namespace
{
const sal_Unicode quote_char = '"';
const sal_Unicode comma_char = ',';
- constexpr OUStringLiteral dos_newline = u"\r\n";
+ constexpr OUString dos_newline = u"\r\n"_ustr;
bool needsQuoting(std::u16string_view str)
{
return str.find_first_of(u"\",\n\r") != std::u16string_view::npos;
};
- void appendEncodedString(OUStringBuffer& buf, const OUString& str)
+ void appendEncodedString(OUStringBuffer& buf, std::u16string_view str)
{
if(needsQuoting(str))
{
// each double-quote will get replaced by two double-quotes
buf.append(quote_char);
const sal_Int32 buf_offset = buf.getLength();
- const sal_Int32 str_length = str.getLength();
+ const size_t str_length = str.size();
buf.append(str);
// special treatment for the last character
if(quote_char==str[str_length-1])
buf.append(quote_char);
// iterating backwards because the index at which we insert won't be shifted
// when moving that way.
- for(sal_Int32 i = str_length; i>=0; )
+ for(size_t i = str_length;; )
{
- i=str.lastIndexOf(quote_char, --i);
- if(i!=-1)
- buf.insert(buf_offset + i, quote_char);
+ --i;
+ i=str.substr(i).rfind(quote_char);
+ if(i==std::u16string_view::npos)
+ break;
+ buf.insert(buf_offset + i, quote_char);
}
buf.append(quote_char);
}
@@ -198,8 +202,7 @@ namespace logging
sal_Int32 columns = m_Columnnames.getLength();
for(sal_Int32 i=0; i<columns; i++)
{
- buf.append(m_Columnnames[i]);
- buf.append(comma_char);
+ buf.append(m_Columnnames[i] + OUStringChar(comma_char));
}
buf.setLength(buf.getLength()-1);
buf.append(dos_newline);
@@ -212,14 +215,12 @@ namespace logging
if(m_LogEventNo)
{
- aLogEntry.append( record.SequenceNumber );
- aLogEntry.append(comma_char);
+ aLogEntry.append(record.SequenceNumber + comma_char);
}
if(m_LogThread)
{
- aLogEntry.append( record.ThreadID );
- aLogEntry.append(comma_char);
+ aLogEntry.append(record.ThreadID + OUStringChar(comma_char));
}
if(m_LogTimestamp)
@@ -236,16 +237,16 @@ namespace logging
}
// ISO 8601
- char buffer[ 31 ];
+ char buffer[ SAL_N_ELEMENTS("-32768-65535-65535T65535:65535:65535.4294967295") ];
const size_t buffer_size = sizeof( buffer );
- snprintf( buffer, buffer_size, "%04i-%02i-%02iT%02i:%02i:%02i.%09i",
+ snprintf( buffer, buffer_size, "%04i-%02u-%02uT%02u:%02u:%02u.%09" SAL_PRIuUINT32,
static_cast<int>(record.LogTime.Year),
- static_cast<int>(record.LogTime.Month),
- static_cast<int>(record.LogTime.Day),
- static_cast<int>(record.LogTime.Hours),
- static_cast<int>(record.LogTime.Minutes),
- static_cast<int>(record.LogTime.Seconds),
- static_cast<int>(record.LogTime.NanoSeconds) );
+ static_cast<unsigned int>(record.LogTime.Month),
+ static_cast<unsigned int>(record.LogTime.Day),
+ static_cast<unsigned int>(record.LogTime.Hours),
+ static_cast<unsigned int>(record.LogTime.Minutes),
+ static_cast<unsigned int>(record.LogTime.Seconds),
+ record.LogTime.NanoSeconds );
aLogEntry.appendAscii( buffer );
aLogEntry.append(comma_char);
}
diff --git a/extensions/source/logging/filehandler.cxx b/extensions/source/logging/filehandler.cxx
index 222146b0b4d2..8108f7c6abf8 100644
--- a/extensions/source/logging/filehandler.cxx
+++ b/extensions/source/logging/filehandler.cxx
@@ -29,7 +29,7 @@
#include <com/sun/star/util/PathSubstitution.hpp>
#include <com/sun/star/util/XStringSubstitution.hpp>
-#include <tools/diagnose_ex.h>
+#include <comphelper/diagnose_ex.hxx>
#include <cppuhelper/compbase.hxx>
#include <cppuhelper/basemutex.hxx>
@@ -130,8 +130,6 @@ namespace logging
:FileHandler_Base( m_aMutex )
,m_xContext( context )
,m_aHandlerHelper( context, m_aMutex, rBHelper )
- ,m_sFileURL( )
- ,m_pFile( )
,m_eFileValidity( eUnknown )
{
::osl::MutexGuard aGuard( m_aMutex );
diff --git a/extensions/source/logging/log.component b/extensions/source/logging/log.component
index d4bda58c6900..ae221bb5768d 100644
--- a/extensions/source/logging/log.component
+++ b/extensions/source/logging/log.component
@@ -32,7 +32,8 @@
<service name="com.sun.star.logging.FileHandler"/>
</implementation>
<implementation name="com.sun.star.comp.extensions.LoggerPool"
- constructor="com_sun_star_comp_extensions_LoggerPool">
+ constructor="com_sun_star_comp_extensions_LoggerPool"
+ single-instance="true">
<singleton name="com.sun.star.logging.LoggerPool"/>
</implementation>
<implementation name="com.sun.star.comp.extensions.PlainTextFormatter"
diff --git a/extensions/source/logging/logger.cxx b/extensions/source/logging/logger.cxx
index 1770ca377175..4ae2f79362fc 100644
--- a/extensions/source/logging/logger.cxx
+++ b/extensions/source/logging/logger.cxx
@@ -32,8 +32,8 @@
#include <cppuhelper/implbase.hxx>
#include <cppuhelper/supportsservice.hxx>
#include <cppuhelper/weakref.hxx>
-#include <rtl/ref.hxx>
#include <map>
+#include <utility>
namespace logging
@@ -64,7 +64,7 @@ namespace logging
// </attributes>
public:
- EventLogger( const Reference< XComponentContext >& _rxContext, const OUString& _rName );
+ EventLogger( const Reference< XComponentContext >& _rxContext, OUString _aName );
// XLogger
virtual OUString SAL_CALL getName() override;
@@ -114,11 +114,11 @@ namespace logging
}
- EventLogger::EventLogger( const Reference< XComponentContext >& _rxContext, const OUString& _rName )
+ EventLogger::EventLogger( const Reference< XComponentContext >& _rxContext, OUString _aName )
:m_aHandlers( m_aMutex )
,m_nEventNumber( 0 )
,m_nLogLevel( css::logging::LogLevel::OFF )
- ,m_sName( _rName )
+ ,m_sName(std::move( _aName ))
{
osl_atomic_increment( &m_refCount );
{
@@ -255,31 +255,12 @@ namespace logging
} // namespace logging
-namespace {
-
-struct Instance {
- explicit Instance(
- css::uno::Reference<css::uno::XComponentContext> const & context):
- instance(static_cast<cppu::OWeakObject *>(new logging::LoggerPool(context)))
- {}
-
- rtl::Reference<css::uno::XInterface> instance;
-};
-
-struct Singleton:
- public rtl::StaticWithArg<
- Instance, css::uno::Reference<css::uno::XComponentContext>, Singleton>
-{};
-
-}
-
extern "C" SAL_DLLPUBLIC_EXPORT css::uno::XInterface *
com_sun_star_comp_extensions_LoggerPool(
css::uno::XComponentContext *context,
css::uno::Sequence<css::uno::Any> const &)
{
- return cppu::acquire(static_cast<cppu::OWeakObject *>(
- Singleton::get(context).instance.get()));
+ return cppu::acquire(new logging::LoggerPool(context));
}
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/extensions/source/logging/loggerconfig.cxx b/extensions/source/logging/loggerconfig.cxx
index 4fd183099544..daf42859b833 100644
--- a/extensions/source/logging/loggerconfig.cxx
+++ b/extensions/source/logging/loggerconfig.cxx
@@ -34,7 +34,7 @@
#include <com/sun/star/logging/XLogHandler.hpp>
#include <com/sun/star/logging/XLogFormatter.hpp>
-#include <tools/diagnose_ex.h>
+#include <comphelper/diagnose_ex.hxx>
#include <osl/process.h>
#include <cppuhelper/component_context.hxx>
@@ -54,7 +54,6 @@ namespace logging
using ::com::sun::star::lang::XSingleServiceFactory;
using ::com::sun::star::uno::XInterface;
using ::com::sun::star::util::XChangesBatch;
- using ::com::sun::star::uno::makeAny;
using ::com::sun::star::lang::NullPointerException;
using ::com::sun::star::uno::Exception;
using ::com::sun::star::lang::ServiceNotRegisteredException;
@@ -105,22 +104,19 @@ namespace logging
::sal::static_int_cast< sal_Int16 >( aDateTime.NanoSeconds / 10000000 ) );
OUString sTime = OUString::createFromAscii( buffer );
- OUString sDateTime = sDate + "." + sTime;
-
oslProcessIdentifier aProcessId = 0;
oslProcessInfo info;
info.Size = sizeof (oslProcessInfo);
if ( osl_getProcessInfo ( nullptr, osl_Process_IDENTIFIER, &info ) == osl_Process_E_None)
aProcessId = info.Ident;
- OUString aPID = OUString::number( aProcessId );
Variable const aVariables[] =
{
{std::u16string_view(u"$(loggername)"), sLoggerName},
{std::u16string_view(u"$(date)"), sDate},
{std::u16string_view(u"$(time)"), sTime},
- {std::u16string_view(u"$(datetime)"), sDateTime},
- {std::u16string_view(u"$(pid)"), aPID}
+ {std::u16string_view(u"$(datetime)"), sDate + "." + sTime },
+ {std::u16string_view(u"$(pid)"), OUString::number(aProcessId)}
};
for (Variable const & aVariable : aVariables)
@@ -191,8 +187,7 @@ namespace logging
bool bSuccess = false;
if ( aSettings.hasElements() )
{
- Sequence< Any > aConstructionArgs(1);
- aConstructionArgs[0] <<= aSettings;
+ Sequence< Any > aConstructionArgs{ Any(aSettings) };
xInstance = _rContext->getServiceManager()->createInstanceWithArgumentsAndContext(sServiceName, aConstructionArgs, _rContext);
bSuccess = xInstance.is();
}
@@ -222,11 +217,8 @@ namespace logging
css::configuration::theDefaultProvider::get(_rContext));
// write access to the "Settings" node (which includes settings for all loggers)
- Sequence< Any > aArguments(1);
- aArguments[0] <<= NamedValue(
- "nodepath",
- makeAny( OUString( "/org.openoffice.Office.Logging/Settings" ) )
- );
+ Sequence<Any> aArguments{ Any(NamedValue(
+ "nodepath", Any(OUString("/org.openoffice.Office.Logging/Settings")))) };
Reference< XNameContainer > xAllSettings( xConfigProvider->createInstanceWithArguments(
"com.sun.star.configuration.ConfigurationUpdateAccess",
aArguments
@@ -238,7 +230,7 @@ namespace logging
// no node yet for this logger. Create default settings.
Reference< XSingleServiceFactory > xNodeFactory( xAllSettings, UNO_QUERY_THROW );
Reference< XInterface > xLoggerSettings( xNodeFactory->createInstance(), css::uno::UNO_SET_THROW );
- xAllSettings->insertByName( sLoggerName, makeAny( xLoggerSettings ) );
+ xAllSettings->insertByName( sLoggerName, Any( xLoggerSettings ) );
Reference< XChangesBatch > xChanges( xAllSettings, UNO_QUERY_THROW );
xChanges->commitChanges();
}
diff --git a/extensions/source/logging/loggerconfig.hxx b/extensions/source/logging/loggerconfig.hxx
index bc603135da2c..b08628cf16c0 100644
--- a/extensions/source/logging/loggerconfig.hxx
+++ b/extensions/source/logging/loggerconfig.hxx
@@ -17,8 +17,7 @@
* the License at http://www.apache.org/licenses/LICENSE-2.0 .
*/
-#ifndef INCLUDED_EXTENSIONS_SOURCE_LOGGING_LOGGERCONFIG_HXX
-#define INCLUDED_EXTENSIONS_SOURCE_LOGGING_LOGGERCONFIG_HXX
+#pragma once
#include <com/sun/star/logging/XLogger.hpp>
#include <com/sun/star/uno/XComponentContext.hpp>
@@ -48,6 +47,4 @@ namespace logging
} // namespace logging
-#endif // INCLUDED_EXTENSIONS_SOURCE_LOGGING_LOGGERCONFIG_HXX
-
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/extensions/source/logging/loghandler.cxx b/extensions/source/logging/loghandler.cxx
index afc33605b9fc..a398bd053acd 100644
--- a/extensions/source/logging/loghandler.cxx
+++ b/extensions/source/logging/loghandler.cxx
@@ -25,7 +25,7 @@
#include <com/sun/star/lang/DisposedException.hpp>
#include <com/sun/star/logging/PlainTextFormatter.hpp>
-#include <tools/diagnose_ex.h>
+#include <comphelper/diagnose_ex.hxx>
#include <rtl/tencinfo.h>
@@ -36,7 +36,6 @@ namespace logging
using ::com::sun::star::uno::Reference;
using ::com::sun::star::uno::XComponentContext;
using ::com::sun::star::logging::LogRecord;
- using ::com::sun::star::uno::UNO_QUERY_THROW;
using ::com::sun::star::logging::XLogFormatter;
using ::com::sun::star::uno::Exception;
using ::com::sun::star::lang::IllegalArgumentException;
diff --git a/extensions/source/logging/loghandler.hxx b/extensions/source/logging/loghandler.hxx
index 1e0feaa06c7c..02f4fb773761 100644
--- a/extensions/source/logging/loghandler.hxx
+++ b/extensions/source/logging/loghandler.hxx
@@ -17,8 +17,7 @@
* the License at http://www.apache.org/licenses/LICENSE-2.0 .
*/
-#ifndef INCLUDED_EXTENSIONS_SOURCE_LOGGING_LOGHANDLER_HXX
-#define INCLUDED_EXTENSIONS_SOURCE_LOGGING_LOGHANDLER_HXX
+#pragma once
#include <sal/config.h>
@@ -140,6 +139,4 @@ namespace logging
} // namespace logging
-#endif // INCLUDED_EXTENSIONS_SOURCE_LOGGING_LOGHANDLER_HXX
-
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/extensions/source/logging/logrecord.hxx b/extensions/source/logging/logrecord.hxx
index eb192f80fb68..ad6e350cfbeb 100644
--- a/extensions/source/logging/logrecord.hxx
+++ b/extensions/source/logging/logrecord.hxx
@@ -17,8 +17,7 @@
* the License at http://www.apache.org/licenses/LICENSE-2.0 .
*/
-#ifndef INCLUDED_EXTENSIONS_SOURCE_LOGGING_LOGRECORD_HXX
-#define INCLUDED_EXTENSIONS_SOURCE_LOGGING_LOGRECORD_HXX
+#pragma once
#include <com/sun/star/logging/LogRecord.hpp>
@@ -51,6 +50,4 @@ namespace logging
} // namespace logging
-#endif // INCLUDED_EXTENSIONS_SOURCE_LOGGING_LOGRECORD_HXX
-
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/extensions/source/logging/methodguard.hxx b/extensions/source/logging/methodguard.hxx
index 167b3a379617..189462eae667 100644
--- a/extensions/source/logging/methodguard.hxx
+++ b/extensions/source/logging/methodguard.hxx
@@ -17,8 +17,7 @@
* the License at http://www.apache.org/licenses/LICENSE-2.0 .
*/
-#ifndef INCLUDED_EXTENSIONS_SOURCE_LOGGING_METHODGUARD_HXX
-#define INCLUDED_EXTENSIONS_SOURCE_LOGGING_METHODGUARD_HXX
+#pragma once
namespace logging
@@ -53,6 +52,4 @@ namespace logging
} // namespace logging
-#endif // INCLUDED_EXTENSIONS_SOURCE_LOGGING_METHODGUARD_HXX
-
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/extensions/source/logging/plaintextformatter.cxx b/extensions/source/logging/plaintextformatter.cxx
index 23392b61c491..2c534a2a2e8f 100644
--- a/extensions/source/logging/plaintextformatter.cxx
+++ b/extensions/source/logging/plaintextformatter.cxx
@@ -105,14 +105,11 @@ namespace logging
if ( !(_rRecord.SourceClassName.isEmpty() || _rRecord.SourceMethodName.isEmpty()) )
{
- aLogEntry.append( _rRecord.SourceClassName );
- aLogEntry.append( "::" );
- aLogEntry.append( _rRecord.SourceMethodName );
- aLogEntry.append( ": " );
+ aLogEntry.append( _rRecord.SourceClassName + "::"
+ + _rRecord.SourceMethodName + ": " );
}
- aLogEntry.append( _rRecord.Message );
- aLogEntry.append( "\n" );
+ aLogEntry.append( _rRecord.Message + "\n" );
return aLogEntry.makeStringAndClear();
}
diff --git a/extensions/source/logging/simpletextformatter.cxx b/extensions/source/logging/simpletextformatter.cxx
index 83416e61c7d6..b54fea5a645b 100644
--- a/extensions/source/logging/simpletextformatter.cxx
+++ b/extensions/source/logging/simpletextformatter.cxx
@@ -27,8 +27,6 @@
#include <cppuhelper/implbase.hxx>
#include <cppuhelper/supportsservice.hxx>
-#include <rtl/ustrbuf.hxx>
-
namespace logging
{
using css::logging::LogRecord;
@@ -61,17 +59,14 @@ OUString SAL_CALL SimpleTextFormatter::getHead() { return OUString(); }
OUString SAL_CALL SimpleTextFormatter::format(const LogRecord& _rRecord)
{
- OUStringBuffer aLogEntry;
+ OUString aLogEntry;
// Highlight warnings
if (_rRecord.Level == css::logging::LogLevel::SEVERE)
- aLogEntry.append("ERROR: ");
- if (_rRecord.Level == css::logging::LogLevel::WARNING)
- aLogEntry.append("WARNING: ");
-
- aLogEntry.append(_rRecord.Message);
- aLogEntry.append("\n");
+ aLogEntry = "ERROR: ";
+ else if (_rRecord.Level == css::logging::LogLevel::WARNING)
+ aLogEntry = "WARNING: ";
- return aLogEntry.makeStringAndClear();
+ return aLogEntry + _rRecord.Message + "\n";
}
OUString SAL_CALL SimpleTextFormatter::getTail() { return OUString(); }