summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--desktop/source/pkgchk/unopkg/unopkg_app.cxx13
-rw-r--r--extensions/Library_log.mk1
-rw-r--r--extensions/source/logging/log.component4
-rw-r--r--extensions/source/logging/simpletextformatter.cxx103
-rw-r--r--offapi/UnoApi_offapi.mk1
-rw-r--r--offapi/com/sun/star/logging/SimpleTextFormatter.idl49
6 files changed, 169 insertions, 2 deletions
diff --git a/desktop/source/pkgchk/unopkg/unopkg_app.cxx b/desktop/source/pkgchk/unopkg/unopkg_app.cxx
index ab812f48f269..22d6f66d0255 100644
--- a/desktop/source/pkgchk/unopkg/unopkg_app.cxx
+++ b/desktop/source/pkgchk/unopkg/unopkg_app.cxx
@@ -44,6 +44,7 @@
#include <com/sun/star/logging/ConsoleHandler.hpp>
#include <com/sun/star/logging/FileHandler.hpp>
#include <com/sun/star/logging/LogLevel.hpp>
+#include <com/sun/star/logging/SimpleTextFormatter.hpp>
#include <com/sun/star/logging/XLogger.hpp>
#include <com/sun/star/ucb/CommandAbortedException.hpp>
#include <com/sun/star/ucb/CommandFailedException.hpp>
@@ -300,16 +301,24 @@ extern "C" int unopkg_main()
xComponentContext = getUNO(
option_verbose, option_shared, subcmd_gui, xLocalComponentContext );
+ // Initialize logging. This will log errors to the console and
+ // also to file if the --log-file parameter was provided.
logger.reset(new comphelper::EventLogger(xComponentContext, "unopkg"));
const Reference<XLogger> xLogger(logger->getLogger());
xLogger->setLevel(LogLevel::WARNING);
- xConsoleHandler.set(css::logging::ConsoleHandler::create(xComponentContext));
+ Reference<XLogFormatter> xLogFormatter(SimpleTextFormatter::create(xComponentContext));
+ Sequence < beans::NamedValue > aSeq { { "Formatter", Any(xLogFormatter) } };
+
+ xConsoleHandler.set(ConsoleHandler::createWithSettings(xComponentContext, aSeq));
xLogger->addLogHandler(xConsoleHandler);
xConsoleHandler->setLevel(LogLevel::WARNING);
xLogger->setLevel(LogLevel::WARNING);
+
+
if (!logFile.isEmpty())
{
- xFileHandler.set(css::logging::FileHandler::create(xComponentContext, logFile));
+ Sequence < beans::NamedValue > aSeq2 { { "Formatter", Any(xLogFormatter) }, {"FileURL", Any(logFile)} };
+ xFileHandler.set(css::logging::FileHandler::createWithSettings(xComponentContext, aSeq2));
xFileHandler->setLevel(LogLevel::WARNING);
xLogger->addLogHandler(xFileHandler);
}
diff --git a/extensions/Library_log.mk b/extensions/Library_log.mk
index 69115fe8d58e..4db9012adaa1 100644
--- a/extensions/Library_log.mk
+++ b/extensions/Library_log.mk
@@ -26,6 +26,7 @@ $(eval $(call gb_Library_add_exception_objects,log,\
extensions/source/logging/loghandler \
extensions/source/logging/logrecord \
extensions/source/logging/plaintextformatter \
+ extensions/source/logging/simpletextformatter \
))
$(eval $(call gb_Library_use_libraries,log,\
diff --git a/extensions/source/logging/log.component b/extensions/source/logging/log.component
index 2bd7f651a622..d4bda58c6900 100644
--- a/extensions/source/logging/log.component
+++ b/extensions/source/logging/log.component
@@ -39,4 +39,8 @@
constructor="com_sun_star_comp_extensions_PlainTextFormatter">
<service name="com.sun.star.logging.PlainTextFormatter"/>
</implementation>
+ <implementation name="com.sun.star.comp.extensions.SimpleTextFormatter"
+ constructor="com_sun_star_comp_extensions_SimpleTextFormatter">
+ <service name="com.sun.star.logging.SimpleTextFormatter"/>
+ </implementation>
</component>
diff --git a/extensions/source/logging/simpletextformatter.cxx b/extensions/source/logging/simpletextformatter.cxx
new file mode 100644
index 000000000000..a5eb3deaf547
--- /dev/null
+++ b/extensions/source/logging/simpletextformatter.cxx
@@ -0,0 +1,103 @@
+/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
+/*
+ * This file is part of the LibreOffice project.
+ *
+ * This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
+ * file, You can obtain one at http://mozilla.org/MPL/2.0/.
+ *
+ * This file incorporates work covered by the following license notice:
+ *
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed
+ * with this work for additional information regarding copyright
+ * ownership. The ASF licenses this file to you under the Apache
+ * License, Version 2.0 (the "License"); you may not use this file
+ * except in compliance with the License. You may obtain a copy of
+ * the License at http://www.apache.org/licenses/LICENSE-2.0 .
+ */
+
+#include <sal/config.h>
+
+#include <com/sun/star/logging/XLogFormatter.hpp>
+#include <com/sun/star/logging/LogLevel.hpp>
+#include <com/sun/star/uno/XComponentContext.hpp>
+#include <com/sun/star/lang/XServiceInfo.hpp>
+
+#include <cppuhelper/implbase.hxx>
+#include <cppuhelper/supportsservice.hxx>
+
+#include <rtl/ustrbuf.hxx>
+#include <osl/thread.h>
+
+#include <stdio.h>
+
+namespace logging
+{
+using css::logging::LogRecord;
+using namespace css::uno;
+
+class SimpleTextFormatter
+ : public cppu::WeakImplHelper<css::logging::XLogFormatter, css::lang::XServiceInfo>
+{
+public:
+ SimpleTextFormatter();
+
+private:
+ // XLogFormatter
+ virtual OUString SAL_CALL getHead() override;
+ virtual OUString SAL_CALL format(const LogRecord& Record) override;
+ virtual OUString SAL_CALL getTail() override;
+
+ // XServiceInfo
+ virtual OUString SAL_CALL getImplementationName() override;
+ virtual sal_Bool SAL_CALL supportsService(const OUString& _rServiceName) override;
+ virtual Sequence<OUString> SAL_CALL getSupportedServiceNames() override;
+};
+
+SimpleTextFormatter::SimpleTextFormatter() {}
+
+OUString SAL_CALL SimpleTextFormatter::getHead() { return OUString(); }
+
+OUString SAL_CALL SimpleTextFormatter::format(const LogRecord& _rRecord)
+{
+ OUStringBuffer 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");
+
+ return aLogEntry.makeStringAndClear();
+}
+
+OUString SAL_CALL SimpleTextFormatter::getTail() { return OUString(); }
+
+sal_Bool SAL_CALL SimpleTextFormatter::supportsService(const OUString& _rServiceName)
+{
+ return cppu::supportsService(this, _rServiceName);
+}
+
+OUString SAL_CALL SimpleTextFormatter::getImplementationName()
+{
+ return OUString("com.sun.star.comp.extensions.SimpleTextFormatter");
+}
+
+Sequence<OUString> SAL_CALL SimpleTextFormatter::getSupportedServiceNames()
+{
+ return { "com.sun.star.logging.SimpleTextFormatter" };
+}
+
+} // namespace logging
+
+extern "C" SAL_DLLPUBLIC_EXPORT css::uno::XInterface*
+com_sun_star_comp_extensions_SimpleTextFormatter(css::uno::XComponentContext*,
+ css::uno::Sequence<css::uno::Any> const&)
+{
+ return cppu::acquire(new logging::SimpleTextFormatter());
+}
+
+/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/offapi/UnoApi_offapi.mk b/offapi/UnoApi_offapi.mk
index 54231555fbff..4b47111da786 100644
--- a/offapi/UnoApi_offapi.mk
+++ b/offapi/UnoApi_offapi.mk
@@ -254,6 +254,7 @@ $(eval $(call gb_UnoApi_add_idlfiles_nohdl,offapi,com/sun/star/logging,\
FileHandler \
LoggerPool \
PlainTextFormatter \
+ SimpleTextFormatter \
))
$(eval $(call gb_UnoApi_add_idlfiles_nohdl,offapi,com/sun/star/mail,\
MailMessage \
diff --git a/offapi/com/sun/star/logging/SimpleTextFormatter.idl b/offapi/com/sun/star/logging/SimpleTextFormatter.idl
new file mode 100644
index 000000000000..03aae22ef3f2
--- /dev/null
+++ b/offapi/com/sun/star/logging/SimpleTextFormatter.idl
@@ -0,0 +1,49 @@
+/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
+/*
+ * This file is part of the LibreOffice project.
+ *
+ * This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
+ * file, You can obtain one at http://mozilla.org/MPL/2.0/.
+ *
+ * This file incorporates work covered by the following license notice:
+ *
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed
+ * with this work for additional information regarding copyright
+ * ownership. The ASF licenses this file to you under the Apache
+ * License, Version 2.0 (the "License"); you may not use this file
+ * except in compliance with the License. You may obtain a copy of
+ * the License at http://www.apache.org/licenses/LICENSE-2.0 .
+ */
+
+#ifndef __com_sun_star_logging_SimpleTextFormatter_idl__
+#define __com_sun_star_logging_SimpleTextFormatter_idl__
+
+
+module com { module sun { module star { module logging {
+
+interface XLogFormatter;
+
+
+/** specifies a service which formats log records as single line plain text
+
+ <p>Every log record, as passed to XLogFormatter::format(), will
+ be formatted into a single text line, with just the log message being output.
+ If the loglevel is WARNING, or SEVERE, the line will be prefixed accordingly.</p>
+
+ @since LibreOffice 6.2
+ */
+service SimpleTextFormatter : XLogFormatter
+{
+ /// creates a SimpleTextFormatter instance
+ create();
+};
+
+
+}; }; }; };
+
+
+#endif
+
+/* vim:set shiftwidth=4 softtabstop=4 expandtab: */