summaryrefslogtreecommitdiff
path: root/extensions
diff options
context:
space:
mode:
authorSamuel Mehrbrodt <Samuel.Mehrbrodt@cib.de>2018-10-25 21:09:01 +0200
committerSamuel Mehrbrodt <Samuel.Mehrbrodt@cib.de>2018-10-26 10:22:36 +0200
commite4583f1ce81fc76dbfe55bcfd86d63ffe3518e5b (patch)
treefc86401a3dc3306aff276d91976edd066c4bf0e2 /extensions
parente8d130e7c6b2ff2a941372f386ee46fe8a95f218 (diff)
Introduce SimpleTextFormatter and format unopkg output using it
This will write log messages as plain text (no timestamp and other stuff like PlainTextFormatter). Warnings and errors will be prefixed accordingly. Change-Id: Id82512d7dd3907a4c7cd69a963a375966189dc20 Reviewed-on: https://gerrit.libreoffice.org/62370 Tested-by: Jenkins Reviewed-by: Samuel Mehrbrodt <Samuel.Mehrbrodt@cib.de>
Diffstat (limited to 'extensions')
-rw-r--r--extensions/Library_log.mk1
-rw-r--r--extensions/source/logging/log.component4
-rw-r--r--extensions/source/logging/simpletextformatter.cxx103
3 files changed, 108 insertions, 0 deletions
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: */