22#include <com/sun/star/logging/XLogFormatter.hpp>
23#include <com/sun/star/uno/XComponentContext.hpp>
24#include <com/sun/star/lang/XServiceInfo.hpp>
29#include <rtl/ustrbuf.hxx>
30#include <osl/thread.h>
36 using ::com::sun::star::uno::XComponentContext;
37 using ::com::sun::star::uno::Sequence;
38 using ::com::sun::star::logging::LogRecord;
39 using ::com::sun::star::uno::XInterface;
43 class PlainTextFormatter :
public cppu::WeakImplHelper<css::logging::XLogFormatter, css::lang::XServiceInfo>
50 virtual OUString SAL_CALL getHead( )
override;
51 virtual OUString SAL_CALL format(
const LogRecord& Record )
override;
52 virtual OUString SAL_CALL getTail( )
override;
62 PlainTextFormatter::PlainTextFormatter()
66 OUString SAL_CALL PlainTextFormatter::getHead( )
77 "(class/method:) message"
82 OUString SAL_CALL PlainTextFormatter::format(
const LogRecord& _rRecord )
84 char buffer[
sizeof(
"-32768-65535-65535 65535:65535:65535.4294967295") ];
86 const int buffer_size =
sizeof( buffer );
87 int used = snprintf( buffer, buffer_size,
"%10i",
static_cast<int>(_rRecord.SequenceNumber) );
88 if ( used >= buffer_size || used < 0 )
89 buffer[ buffer_size - 1 ] = 0;
91 OUStringBuffer aLogEntry;
92 aLogEntry.appendAscii( buffer );
93 aLogEntry.append(
" " );
95 OString sThreadID(
OUStringToOString( _rRecord.ThreadID, osl_getThreadTextEncoding() ) );
96 snprintf( buffer, buffer_size,
"%8s", sThreadID.getStr() );
97 aLogEntry.appendAscii( buffer );
98 aLogEntry.append(
" " );
100 snprintf( buffer, buffer_size,
"%04" SAL_PRIdINT32
"-%02" SAL_PRIuUINT32
"-%02" SAL_PRIuUINT32
" %02" SAL_PRIuUINT32
":%02" SAL_PRIuUINT32
":%02" SAL_PRIuUINT32
".%09" SAL_PRIuUINT32,
101 static_cast<sal_Int32
>(_rRecord.LogTime.Year),
static_cast<sal_uInt32
>(_rRecord.LogTime.Month),
static_cast<sal_uInt32
>(_rRecord.LogTime.Day),
102 static_cast<sal_uInt32
>(_rRecord.LogTime.Hours),
static_cast<sal_uInt32
>(_rRecord.LogTime.Minutes),
static_cast<sal_uInt32
>(_rRecord.LogTime.Seconds), _rRecord.LogTime.NanoSeconds );
103 aLogEntry.appendAscii( buffer );
104 aLogEntry.append(
" " );
106 if ( !(_rRecord.SourceClassName.isEmpty() || _rRecord.SourceMethodName.isEmpty()) )
108 aLogEntry.append( _rRecord.SourceClassName +
"::"
109 + _rRecord.SourceMethodName +
": " );
112 aLogEntry.append( _rRecord.Message +
"\n" );
114 return aLogEntry.makeStringAndClear();
118 OUString SAL_CALL PlainTextFormatter::getTail( )
124 sal_Bool SAL_CALL PlainTextFormatter::supportsService(
const OUString& _rServiceName )
130 OUString SAL_CALL PlainTextFormatter::getImplementationName()
132 return "com.sun.star.comp.extensions.PlainTextFormatter";
135 Sequence< OUString > SAL_CALL PlainTextFormatter::getSupportedServiceNames()
137 return {
"com.sun.star.logging.PlainTextFormatter" };
142extern "C" SAL_DLLPUBLIC_EXPORT css::uno::XInterface *
144 css::uno::XComponentContext *,
145 css::uno::Sequence<css::uno::Any>
const &)
147 return cppu::acquire(
new logging::PlainTextFormatter());
css::uno::Sequence< OUString > getSupportedServiceNames()
OUString getImplementationName()
bool CPPUHELPER_DLLPUBLIC supportsService(css::lang::XServiceInfo *implementation, rtl::OUString const &name)
OString OUStringToOString(std::u16string_view str, ConnectionSettings const *settings)
SAL_DLLPUBLIC_EXPORT css::uno::XInterface * com_sun_star_comp_extensions_PlainTextFormatter(css::uno::XComponentContext *, css::uno::Sequence< css::uno::Any > const &)