diff options
author | Samuel Mehrbrodt <Samuel.Mehrbrodt@cib.de> | 2018-10-26 14:46:47 +0200 |
---|---|---|
committer | Samuel Mehrbrodt <Samuel.Mehrbrodt@cib.de> | 2018-10-26 16:50:40 +0200 |
commit | ad9d295c13d4c176643a26898f1b697b2a406ee7 (patch) | |
tree | cbf55f76394cdb83d77ee412c63ddf53752aefac | |
parent | 40c4c0f17ad5871861b64014fc7f8ae04d3f8971 (diff) |
unopkg: Log deployment output with the same logger as unopkg
This prevents overwriting the existing logfile by
using the same logger as unopkg does.
Reviewed-on: https://gerrit.libreoffice.org/62393
Tested-by: Jenkins
Reviewed-by: Samuel Mehrbrodt <Samuel.Mehrbrodt@cib.de>
(cherry picked from commit 5bd0212b54ea8c98fe401e8b1ad6d0b626a4b7e1)
Change-Id: Iaad4c5b99a4f428d3a4ad8a046c88404aecb5652
-rw-r--r-- | desktop/source/deployment/dp_log.cxx | 90 |
1 files changed, 11 insertions, 79 deletions
diff --git a/desktop/source/deployment/dp_log.cxx b/desktop/source/deployment/dp_log.cxx index a11b0d9560e8..8e89dfc8f25a 100644 --- a/desktop/source/deployment/dp_log.cxx +++ b/desktop/source/deployment/dp_log.cxx @@ -26,7 +26,9 @@ #include <comphelper/anytostring.hxx> #include <comphelper/servicedecl.hxx> #include <comphelper/unwrapargs.hxx> +#include <comphelper/logging.hxx> #include <com/sun/star/deployment/DeploymentException.hpp> +#include <com/sun/star/logging/LogLevel.hpp> #include <com/sun/star/ucb/XProgressHandler.hpp> #include <com/sun/star/ucb/SimpleFileAccess.hpp> #include <com/sun/star/io/XSeekable.hpp> @@ -35,6 +37,7 @@ using namespace ::com::sun::star; using namespace ::com::sun::star::uno; +using namespace ::com::sun::star::logging; namespace dp_log { @@ -44,8 +47,7 @@ typedef ::cppu::WeakComponentImplHelper<ucb::XProgressHandler> t_log_helper; class ProgressLogImpl : public ::dp_misc::MutexHolder, public t_log_helper { Reference<io::XOutputStream> m_xLogFile; - sal_Int32 m_log_level; - void log_write( OString const & text ); + std::unique_ptr<comphelper::EventLogger> m_logger; protected: virtual void SAL_CALL disposing() override; @@ -69,77 +71,16 @@ ProgressLogImpl::~ProgressLogImpl() void ProgressLogImpl::disposing() { - try { - if (m_xLogFile.is()) { - m_xLogFile->closeOutput(); - m_xLogFile.clear(); - } - } - catch (const Exception & exc) { - (void) exc; - OSL_FAIL( OUStringToOString( - exc.Message, RTL_TEXTENCODING_UTF8 ).getStr() ); - } } ProgressLogImpl::ProgressLogImpl( - Sequence<Any> const & args, + Sequence<Any> const & /* args */, Reference<XComponentContext> const & xContext ) - : t_log_helper( getMutex() ), - m_log_level( 0 ) -{ - OUString log_file; - boost::optional< Reference<task::XInteractionHandler> > interactionHandler; - comphelper::unwrapArgs( args, log_file, interactionHandler ); - - Reference<ucb::XSimpleFileAccess3> xSimpleFileAccess( ucb::SimpleFileAccess::create(xContext) ); - // optional ia handler: - if (interactionHandler) - xSimpleFileAccess->setInteractionHandler( *interactionHandler ); - - m_xLogFile.set( - xSimpleFileAccess->openFileWrite( log_file ), UNO_QUERY_THROW ); - Reference<io::XSeekable> xSeekable( m_xLogFile, UNO_QUERY_THROW ); - xSeekable->seek( xSeekable->getLength() ); - - // write log stamp - OStringBuffer buf; - buf.append( "###### Progress log entry " ); - TimeValue aStartTime, tLocal; - oslDateTime date_time; - if (osl_getSystemTime( &aStartTime ) && - osl_getLocalTimeFromSystemTime( &aStartTime, &tLocal ) && - osl_getDateTimeFromTimeValue( &tLocal, &date_time )) - { - char ar[ 128 ]; - snprintf( - ar, sizeof (ar), - "%04d-%02d-%02d %02d:%02d:%02d ", - date_time.Year, date_time.Month, date_time.Day, - date_time.Hours, date_time.Minutes, date_time.Seconds ); - buf.append( ar ); - } - buf.append( "######\n" ); - log_write( buf.makeStringAndClear() ); -} - - -void ProgressLogImpl::log_write( OString const & text ) + : t_log_helper( getMutex() ) { - try { - if (m_xLogFile.is()) { - m_xLogFile->writeBytes( - Sequence< sal_Int8 >( - reinterpret_cast< sal_Int8 const * >(text.getStr()), - text.getLength() ) ); - } - } - catch (const io::IOException & exc) { - (void) exc; - OSL_FAIL( OUStringToOString( - exc.Message, RTL_TEXTENCODING_UTF8 ).getStr() ); - } + // Use the logger created by unopkg app + m_logger.reset(new comphelper::EventLogger(xContext, "unopkg")); } // XProgressHandler @@ -148,11 +89,8 @@ void ProgressLogImpl::push( Any const & Status ) throw (RuntimeException, std::exception) { update( Status ); - OSL_ASSERT( m_log_level >= 0 ); - ++m_log_level; } - void ProgressLogImpl::update( Any const & Status ) throw (RuntimeException, std::exception) { @@ -160,28 +98,22 @@ void ProgressLogImpl::update( Any const & Status ) return; OUStringBuffer buf; - OSL_ASSERT( m_log_level >= 0 ); - for ( sal_Int32 n = 0; n < m_log_level; ++n ) - buf.append( ' ' ); OUString msg; + sal_Int32 logLevel = LogLevel::INFO; if (Status >>= msg) { buf.append( msg ); } else { - buf.append( "ERROR: " ); + logLevel = LogLevel::SEVERE; buf.append( ::comphelper::anyToString(Status) ); } - buf.append( "\n" ); - log_write( OUStringToOString( - buf.makeStringAndClear(), osl_getThreadTextEncoding() ) ); + m_logger->log(logLevel, buf.makeStringAndClear()); } void ProgressLogImpl::pop() throw (RuntimeException, std::exception) { - OSL_ASSERT( m_log_level > 0 ); - --m_log_level; } namespace sdecl = comphelper::service_decl; |