From 0a239ec9e03188684d122dc18b61719a3c30d84e Mon Sep 17 00:00:00 2001 From: Klaus Kaempf Date: Wed, 8 Feb 2006 19:36:25 +0000 Subject: [PATCH] revert LogControl, it dumps core :-( --- zypp/base/LogControl.cc | 201 ---------------------------------- zypp/base/{LogControl.h => Logger.cc} | 83 ++++++-------- zypp/base/Makefile.am | 3 +- 3 files changed, 32 insertions(+), 255 deletions(-) delete mode 100644 zypp/base/LogControl.cc rename zypp/base/{LogControl.h => Logger.cc} (50%) diff --git a/zypp/base/LogControl.cc b/zypp/base/LogControl.cc deleted file mode 100644 index d47767a..0000000 --- a/zypp/base/LogControl.cc +++ /dev/null @@ -1,201 +0,0 @@ -/*---------------------------------------------------------------------\ -| ____ _ __ __ ___ | -| |__ / \ / / . \ . \ | -| / / \ V /| _/ _/ | -| / /__ | | | | | | | -| /_____||_| |_| |_| | -| | -\---------------------------------------------------------------------*/ -/** \file zypp/base/LogControl.cc - * -*/ -#include - -#include "zypp/base/Logger.h" -#include "zypp/base/LogControl.h" -#include "zypp/base/String.h" - -using std::endl; - -/////////////////////////////////////////////////////////////////// -namespace zypp -{ ///////////////////////////////////////////////////////////////// - /////////////////////////////////////////////////////////////////// - namespace base - { ///////////////////////////////////////////////////////////////// - /////////////////////////////////////////////////////////////////// - namespace logger - { ///////////////////////////////////////////////////////////////// - - /////////////////////////////////////////////////////////////////// - // - // CLASS NAME : LogControlImpl - // - /** LogControl implementation. */ - struct LogControlImpl - { - public: - const Pathname & logfile() const - { return _logfile; } - - /** \todo IMPEMENT it */ - void logfile( const Pathname & logfile_r ) - {} - - void excessive( bool onOff_r ) - { _excessive = onOff_r; } - - public: - /** Provide the stream to write (logger interface) */ - std::ostream & getStream( const char * group_r, - LogLevel level_r, - const char * file_r, - const char * func_r, - const int line_r ); - private: - /** Current output stream. */ - std::ostream & outStr() - { return *_outStrPtr; } - - /** Output stream for level XXX */ - std::ostream & fullStr() - { return _excessive ? outStr() : _no_stream; } - - private: - std::ostream _no_stream; - - /** must pont to the current outpot stream or _no_stream! */ - std::ostream *_outStrPtr; - - Pathname _logfile; - bool _excessive; - - private: - /** Singleton */ - LogControlImpl() - : _no_stream( 0 ) - , _outStrPtr( getenv("ZYPP_NOLOG") ? &_no_stream : &std::cerr ) - , _excessive( getenv("ZYPP_FULLLOG") ) - {} - - public: - /** Offer default Impl. */ - static shared_ptr instance() - { - static shared_ptr _instance( new LogControlImpl ); - return _instance; - } - }; - /////////////////////////////////////////////////////////////////// - - /** \relates LogControl::Impl Stream output */ - inline std::ostream & operator<<( std::ostream & str, const LogControlImpl & obj ) - { - return str << "LogControl::Impl"; - } - - /** That's what logger:: calls. */ - std::ostream & getStream( const char * group_r, - LogLevel level_r, - const char * file_r, - const char * func_r, - const int line_r ) - { - // forward to LogControlImpl singleton - static shared_ptr _logControl( LogControlImpl::instance() ); - return _logControl->getStream( group_r, level_r, file_r, func_r, line_r ); - } - - /////////////////////////////////////////////////////////////////// - // - // CLASS NAME : LogControlImpl - // - /////////////////////////////////////////////////////////////////// - - std::ostream & LogControlImpl::getStream( const char * group_r, - LogLevel level_r, - const char * file_r, - const char * func_r, - const int line_r ) - { - return (level_r != E_XXX ? outStr() : fullStr() ) - << str::form( "<%d> [%s] %s(%s):%d ", - level_r, group_r, - file_r, func_r, line_r ); - } - - ///////////////////////////////////////////////////////////////// - } // namespace logger - /////////////////////////////////////////////////////////////////// - - /////////////////////////////////////////////////////////////////// - // - // CLASS NAME : LogControl - // - /////////////////////////////////////////////////////////////////// - - /////////////////////////////////////////////////////////////////// - // - // METHOD NAME : LogControl::instance - // METHOD TYPE : LogControl - // - LogControl LogControl::instance() - { - return LogControl(); - } - - /////////////////////////////////////////////////////////////////// - // - // METHOD NAME : LogControl::LogControl - // METHOD TYPE : Ctor - // - LogControl::LogControl() - : _pimpl( Impl::instance() ) - {} - - /////////////////////////////////////////////////////////////////// - // - // METHOD NAME : LogControl::~LogControl - // METHOD TYPE : Dtor - // - LogControl::~LogControl() - {} - - /////////////////////////////////////////////////////////////////// - // - // Forward to implementation. - // - /////////////////////////////////////////////////////////////////// - - const Pathname & LogControl::logfile() const - { return _pimpl->logfile(); } - - void LogControl::logfile( const Pathname & logfile_r ) - { _pimpl->logfile( logfile_r ); } - - /////////////////////////////////////////////////////////////////// - // - // LogControl::TmpExcessive - // - /////////////////////////////////////////////////////////////////// - LogControl::TmpExcessive::TmpExcessive() - { logger::LogControlImpl::instance()->excessive( true ); } - LogControl::TmpExcessive::~TmpExcessive() - { logger::LogControlImpl::instance()->excessive( false ); } - - /****************************************************************** - ** - ** FUNCTION NAME : operator<< - ** FUNCTION TYPE : std::ostream & - */ - std::ostream & operator<<( std::ostream & str, const LogControl & obj ) - { - return str << *obj._pimpl; - } - - ///////////////////////////////////////////////////////////////// - } // namespace base - /////////////////////////////////////////////////////////////////// - ///////////////////////////////////////////////////////////////// -} // namespace zypp -/////////////////////////////////////////////////////////////////// diff --git a/zypp/base/LogControl.h b/zypp/base/Logger.cc similarity index 50% rename from zypp/base/LogControl.h rename to zypp/base/Logger.cc index f8d5895..9412c05 100644 --- a/zypp/base/LogControl.h +++ b/zypp/base/Logger.cc @@ -6,16 +6,17 @@ | /_____||_| |_| |_| | | | \---------------------------------------------------------------------*/ -/** \file zypp/base/LogControl.h +/** \file zypp/base/Logger.cc * */ -#ifndef ZYPP_BASE_LOGCONTROL_H -#define ZYPP_BASE_LOGCONTROL_H +#include -#include +#include -#include "zypp/base/PtrTypes.h" -#include "zypp/Pathname.h" +#include "zypp/base/Logger.h" +#include "zypp/base/String.h" + +using namespace std; /////////////////////////////////////////////////////////////////// namespace zypp @@ -24,64 +25,42 @@ namespace zypp namespace base { ///////////////////////////////////////////////////////////////// - namespace logger + namespace { - class LogControlImpl; + std::ostream & noStream() + { + static std::ostream no_stream( 0 ); + return no_stream; + } } /////////////////////////////////////////////////////////////////// - // - // CLASS NAME : LogControl - // - /** Maintain logfile related options. - * Singleton - */ - class LogControl - { - friend std::ostream & operator<<( std::ostream & str, const LogControl & obj ); - typedef logger::LogControlImpl Impl; - - public: - /** Singleton access. */ - static LogControl instance(); - /** Dtor */ - ~LogControl(); - - public: - /** Return path to the logfile. - * An emty pathname for std::err. - */ - const Pathname & logfile() const; - - /** Set path for the logfile. - * An emty pathname for std::err. - * \throw if \a logfile_r is not usable. - */ - void logfile( const Pathname & logfile_r ); + namespace logger + { ///////////////////////////////////////////////////////////////// - public: - /** Turn on excessive logging for the lifetime of this object.*/ - struct TmpExcessive + std::ostream & getStream( const char * group_r, + LogLevel level_r, + const char * file_r, + const char * func_r, + const int line_r ) { - TmpExcessive(); - ~TmpExcessive(); - }; + static std::ostream & outStr( getenv("ZYPP_NOLOG") ? noStream() + : std::cerr ); + static std::ostream & fullStr( getenv("ZYPP_FULLLOG") ? outStr + : noStream() ); + return (level_r != E_XXX ? outStr : fullStr ) + << str::form( "<%d> [%s] %s(%s):%d ", + level_r, group_r, + file_r, func_r, line_r ); + } - private: - /** Default ctor: Singleton*/ - LogControl(); - /** Pointer to implementation */ - RW_pointer _pimpl; - }; + ///////////////////////////////////////////////////////////////// + } // namespace logger /////////////////////////////////////////////////////////////////// - /** \relates LogControl Stream output */ - std::ostream & operator<<( std::ostream & str, const LogControl & obj ); - ///////////////////////////////////////////////////////////////// } // namespace base /////////////////////////////////////////////////////////////////// ///////////////////////////////////////////////////////////////// } // namespace zypp /////////////////////////////////////////////////////////////////// -#endif // ZYPP_BASE_LOGCONTROL_H diff --git a/zypp/base/Makefile.am b/zypp/base/Makefile.am index 91eb364..2577718 100644 --- a/zypp/base/Makefile.am +++ b/zypp/base/Makefile.am @@ -16,7 +16,6 @@ baseinclude_HEADERS = \ Functional.h \ Iterator.h \ Logger.h \ - LogControl.h \ \ Fd.h \ KindOf.h \ @@ -37,7 +36,7 @@ noinst_LTLIBRARIES = lib@PACKAGE@_base.la ## ################################################## lib@PACKAGE@_base_la_SOURCES = \ - LogControl.cc \ + Logger.cc \ Exception.cc \ Fd.cc \ Gettext.cc \ -- 2.7.4