[Libreoffice-commits] core.git: Branch 'feature/cib_contract136' - 4 commits - comphelper/source desktop/source extensions/Library_log.mk extensions/source include/comphelper offapi/com offapi/UnoApi_offapi.mk
Libreoffice Gerrit user
logerrit at kemper.freedesktop.org
Fri Oct 26 14:59:01 UTC 2018
comphelper/source/misc/logging.cxx | 5
desktop/source/deployment/dp_log.cxx | 90 ++---------------
desktop/source/pkgchk/unopkg/unopkg_app.cxx | 105 ++++++++++++--------
extensions/Library_log.mk | 1
extensions/source/logging/log.component | 4
extensions/source/logging/simpletextformatter.cxx | 103 +++++++++++++++++++
include/comphelper/logging.hxx | 12 ++
offapi/UnoApi_offapi.mk | 1
offapi/com/sun/star/logging/SimpleTextFormatter.idl | 49 +++++++++
9 files changed, 248 insertions(+), 122 deletions(-)
New commits:
commit ad9d295c13d4c176643a26898f1b697b2a406ee7
Author: Samuel Mehrbrodt <Samuel.Mehrbrodt at cib.de>
AuthorDate: Fri Oct 26 14:46:47 2018 +0200
Commit: Samuel Mehrbrodt <Samuel.Mehrbrodt at cib.de>
CommitDate: Fri Oct 26 16:50:40 2018 +0200
unopkg: Log deployment output with the same logger as unopkg
This prevents overwriting the existing logfile by
using the same logger as unopkg does.
Reviewed-on: https://gerrit.libreoffice.org/62393
Tested-by: Jenkins
Reviewed-by: Samuel Mehrbrodt <Samuel.Mehrbrodt at cib.de>
(cherry picked from commit 5bd0212b54ea8c98fe401e8b1ad6d0b626a4b7e1)
Change-Id: Iaad4c5b99a4f428d3a4ad8a046c88404aecb5652
diff --git a/desktop/source/deployment/dp_log.cxx b/desktop/source/deployment/dp_log.cxx
index a11b0d9560e8..8e89dfc8f25a 100644
--- a/desktop/source/deployment/dp_log.cxx
+++ b/desktop/source/deployment/dp_log.cxx
@@ -26,7 +26,9 @@
#include <comphelper/anytostring.hxx>
#include <comphelper/servicedecl.hxx>
#include <comphelper/unwrapargs.hxx>
+#include <comphelper/logging.hxx>
#include <com/sun/star/deployment/DeploymentException.hpp>
+#include <com/sun/star/logging/LogLevel.hpp>
#include <com/sun/star/ucb/XProgressHandler.hpp>
#include <com/sun/star/ucb/SimpleFileAccess.hpp>
#include <com/sun/star/io/XSeekable.hpp>
@@ -35,6 +37,7 @@
using namespace ::com::sun::star;
using namespace ::com::sun::star::uno;
+using namespace ::com::sun::star::logging;
namespace dp_log {
@@ -44,8 +47,7 @@ typedef ::cppu::WeakComponentImplHelper<ucb::XProgressHandler> t_log_helper;
class ProgressLogImpl : public ::dp_misc::MutexHolder, public t_log_helper
{
Reference<io::XOutputStream> m_xLogFile;
- sal_Int32 m_log_level;
- void log_write( OString const & text );
+ std::unique_ptr<comphelper::EventLogger> m_logger;
protected:
virtual void SAL_CALL disposing() override;
@@ -69,77 +71,16 @@ ProgressLogImpl::~ProgressLogImpl()
void ProgressLogImpl::disposing()
{
- try {
- if (m_xLogFile.is()) {
- m_xLogFile->closeOutput();
- m_xLogFile.clear();
- }
- }
- catch (const Exception & exc) {
- (void) exc;
- OSL_FAIL( OUStringToOString(
- exc.Message, RTL_TEXTENCODING_UTF8 ).getStr() );
- }
}
ProgressLogImpl::ProgressLogImpl(
- Sequence<Any> const & args,
+ Sequence<Any> const & /* args */,
Reference<XComponentContext> const & xContext )
- : t_log_helper( getMutex() ),
- m_log_level( 0 )
-{
- OUString log_file;
- boost::optional< Reference<task::XInteractionHandler> > interactionHandler;
- comphelper::unwrapArgs( args, log_file, interactionHandler );
-
- Reference<ucb::XSimpleFileAccess3> xSimpleFileAccess( ucb::SimpleFileAccess::create(xContext) );
- // optional ia handler:
- if (interactionHandler)
- xSimpleFileAccess->setInteractionHandler( *interactionHandler );
-
- m_xLogFile.set(
- xSimpleFileAccess->openFileWrite( log_file ), UNO_QUERY_THROW );
- Reference<io::XSeekable> xSeekable( m_xLogFile, UNO_QUERY_THROW );
- xSeekable->seek( xSeekable->getLength() );
-
- // write log stamp
- OStringBuffer buf;
- buf.append( "###### Progress log entry " );
- TimeValue aStartTime, tLocal;
- oslDateTime date_time;
- if (osl_getSystemTime( &aStartTime ) &&
- osl_getLocalTimeFromSystemTime( &aStartTime, &tLocal ) &&
- osl_getDateTimeFromTimeValue( &tLocal, &date_time ))
- {
- char ar[ 128 ];
- snprintf(
- ar, sizeof (ar),
- "%04d-%02d-%02d %02d:%02d:%02d ",
- date_time.Year, date_time.Month, date_time.Day,
- date_time.Hours, date_time.Minutes, date_time.Seconds );
- buf.append( ar );
- }
- buf.append( "######\n" );
- log_write( buf.makeStringAndClear() );
-}
-
-
-void ProgressLogImpl::log_write( OString const & text )
+ : t_log_helper( getMutex() )
{
- try {
- if (m_xLogFile.is()) {
- m_xLogFile->writeBytes(
- Sequence< sal_Int8 >(
- reinterpret_cast< sal_Int8 const * >(text.getStr()),
- text.getLength() ) );
- }
- }
- catch (const io::IOException & exc) {
- (void) exc;
- OSL_FAIL( OUStringToOString(
- exc.Message, RTL_TEXTENCODING_UTF8 ).getStr() );
- }
+ // Use the logger created by unopkg app
+ m_logger.reset(new comphelper::EventLogger(xContext, "unopkg"));
}
// XProgressHandler
@@ -148,11 +89,8 @@ void ProgressLogImpl::push( Any const & Status )
throw (RuntimeException, std::exception)
{
update( Status );
- OSL_ASSERT( m_log_level >= 0 );
- ++m_log_level;
}
-
void ProgressLogImpl::update( Any const & Status )
throw (RuntimeException, std::exception)
{
@@ -160,28 +98,22 @@ void ProgressLogImpl::update( Any const & Status )
return;
OUStringBuffer buf;
- OSL_ASSERT( m_log_level >= 0 );
- for ( sal_Int32 n = 0; n < m_log_level; ++n )
- buf.append( ' ' );
OUString msg;
+ sal_Int32 logLevel = LogLevel::INFO;
if (Status >>= msg) {
buf.append( msg );
}
else {
- buf.append( "ERROR: " );
+ logLevel = LogLevel::SEVERE;
buf.append( ::comphelper::anyToString(Status) );
}
- buf.append( "\n" );
- log_write( OUStringToOString(
- buf.makeStringAndClear(), osl_getThreadTextEncoding() ) );
+ m_logger->log(logLevel, buf.makeStringAndClear());
}
void ProgressLogImpl::pop() throw (RuntimeException, std::exception)
{
- OSL_ASSERT( m_log_level > 0 );
- --m_log_level;
}
namespace sdecl = comphelper::service_decl;
commit 40c4c0f17ad5871861b64014fc7f8ae04d3f8971
Author: Samuel Mehrbrodt <Samuel.Mehrbrodt at cib.de>
AuthorDate: Fri Oct 26 14:17:06 2018 +0200
Commit: Samuel Mehrbrodt <Samuel.Mehrbrodt at cib.de>
CommitDate: Fri Oct 26 16:48:43 2018 +0200
unopkg: Write to console when no UNO available
Change-Id: I159b7e85f53e33c5359cca83aa958387d888f6a2
Reviewed-on: https://gerrit.libreoffice.org/62391
Tested-by: Jenkins
Reviewed-by: Samuel Mehrbrodt <Samuel.Mehrbrodt at cib.de>
(cherry picked from commit d2a4fac09bc6d17b85fd34a3f0777ecc5e3bd286)
diff --git a/desktop/source/pkgchk/unopkg/unopkg_app.cxx b/desktop/source/pkgchk/unopkg/unopkg_app.cxx
index 864f22a882cc..d0661fe0c806 100644
--- a/desktop/source/pkgchk/unopkg/unopkg_app.cxx
+++ b/desktop/source/pkgchk/unopkg/unopkg_app.cxx
@@ -614,7 +614,8 @@ extern "C" int unopkg_main()
}
catch (const LockFileException & e)
{
- logger->log(LogLevel::SEVERE, "Exception occurred: $1$", e.Message);
+ // No logger since it requires UNO which we don't have here
+ dp_misc::writeConsoleError(e.Message + "\n");
bNoOtherErrorMsg = true;
}
catch (const css::uno::Exception & e ) {
commit f5b786e8749ce5622138f800ca620942e8921854
Author: Samuel Mehrbrodt <Samuel.Mehrbrodt at cib.de>
AuthorDate: Thu Oct 25 21:09:01 2018 +0200
Commit: Samuel Mehrbrodt <Samuel.Mehrbrodt at cib.de>
CommitDate: Fri Oct 26 10:33:38 2018 +0200
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.
Reviewed-on: https://gerrit.libreoffice.org/62370
Tested-by: Jenkins
Reviewed-by: Samuel Mehrbrodt <Samuel.Mehrbrodt at cib.de>
(cherry picked from commit e4583f1ce81fc76dbfe55bcfd86d63ffe3518e5b)
Change-Id: Id82512d7dd3907a4c7cd69a963a375966189dc20
diff --git a/desktop/source/pkgchk/unopkg/unopkg_app.cxx b/desktop/source/pkgchk/unopkg/unopkg_app.cxx
index b0ee3270fcd2..864f22a882cc 100644
--- a/desktop/source/pkgchk/unopkg/unopkg_app.cxx
+++ b/desktop/source/pkgchk/unopkg/unopkg_app.cxx
@@ -42,6 +42,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/ui/dialogs/XExecutableDialog.hpp>
#include <com/sun/star/ui/dialogs/XDialogClosedListener.hpp>
@@ -301,16 +302,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 99f8090db335..1026f342a2c3 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 ad793bdf6c93..fcb041a31cf4 100644
--- a/offapi/UnoApi_offapi.mk
+++ b/offapi/UnoApi_offapi.mk
@@ -248,6 +248,7 @@ $(eval $(call gb_UnoApi_add_idlfiles_nohdl,offapi,com/sun/star/logging,\
FileHandler \
LoggerPool \
PlainTextFormatter \
+ SimpleTextFormatter \
SimpleLogRing \
))
$(eval $(call gb_UnoApi_add_idlfiles_nohdl,offapi,com/sun/star/mail,\
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: */
commit 33fdf7bc8bfd32c3609dc12dc949602586b2d48c
Author: Samuel Mehrbrodt <Samuel.Mehrbrodt at cib.de>
AuthorDate: Thu Oct 25 20:18:04 2018 +0200
Commit: Samuel Mehrbrodt <Samuel.Mehrbrodt at cib.de>
CommitDate: Fri Oct 26 10:31:53 2018 +0200
Log unopkg errors to log file if requested
Before only the output generated by extension add/remove/... functions
were logged to file, but not the error messages of unopkg itself.
Reviewed-on: https://gerrit.libreoffice.org/62369
Tested-by: Jenkins
Reviewed-by: Samuel Mehrbrodt <Samuel.Mehrbrodt at cib.de>
(cherry picked from commit e8d130e7c6b2ff2a941372f386ee46fe8a95f218)
Change-Id: I4451aa51e2877ae48c453ee4791e36d970832567
diff --git a/comphelper/source/misc/logging.cxx b/comphelper/source/misc/logging.cxx
index 452d2a365132..75555bd3d8c0 100644
--- a/comphelper/source/misc/logging.cxx
+++ b/comphelper/source/misc/logging.cxx
@@ -113,6 +113,11 @@ namespace comphelper
return false;
}
+ const css::uno::Reference<css::logging::XLogger> EventLogger::getLogger()
+ {
+ return m_pImpl->getLogger();
+ }
+
namespace
{
diff --git a/desktop/source/pkgchk/unopkg/unopkg_app.cxx b/desktop/source/pkgchk/unopkg/unopkg_app.cxx
index 822a1b9c4276..b0ee3270fcd2 100644
--- a/desktop/source/pkgchk/unopkg/unopkg_app.cxx
+++ b/desktop/source/pkgchk/unopkg/unopkg_app.cxx
@@ -34,13 +34,17 @@
#include <cppuhelper/implbase.hxx>
#include <cppuhelper/exc_hlp.hxx>
#include <comphelper/anytostring.hxx>
+#include <comphelper/logging.hxx>
#include <comphelper/sequence.hxx>
#include <com/sun/star/deployment/ExtensionManager.hpp>
#include <com/sun/star/deployment/ui/PackageManagerDialog.hpp>
+#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/XLogger.hpp>
#include <com/sun/star/ui/dialogs/XExecutableDialog.hpp>
#include <com/sun/star/ui/dialogs/XDialogClosedListener.hpp>
-#include <com/sun/star/bridge/BridgeFactory.hpp>
#include <stdio.h>
#if defined(UNX)
#include <unistd.h>
@@ -49,8 +53,10 @@
using namespace ::com::sun::star;
+using namespace ::com::sun::star::logging;
using namespace ::com::sun::star::uno;
using namespace ::unopkg;
+
namespace {
struct ExtensionName
@@ -90,7 +96,7 @@ const char s_usingText [] =
"options:\n"
" -h, --help this help\n"
" -V, --version version information\n"
-" -v, --verbose verbose output to stdout\n"
+" -v, --verbose verbose output\n"
" -f, --force force overwriting existing extensions\n"
" -s, --suppress-license prevents showing the license\n"
" --log-file <file> custom log file; default: <cache-dir>/log.txt\n"
@@ -195,6 +201,9 @@ extern "C" int unopkg_main()
OUString repository;
OUString cmdArg;
::std::vector<OUString> cmdPackages;
+ Reference<XLogHandler> xFileHandler;
+ Reference<XLogHandler> xConsoleHandler;
+ std::unique_ptr<comphelper::EventLogger> logger;
OptionInfo const * info_shared = getOptionInfo(
s_option_infos, "shared" );
@@ -289,6 +298,31 @@ extern "C" int unopkg_main()
}
}
+ xComponentContext = getUNO(
+ option_verbose, option_shared, subcmd_gui, xLocalComponentContext );
+
+ logger.reset(new comphelper::EventLogger(xComponentContext, "unopkg"));
+ const Reference<XLogger> xLogger(logger->getLogger());
+ xLogger->setLevel(LogLevel::WARNING);
+ xConsoleHandler.set(css::logging::ConsoleHandler::create(xComponentContext));
+ xLogger->addLogHandler(xConsoleHandler);
+ xConsoleHandler->setLevel(LogLevel::WARNING);
+ xLogger->setLevel(LogLevel::WARNING);
+ if (!logFile.isEmpty())
+ {
+ xFileHandler.set(css::logging::FileHandler::create(xComponentContext, logFile));
+ xFileHandler->setLevel(LogLevel::WARNING);
+ xLogger->addLogHandler(xFileHandler);
+ }
+
+ if (option_verbose)
+ {
+ xLogger->setLevel(LogLevel::INFO);
+ xConsoleHandler->setLevel(LogLevel::INFO);
+ if (xFileHandler.is())
+ xFileHandler->setLevel(LogLevel::INFO);
+ }
+
if (repository.isEmpty())
{
if (option_shared)
@@ -303,10 +337,9 @@ extern "C" int unopkg_main()
if ( repository == "shared" ) {
option_shared = true;
}
- else if (option_shared) {
- dp_misc::writeConsoleError(
- "WARNING: explicit context given! Ignoring option " +
- toString( info_shared ) + "!\n" );
+ else if (option_shared)
+ {
+ logger->log(LogLevel::WARNING, "Explicit context given! Ignoring option '$1$'", toString(info_shared));
}
}
#if defined(UNX)
@@ -314,10 +347,8 @@ extern "C" int unopkg_main()
{
if ( !(option_shared || option_bundled || option_help) )
{
- dp_misc::writeConsoleError(
- "ERROR: cannot run " APP_NAME " as root without " +
- toString( info_shared ) + " or " + toString( info_bundled )
- + " option.\n");
+ logger->log(LogLevel::SEVERE, "Cannot run $1$ as root without $2$ or $3$ option.",
+ APP_NAME, toString(info_shared), toString(info_bundled));
return 1;
}
@@ -344,9 +375,6 @@ extern "C" int unopkg_main()
throw Exception("Could not delete " + extensionUnorc, nullptr);
}
- xComponentContext = getUNO(
- option_verbose, option_shared, subcmd_gui, xLocalComponentContext );
-
Reference<deployment::XExtensionManager> xExtensionManager(
deployment::ExtensionManager::get( xComponentContext ) );
@@ -550,61 +578,44 @@ extern "C" int unopkg_main()
}
else
{
- dp_misc::writeConsoleError(
- "\nERROR: unknown sub-command " +
- subCommand + "!\n Use " APP_NAME " " +
- toString(info_help) + " to print all options.\n");
+ logger->log(LogLevel::SEVERE,
+ "Unknown sub-command: '$1$'. Use $2$ $3$ to print all options.",
+ subCommand, APP_NAME, toString(info_help));
return 1;
}
- if (option_verbose)
- dp_misc::writeConsole("\n" APP_NAME " done.\n");
+ logger->log(LogLevel::INFO, "$1$ done.", APP_NAME);
//Force to release all bridges which connect us to the child processes
dp_misc::disposeBridges(xLocalComponentContext);
return 0;
}
catch (const ucb::CommandFailedException &e)
{
- dp_misc::writeConsoleError(e.Message + "\n");
+ logger->log(LogLevel::SEVERE, "Exception occurred: $1$", e.Message);
bNoOtherErrorMsg = true;
}
catch (const ucb::CommandAbortedException &)
{
- dp_misc::writeConsoleError("\n" APP_NAME " aborted!\n");
+ logger->log(LogLevel::SEVERE, "$1$ aborted.", APP_NAME);
}
catch (const deployment::DeploymentException & exc)
{
- OUString cause;
- if (option_verbose)
- {
- cause = ::comphelper::anyToString(exc.Cause);
- }
- else
- {
- css::uno::Exception e;
- if (exc.Cause >>= e)
- cause = e.Message;
- }
-
- dp_misc::writeConsoleError("\nERROR: " + exc.Message + "\n");
- if (!cause.isEmpty())
- dp_misc::writeConsoleError(" Cause: " + cause + "\n");
+ logger->log(LogLevel::SEVERE, "Exception occurred: $1$", exc.Message);
+ logger->log(LogLevel::INFO, " Cause: $1$", comphelper::anyToString(exc.Cause));
}
catch (const LockFileException & e)
{
- if (!subcmd_gui)
- dp_misc::writeConsoleError(e.Message + "\n");
+ logger->log(LogLevel::SEVERE, "Exception occurred: $1$", e.Message);
bNoOtherErrorMsg = true;
}
catch (const css::uno::Exception & e ) {
Any exc( ::cppu::getCaughtException() );
- dp_misc::writeConsoleError("\nERROR: " +
- OUString(option_verbose ? e.Message + "\nException details: \n" +
- ::comphelper::anyToString(exc) : e.Message) + "\n");
+ logger->log(LogLevel::SEVERE, "Exception occurred: $1$", e.Message);
+ logger->log(LogLevel::INFO, " Cause: $1$", comphelper::anyToString(exc));
}
if (!bNoOtherErrorMsg)
- dp_misc::writeConsoleError("\n" APP_NAME " failed.\n");
+ logger->log(LogLevel::SEVERE, "$1$ failed.", APP_NAME);
dp_misc::disposeBridges(xLocalComponentContext);
return 1;
}
diff --git a/include/comphelper/logging.hxx b/include/comphelper/logging.hxx
index ef17801aa9f1..0fd7641fb2b5 100644
--- a/include/comphelper/logging.hxx
+++ b/include/comphelper/logging.hxx
@@ -29,10 +29,11 @@
#include <boost/optional.hpp>
#include <memory>
+#include <com/sun/star/logging/XLogger.hpp>
+
namespace comphelper
{
-
//= string conversions, employed by the templatized log* members of
//= EventLogger
@@ -118,6 +119,15 @@ namespace comphelper
//- XLogger::log equivalents/wrappers
//- string messages
+ /// logs a given message, without any arguments, or source class/method names
+ void log( const sal_Int32 _nLogLevel, const OUString& rMessage ) const
+ {
+ if ( isLoggable( _nLogLevel ) )
+ impl_log(_nLogLevel, nullptr, nullptr, rMessage);
+ }
+
+ const css::uno::Reference<css::logging::XLogger> getLogger();
+
/** logs a given message, replacing a placeholder in the message with an argument
The function takes, additionally to the log level and the message, an arbitrary
More information about the Libreoffice-commits
mailing list