- (re)enabled LogControl. The LogControlImpl singleton must be the first
authorMichael Andres <ma@suse.de>
Wed, 8 Feb 2006 23:27:49 +0000 (23:27 +0000)
committerMichael Andres <ma@suse.de>
Wed, 8 Feb 2006 23:27:49 +0000 (23:27 +0000)
  static being intialized and the last destructed.

zypp/Makefile.am
zypp/base/Debug.h
zypp/base/LogControl.cc [new file with mode: 0644]
zypp/base/LogControl.h [new file with mode: 0644]
zypp/base/Makefile.am

index 7594d14..4c2f36b 100644 (file)
@@ -145,8 +145,7 @@ lib@PACKAGE@_la_SOURCES = \
 
 lib@PACKAGE@_la_LDFLAGS =      @LIBZYPP_VERSION_INFO@
 
-lib@PACKAGE@_la_LIBADD =        base/lib@PACKAGE@_base.la      \
-                               thread/lib@PACKAGE@_thread.la   \
+lib@PACKAGE@_la_LIBADD =        thread/lib@PACKAGE@_thread.la  \
                                detail/lib@PACKAGE@_detail.la   \
                                capability/lib@PACKAGE@_capability.la   \
                                pool/lib@PACKAGE@_pool.la       \
@@ -159,7 +158,9 @@ lib@PACKAGE@_la_LIBADD =        base/lib@PACKAGE@_base.la   \
                                zypp_detail/lib@PACKAGE@_zypp_detail.la \
                                ui/lib@PACKAGE@_ui.la   \
                                \
+                               base/lib@PACKAGE@_base.la       \
                                -lutil
+# !!! base/lib@PACKAGE@_base.la MUST BE THE LAST zypp lib linked
 
 ## ##################################################
 
index eaccf45..cca201e 100644 (file)
@@ -17,8 +17,8 @@
 #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
@@ -43,11 +43,12 @@ 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 )
@@ -87,7 +88,8 @@ namespace zypp
       struct TraceCAD : public TraceCADBase
       {
         TraceCAD()
-        { traceCAD( CTOR, *this, *this ); }
+        { _ident = __PRETTY_FUNCTION__;
+          traceCAD( CTOR, *this, *this ); }
 
         TraceCAD( const TraceCAD & rhs )
         { traceCAD( COPYCTOR, *this, rhs ); }
@@ -115,17 +117,17 @@ namespace zypp
           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
@@ -184,7 +186,7 @@ namespace zypp
       }
     //@}
     ///////////////////////////////////////////////////////////////////
-
+#endif
     /////////////////////////////////////////////////////////////////
   } // namespace debug
   ///////////////////////////////////////////////////////////////////
diff --git a/zypp/base/LogControl.cc b/zypp/base/LogControl.cc
new file mode 100644 (file)
index 0000000..276d978
--- /dev/null
@@ -0,0 +1,185 @@
+/*---------------------------------------------------------------------\
+|                          ____ _   __ __ ___                          |
+|                         |__  / \ / / . \ . \                         |
+|                           / / \ 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
+///////////////////////////////////////////////////////////////////
diff --git a/zypp/base/LogControl.h b/zypp/base/LogControl.h
new file mode 100644 (file)
index 0000000..8b302fa
--- /dev/null
@@ -0,0 +1,80 @@
+/*---------------------------------------------------------------------\
+|                          ____ _   __ __ ___                          |
+|                         |__  / \ / / . \ . \                         |
+|                           / / \ 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
index 2577718..0a6d815 100644 (file)
@@ -16,6 +16,7 @@ baseinclude_HEADERS = \
        Functional.h    \
        Iterator.h      \
        Logger.h        \
+       LogControl.h    \
        \
        Fd.h            \
        KindOf.h        \
@@ -36,17 +37,18 @@ noinst_LTLIBRARIES =        lib@PACKAGE@_base.la
 ## ##################################################
 
 lib@PACKAGE@_base_la_SOURCES = \
-       Logger.cc       \
-       Exception.cc    \
-       Fd.cc           \
-       Gettext.cc      \
-       IOStream.cc     \
+       Fd.cc                   \
+       Gettext.cc              \
+       IOStream.cc             \
        ReferenceCounted.cc     \
-       String.cc       \
-       Unit.cc         \
-               \
-               \
-       ExternalDataSource.cc
+       String.cc               \
+       Unit.cc                 \
+       ExternalDataSource.cc \
+       \
+       Exception.cc            \
+       LogControl.cc
+# NO entries below LogControl.cc
+# The static LogControlImpl singleton musr be initialized first!
 
 lib@PACKAGE@_base_la_LIBADD = -lboost_regex