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>
This commit is contained in:
parent
996f1b9b32
commit
015e9f780b
1 changed files with 36 additions and 3 deletions
|
@ -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;
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue