summaryrefslogtreecommitdiff
path: root/desktop/source/pkgchk/unopkg/unopkg_app.cxx
diff options
context:
space:
mode:
Diffstat (limited to 'desktop/source/pkgchk/unopkg/unopkg_app.cxx')
-rw-r--r--desktop/source/pkgchk/unopkg/unopkg_app.cxx94
1 files changed, 53 insertions, 41 deletions
diff --git a/desktop/source/pkgchk/unopkg/unopkg_app.cxx b/desktop/source/pkgchk/unopkg/unopkg_app.cxx
index fea990384e9c..ab812f48f269 100644
--- a/desktop/source/pkgchk/unopkg/unopkg_app.cxx
+++ b/desktop/source/pkgchk/unopkg/unopkg_app.cxx
@@ -34,12 +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/DeploymentException.hpp>
#include <com/sun/star/deployment/ExtensionManager.hpp>
#include <com/sun/star/deployment/ui/PackageManagerDialog.hpp>
#include <com/sun/star/lang/IllegalArgumentException.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/ucb/CommandAbortedException.hpp>
#include <com/sun/star/ucb/CommandFailedException.hpp>
#include <com/sun/star/ui/dialogs/XExecutableDialog.hpp>
@@ -53,8 +58,10 @@
using namespace ::com::sun::star;
+using namespace ::com::sun::star::logging;
using namespace ::com::sun::star::uno;
using namespace ::unopkg;
+
namespace {
struct ExtensionName
@@ -92,7 +99,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"
@@ -193,6 +200,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" );
@@ -287,6 +297,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)
@@ -301,10 +336,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)
@@ -312,10 +346,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;
}
@@ -342,9 +374,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 ) );
@@ -544,61 +573,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: " +
- (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;
}