#include <iostream>
#include <sstream>
#include "zypp/base/Logger.h"
-#include "zypp/base/PtrTypes.h"
-#include "zypp/ResObject.h"
+//#include "zypp/base/PtrTypes.h"
+//#include "zypp/ResObject.h"
///////////////////////////////////////////////////////////////////
namespace zypp
struct TraceCADBase
{
enum What { CTOR, COPYCTOR, ASSIGN, DTOR, PING };
+ std::string _ident;
};
/** \relates TraceCADBase Stream output. */
inline std::ostream & operator<<( std::ostream & str, const TraceCADBase & obj )
- { return str << "TraceCAD[" << &obj << "] "; }
+ { return str << obj._ident << "[" << &obj << "] "; }
/** \relates TraceCADBase Stream output of TraceCADBase::What. */
inline std::ostream & operator<<( std::ostream & str, TraceCADBase::What obj )
struct TraceCAD : public TraceCADBase
{
TraceCAD()
- { traceCAD( CTOR, *this, *this ); }
+ { _ident = __PRETTY_FUNCTION__;
+ traceCAD( CTOR, *this, *this ); }
TraceCAD( const TraceCAD & rhs )
{ traceCAD( COPYCTOR, *this, rhs ); }
case TraceCADBase::CTOR:
case TraceCADBase::DTOR:
case TraceCADBase::PING:
- INT << self_r << what_r << std::endl;
+ std::cerr << self_r << what_r << std::endl;
break;
case TraceCADBase::COPYCTOR:
case TraceCADBase::ASSIGN:
- INT << self_r << what_r << "( " << rhs_r << ")" << std::endl;
+ std::cerr << self_r << what_r << "( " << rhs_r << ")" << std::endl;
break;
}
}
//@}
///////////////////////////////////////////////////////////////////
-
+#if 0
///////////////////////////////////////////////////////////////////
/** \defgroup DBG_FAKED_RESOLVABLES Faked Resolvables
* \ingroup DEBUG
}
//@}
///////////////////////////////////////////////////////////////////
-
+#endif
/////////////////////////////////////////////////////////////////
} // namespace debug
///////////////////////////////////////////////////////////////////
--- /dev/null
+/*---------------------------------------------------------------------\
+| ____ _ __ __ ___ |
+| |__ / \ / / . \ . \ |
+| / / \ V /| _/ _/ |
+| / /__ | | | | | | |
+| /_____||_| |_| |_| |
+| |
+\---------------------------------------------------------------------*/
+/** \file zypp/base/LogControl.cc
+ *
+*/
+#include <iostream>
+
+#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 (Singleton). */
+ 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:
+ /** The LogControlImpl singleton
+ * \note As most dtors log, it is inportant that the
+ * LogControlImpl instance is the last static variable
+ * destructed. At least destucted after all statics
+ * which log from their dtor.
+ */
+ static LogControlImpl instance;
+ };
+ ///////////////////////////////////////////////////////////////////
+
+ // 'THE' LogControlImpl singleton
+ LogControlImpl LogControlImpl::instance;
+
+ ///////////////////////////////////////////////////////////////////
+
+ /** \relates LogControl::Impl Stream output */
+ inline std::ostream & operator<<( std::ostream & str, const LogControlImpl & obj )
+ {
+ return str << "LogControlImpl";
+ }
+
+ ///////////////////////////////////////////////////////////////////
+ //
+ // Access from logger::
+ //
+ ///////////////////////////////////////////////////////////////////
+
+ /** 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 )
+ {
+ return LogControlImpl::instance.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
+ // Forward to LogControlImpl singleton.
+ //
+ ///////////////////////////////////////////////////////////////////
+
+ using logger::LogControlImpl;
+
+ const Pathname & LogControl::logfile() const
+ { return LogControlImpl::instance.logfile(); }
+
+ void LogControl::logfile( const Pathname & logfile_r )
+ { LogControlImpl::instance.logfile( logfile_r ); }
+
+ ///////////////////////////////////////////////////////////////////
+ //
+ // LogControl::TmpExcessive
+ //
+ ///////////////////////////////////////////////////////////////////
+ LogControl::TmpExcessive::TmpExcessive()
+ { LogControlImpl::instance.excessive( true ); }
+ LogControl::TmpExcessive::~TmpExcessive()
+ { LogControlImpl::instance.excessive( false ); }
+
+ /******************************************************************
+ **
+ ** FUNCTION NAME : operator<<
+ ** FUNCTION TYPE : std::ostream &
+ */
+ std::ostream & operator<<( std::ostream & str, const LogControl & obj )
+ {
+ return str << LogControlImpl::instance;
+ }
+
+ /////////////////////////////////////////////////////////////////
+ } // namespace base
+ ///////////////////////////////////////////////////////////////////
+ /////////////////////////////////////////////////////////////////
+} // namespace zypp
+///////////////////////////////////////////////////////////////////
--- /dev/null
+/*---------------------------------------------------------------------\
+| ____ _ __ __ ___ |
+| |__ / \ / / . \ . \ |
+| / / \ V /| _/ _/ |
+| / /__ | | | | | | |
+| /_____||_| |_| |_| |
+| |
+\---------------------------------------------------------------------*/
+/** \file zypp/base/LogControl.h
+ *
+*/
+#ifndef ZYPP_BASE_LOGCONTROL_H
+#define ZYPP_BASE_LOGCONTROL_H
+
+#include <iosfwd>
+
+#include "zypp/base/PtrTypes.h"
+#include "zypp/Pathname.h"
+
+///////////////////////////////////////////////////////////////////
+namespace zypp
+{ /////////////////////////////////////////////////////////////////
+ ///////////////////////////////////////////////////////////////////
+ namespace base
+ { /////////////////////////////////////////////////////////////////
+
+ ///////////////////////////////////////////////////////////////////
+ //
+ // CLASS NAME : LogControl
+ //
+ /** Maintain logfile related options.
+ * \note A Singleton using a Singleton implementation class,
+ * that's why there is no _pimpl like in other classes.
+ */
+ class LogControl
+ {
+ friend std::ostream & operator<<( std::ostream & str, const LogControl & obj );
+
+ public:
+ /** Singleton access. */
+ static LogControl instance()
+ { return 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 );
+
+ public:
+ /** Turn on excessive logging for the lifetime of this object.*/
+ struct TmpExcessive
+ {
+ TmpExcessive();
+ ~TmpExcessive();
+ };
+
+ private:
+ /** Default ctor: Singleton */
+ LogControl()
+ {}
+ };
+ ///////////////////////////////////////////////////////////////////
+
+ /** \relates LogControl Stream output */
+ std::ostream & operator<<( std::ostream & str, const LogControl & obj );
+
+ /////////////////////////////////////////////////////////////////
+ } // namespace base
+ ///////////////////////////////////////////////////////////////////
+ /////////////////////////////////////////////////////////////////
+} // namespace zypp
+///////////////////////////////////////////////////////////////////
+#endif // ZYPP_BASE_LOGCONTROL_H