diff options
author | Samuel Mehrbrodt <Samuel.Mehrbrodt@cib.de> | 2020-01-10 07:12:28 +0100 |
---|---|---|
committer | Samuel Mehrbrodt <Samuel.Mehrbrodt@cib.de> | 2020-01-21 14:27:35 +0100 |
commit | 015e9f780bc133788f79868bb7fb0b1d4e81f5f3 (patch) | |
tree | 5bb95b81f456ac4145ad16a2387468600f465d5d /extensions | |
parent | 996f1b9b325dcccd7b0ebfcacb45a4ffb4cba58e (diff) |
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 <mike.kaganski@collabora.com>
Reviewed-by: Samuel Mehrbrodt <Samuel.Mehrbrodt@cib.de>
Diffstat (limited to 'extensions')
-rw-r--r-- | extensions/source/logging/consolehandler.cxx | 39 |
1 files changed, 36 insertions, 3 deletions
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 <cppuhelper/compbase.hxx> #include <cppuhelper/basemutex.hxx> #include <cppuhelper/supportsservice.hxx> +#include <osl/thread.hxx> #include <stdio.h> +#ifdef _WIN32 +#include <prewin.h> +#include <postwin.h> +#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; } |