From 015e9f780bc133788f79868bb7fb0b1d4e81f5f3 Mon Sep 17 00:00:00 2001 From: Samuel Mehrbrodt Date: Fri, 10 Jan 2020 07:12:28 +0100 Subject: unopkg: Correctly display log messages on Windows Change-Id: I5ec8c55f9afac8d6f7f697c0e5e387e88db4fde7 Reviewed-on: https://gerrit.libreoffice.org/c/core/+/86517 Tested-by: Jenkins Reviewed-by: Mike Kaganski Reviewed-by: Samuel Mehrbrodt --- extensions/source/logging/consolehandler.cxx | 39 +++++++++++++++++++++++++--- 1 file changed, 36 insertions(+), 3 deletions(-) (limited to 'extensions/source/logging/consolehandler.cxx') diff --git a/extensions/source/logging/consolehandler.cxx b/extensions/source/logging/consolehandler.cxx index d1455baa3178..d213f5aab002 100644 --- a/extensions/source/logging/consolehandler.cxx +++ b/extensions/source/logging/consolehandler.cxx @@ -31,9 +31,15 @@ #include #include #include +#include #include +#ifdef _WIN32 +#include +#include +#endif + namespace logging { using ::com::sun::star::logging::XConsoleHandler; @@ -215,10 +221,38 @@ namespace logging void SAL_CALL ConsoleHandler::flush( ) { MethodGuard aGuard( *this ); +#ifndef _WIN32 fflush( stdout ); fflush( stderr ); +#endif + } + + namespace + { + void lcl_printConsole(const OString& sText) + { +#ifdef _WIN32 + DWORD nWrittenChars = 0; + OUString s = OStringToOUString(sText, RTL_TEXTENCODING_ASCII_US); + WriteFile(GetStdHandle(STD_OUTPUT_HANDLE), s.getStr(), s.getLength() * 2, + &nWrittenChars, nullptr); +#else + fprintf(stdout, "%s\n", sText.getStr()); +#endif } + void lcl_printConsoleError(const OString& sText) + { +#ifdef _WIN32 + DWORD nWrittenChars = 0; + OUString s = OStringToOUString(sText, RTL_TEXTENCODING_ASCII_US); + WriteFile(GetStdHandle(STD_ERROR_HANDLE), s.getStr(), s.getLength() * 2, + &nWrittenChars, nullptr); +#else + fprintf(stderr, "%s\n", sText.getStr()); +#endif + } + } // namespace sal_Bool SAL_CALL ConsoleHandler::publish( const LogRecord& _rRecord ) { @@ -229,10 +263,9 @@ namespace logging return false; if ( _rRecord.Level >= m_nThreshold ) - fprintf( stderr, "%s\n", sEntry.getStr() ); + lcl_printConsoleError(sEntry); else - fprintf( stdout, "%s\n", sEntry.getStr() ); - + lcl_printConsole(sEntry); return true; } -- cgit