From e4583f1ce81fc76dbfe55bcfd86d63ffe3518e5b Mon Sep 17 00:00:00 2001 From: Samuel Mehrbrodt Date: Thu, 25 Oct 2018 21:09:01 +0200 Subject: 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 --- desktop/source/pkgchk/unopkg/unopkg_app.cxx | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) (limited to 'desktop') 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 #include #include +#include #include #include #include @@ -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(logger->getLogger()); xLogger->setLevel(LogLevel::WARNING); - xConsoleHandler.set(css::logging::ConsoleHandler::create(xComponentContext)); + Reference 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); } -- cgit