Commits

a4z committed 905d9c6

log replaced, skip a4z depencency part 1

Comments (0)

Files changed (15)

 src/sbbdep/cachedb.cpp
 src/sbbdep/cachesql.cpp
 src/sbbdep/dircontent.cpp
+src/sbbdep/error.cpp
 src/sbbdep/elffile.cpp
 src/sbbdep/lddmap.cpp
 src/sbbdep/lddirs.cpp

include/sbbdep/error.hpp

 /*
---------------Copyright (c) 2010-2013 H a r a l d  A c h i t z---------------
+--------------Copyright (c) 2009-2013 H a r a l d  A c h i t z---------------
 -----------< h a r a l d dot a c h i t z at g m a i l dot c o m >------------
 Permission is hereby granted, free of charge, to any person obtaining a copy
 of this software and associated documentation files (the "Software"), to deal
 -----------------------------------------------------------------------------
 */
 
-
-
 #ifndef SBBDEP_ERROR_HPP_
 #define SBBDEP_ERROR_HPP_
 
-#include <a4z/err.hpp>
 
+#include <iosfwd>
+#include <string>
 
 namespace sbbdep{
 
-  A4Z_NAME_AS(sbbdep) sbbdepDomainName ;
-  /// defines the root domain 
-  typedef a4z::ErrDomain<sbbdepDomainName> ErrorDomain;
+
+  /// map error reason to enum value
+  enum class ErrCode
+  {
+     GENERIC    = 1 ,
+     TODO       = 98 ,
+     UNEXPECTED = 99 
+  };
   
-  // TODO , this is all very old and not used anymore, review, remove, and add whats needed
-  struct ErrorCodes 
+
+
+  class Error
   {
-    enum Value{
-      Generic = 1,
-      StatErr = 2, 
-      MagicErr = 3,  
-      DepCheckErr = 4 ,
-      PkgErr = 5 ,
-      DirContentErr = 6
-    };  
-     
+
+  public:
+    Error( std::string info ) ;
+    virtual ~Error() noexcept ;
+
+    virtual ErrCode id() const = 0 ;
+
+    const std::string& info() const ;
+
+  protected:
+    const std::string _info;
+
+    friend std::ostream& operator<<(std::ostream& os, const Error& e);
+
+    virtual void toStream(std::ostream& os) const;
   };
 
-  ///defines the err name
-  A4Z_NAME_AS(Error) ErrorName ;
-  ///defines err type
-  typedef a4z::ErrType< ErrorName, ErrorDomain , ErrorCodes::Value  > Error;
+  std::ostream& operator<< (std::ostream& os, const Error& e);
 
 
-  typedef a4z::ErrObject< Error , ErrorCodes::Generic > ErrGeneric ;
-  typedef a4z::ErrObject< Error , ErrorCodes::StatErr > ErrStat ;
-  typedef a4z::ErrObject< Error , ErrorCodes::MagicErr > ErrMagic ;
-  typedef a4z::ErrObject< Error , ErrorCodes::DepCheckErr > ErrDepCheck ;
-  typedef a4z::ErrObject< Error , ErrorCodes::PkgErr > ErrPkg ;
-  typedef a4z::ErrObject< Error , ErrorCodes::DirContentErr > ErrDirContent ; 
+  template<ErrCode ec>
+  class ErrType: public Error
+  {
+
+  public:
+    ErrType( std::string msg = "" )
+      : Error( std::move(msg) )
+    {
+    }
+
+    virtual ~ErrType() noexcept {}
+
+    ErrCode id() const override  { return ec ; }
+
+  };
   
-} // ns
+  using ErrGeneric      =  ErrType<ErrCode::GENERIC>;
+  using ErrToDo         =  ErrType<ErrCode::TODO>;
+  using ErrUnexpected   =  ErrType<ErrCode::UNEXPECTED>;
 
-#endif /* ERROR_HPP_ */
+
+
+} // ns 
+
+
+#endif /* ...ERROR_HPP_ */

include/sbbdep/log.hpp

 /*
---------------Copyright (c) 2010-2013 H a r a l d  A c h i t z---------------
+--------------Copyright (c) 2009-2013 H a r a l d  A c h i t z---------------
 -----------< h a r a l d dot a c h i t z at g m a i l dot c o m >------------
 Permission is hereby granted, free of charge, to any person obtaining a copy
 of this software and associated documentation files (the "Software"), to deal
 */
 
 
-#ifndef SBBDEP_LOG_HPP_
-#define SBBDEP_LOG_HPP_
+#ifndef SBBDEB_LOGSYSTEM_HPP_
+#define SBBDEB_LOGSYSTEM_HPP_
 
-#include <a4z/logsystemomp.hpp>
-#include <a4z/single.hpp>
-#include <a4z/errostream.hpp>
 
-#include <boost/iostreams/stream.hpp>
+#include <memory>
+#include <ostream>
 
-namespace sbbdep {
+namespace sbbdep
+{
 
+  
+typedef std::basic_ostream<char, typename std::char_traits<char>>  log_stream_type;
 
-
-
-
-
-class Log : public a4z::LogSystemOMP<char> , public a4z::Single<sbbdep::Log>
+//the whole thing is a kind of hack, but for now it has to replace the former a4z::LogSystem
+  
+class LogChannel
 {
-    friend class a4z::Single<Log>;
-    
-
-    
+ 
 public:
-    //typedef a4z::LogSystemOMP< char >::ChannelType ChannelType;
-    
-    struct ChannelId{  enum ChannelNames    {
-      Debug = 1 , Info = 2, Error = 3, AppMessage = 4
-    } ;   };
-
-    
-    struct Level {  enum LogLevelValues   {
-      NDebug = 0, Debug = 1
-    }; };    
-    
-    
-  Log() :
-#ifdef DEBUG      
-      a4z::LogSystemOMP<char>(Level::Debug) 
-#else
-      a4z::LogSystemOMP<char>(Level::NDebug) 
-#endif
+  
+  // TODO make private and friend create function ....
+  LogChannel(std::shared_ptr<log_stream_type> stm) 
+  : _stm(stm)
   {
-    // Error/Debug = cerr , Info = cout
-
-  }
-  ~Log();
-  
-
-  static ChannelType Debug(int loglevel = Level::Debug){ 
-    return sbbdep::Log::get()->Channel( ChannelId::Debug , loglevel ) ; 
-  }  
-
-
-  static Log::ChannelType Info(int loglevel = Level::NDebug){ 
-    return sbbdep::Log::get()->Channel( ChannelId::Info , loglevel ); 
-  }  
-  
-
-  static Log::ChannelType Error(int loglevel = Level::NDebug){ 
-    return sbbdep::Log::get()->Channel( ChannelId::Error , loglevel); 
-  }  
-
-  static Log::ChannelType AppMessage(int loglevel = Level::NDebug){
-    try
-      { // needs to be setup by the application
-        return sbbdep::Log::get()->Channel(ChannelId::AppMessage, loglevel);
-      }
-    catch (a4z::LogError& e)
-      {
-        Error()<< e << "\n";
-        throw;
-      }
   }
 
   
-};
+  ~LogChannel()
+  {
+  }
 
 
-//lets see which syntax I will prefer...
-inline
-Log::ChannelType LogDebug(){ 
-  return Log::get()->Debug(); 
-}  
+  template< typename T >
+  LogChannel&
+  operator<<( const T& val )
+  {
+    *_stm << val;
+    return *this;
+  }//---------------------------------------------------------------------------------------------
 
-inline
-Log::ChannelType LogInfo(){ 
-  return Log::get()->Info(); 
-}  
+  LogChannel&
+  operator<<( log_stream_type& (*pf)( log_stream_type& ) )
+  {
+    *_stm << pf;
+    return *this;
+  }//---------------------------------------------------------------------------------------------
 
-inline
-Log::ChannelType LogError(){ 
-  return Log::get()->Error(); 
-}  
+  LogChannel&
+  operator<<( std::ios& (*pf)( std::ios& ) )
+  {
+    *_stm << pf;
+    return *this;
+  }//---------------------------------------------------------------------------------------------
 
-inline
-Log::ChannelType WriteAppMsg(){
-  return Log::get()->AppMessage();
-}
-
-
-
-typedef Log::ChannelType LogChannelType; 
-
-
-// this should go to log base class
-struct DevNullSink
-{
-  typedef char char_type;
-  typedef boost::iostreams::sink_tag category;
-
-  std::streamsize
-  write( const char_type* c, std::streamsize n )
+  LogChannel&
+  operator<<( std::ios_base& (*pf)( std::ios_base& ) )
   {
-    return n;
-  }
+    *_stm << pf;
+    return *this;
+  }//---------------------------------------------------------------------------------------------
+  
+  
+private:
+  std::shared_ptr<log_stream_type> _stm;
+  
 };
 //--------------------------------------------------------------------------------------------------
 
 
-class  DevNullStream : public boost::iostreams::stream< DevNullSink >
+
+class LogSetup
 {
-  DevNullSink m_sink;
+  struct Setup{std::ostream& appstm ; bool quiet;};
+  static std::unique_ptr<Setup> _setup; 
+  
+  
 public:
-  DevNullStream(): m_sink(){ open(m_sink); }
+  static void create(std::ostream& appstm, bool quiet);
+  
+  static bool Quiet() ; 
+  static std::ostream& AppSream() ; 
+  
 };
-//--------------------------------------------------------------------------------------------------
-static  DevNullStream DevNull  ;
 
 
+LogChannel LogDebug();
+LogChannel LogError();
+LogChannel LogInfo();
+LogChannel WriteAppMsg();
 
-}
 
-#endif /* SBBDEP_LOG_HPP_ */
+
+}// ns
+
+
+
+#endif 
 
 // should possible not be required here
 #include <sbbdep/pkg.hpp>
+#include <sbbdep/error.hpp>
 
-#include <a4z/err.hpp>
 #include <a4z/singlecollector.hpp>
 
 namespace sbbdep {
           sbbdep::MINOR_VERSION ,
           sbbdep::PATCH_VERSION );
     }
-  catch (const a4z::Err& e)
+  catch (const Error& e)
     {
       LogError() << e << std::endl;
       return false;
         {
           cli::printSyncReport( Cache::get()->doSync() );
         }
-      catch (const a4z::Err& e)
+      catch (const Error& e)
         {
           LogError() << e << std::endl;
            return false;
         }
+      catch (...)
+        { // TODO, cou
+          LogError() << "Unknown exception" << std::endl;
+          return false;
+        }
     }
   // TODO; here I could reopen the cache read only!!
 
       return 0;
     }
 
-  // log must be the first thing that is initialised !!
-  Log::create();
-  Log::getInstance()->addChannel(Log::ChannelId::Debug, std::cerr , "Debug");
-  Log::getInstance()->addChannel(Log::ChannelId::Error, std::cerr , "Error");
-
-  if( appargs.getQuiet() )
-    Log::getInstance()->addChannel(Log::ChannelId::Info, DevNull , "Info");
+  std::ofstream outfile;
+  if( appargs.getOutFile().size() )
+    {
+      outfile.open(appargs.getOutFile().c_str(), std::ofstream::out | std::ofstream::trunc);
+      LogSetup::create(outfile, appargs.getQuiet()) ;
+    }
   else
-    Log::getInstance()->addChannel(Log::ChannelId::Info, std::cout , "Info");
+    {
+      LogSetup::create(std::cout, appargs.getQuiet()) ;
+    }
 
 
   try
       if( !prepairCache(appargs.getNoSync()) )
         return -2;
     }
-  catch (const a4z::Err& e)
+  catch (const Error& e)
     {
       std::cerr << e << std::endl;
       return -1;
     }
-
-
-  std::ofstream outfile;
-  if( appargs.getOutFile().size() )
+  catch (...)
     {
-      outfile.open(appargs.getOutFile().c_str(), std::ofstream::out | std::ofstream::trunc);
-      Log::getInstance()->addChannel(Log::ChannelId::AppMessage, outfile, "AppMessage");
-    }
-  else
-    {
-      Log::getInstance()->addChannel(Log::ChannelId::AppMessage, std::cout, "AppMessage");
+      std::cerr << "Unknown error" << std::endl;
+      return -1;
     }
 
   Path querypath(appargs.getQuery());
 
           return 0;
         }
-      catch (const a4z::Err& e)
+      catch (const Error& e)
         {
           LogError() << e << std::endl;
           return -3;
         }
+      catch (...)
+        {
+          LogError() << "Unknown error" << std::endl;
+          return -3;
+        }
     }
 
   try
     {
       pkg.Load(); // TODO , check the return value
     }
-  catch (const a4z::Err& e)
+  catch (const Error& e)
     {
       LogError() << e << std::endl;
       return -4;
     }
-
+  catch (...)
+    {
+      LogError() << "Unknown error" << std::endl;
+      return -4;
+    }
   if(appargs.getFeatureX())
     {
       sbbdep::cli::runFx() ;
         {
           cli::printWhoNeed( pkg , appargs.getAppendVersions(), appargs.getXDL() ) ;
         }
-      catch (const a4z::Err& e)
+      catch (const Error& e)
         {
           LogError() << e << std::endl;
           return -5;
         }
-
+      catch (...)
+        {
+          LogError() << "Unknown error" << std::endl;
+          return -5;
+        }
     }
   else if( !appargs.getWhoNeeds()  )
     {
 {
   
 
-  Log::AppMessage() << " internal test function " << __PRETTY_FUNCTION__ << "\n";
+  WriteAppMsg() << " internal test function " << __PRETTY_FUNCTION__ << "\n";
 
 #ifndef DEBUG
   Log::AppMessage() << "not enabled in non debug builds\n";

src/cli/lookup_fileinpackages.cpp

 #include <sbbdep/log.hpp>
 
 #include <fstream>
+#include <vector>
 
 
 using namespace sbbdep;
             PathName match("/"+line);
 
             if (path_is_same_or_incoming(match))
-                WriteAppMsg()  << "absolute match in " << pkgfile << ": " << search  << "\n";
+              WriteAppMsg()  << "absolute match in " << pkgfile << ": " << search  << "\n";
             else
-                WriteAppMsg()  << " filename found in " << pkgfile << ": " << search.getBase() << "\n"
+              WriteAppMsg()  << " filename found in " << pkgfile << ": " << search.getBase() << "\n"
                 << " -> line was :" << line << "\n";
 
             // if there was a match, no need to proceed
   if( pkg.getType() == PkgType::BinLib )
     {
       a4sqlt3::Dataset ds = getPkgsOfFile( pkg.getPath(), pkg.getArch() ) ;
-      Log::AppMessage() << "\n" ;
-      Log::AppMessage() << "check " << pkg.getPath() ;
-      Log::AppMessage() << ", " << pkg.getDynLinked().begin()->getArch() << "bit " ;
+      WriteAppMsg() << "\n" ;
+      WriteAppMsg() << "check " << pkg.getPath() ;
+      WriteAppMsg() << ", " << pkg.getDynLinked().begin()->getArch() << "bit " ;
       if(pkg.getDynLinked().begin()->getType() == ElfFile::Binary)
-        Log::AppMessage() << "binary " ;
+        WriteAppMsg() << "binary " ;
       else if(pkg.getDynLinked().begin()->getType() == ElfFile::Library)
-        Log::AppMessage() << "library (" << pkg.getDynLinked().begin()->soName()  << ")" ;
+        WriteAppMsg() << "library (" << pkg.getDynLinked().begin()->soName()  << ")" ;
 
-      Log::AppMessage() << std::endl ;
+      WriteAppMsg() << std::endl ;
 
       if(ds.getRowCount()==0)
         {
-          Log::AppMessage() << " .. not in a known package" << std::endl;
+          WriteAppMsg() << " .. not in a known package" << std::endl;
         }
       else
         {
           for(auto flds : ds)
-            Log::AppMessage() << " .. from package " <<  flds.getField(0).getString() <<std::endl;
+            WriteAppMsg() << " .. from package " <<  flds.getField(0).getString() <<std::endl;
 
         }
-      Log::AppMessage() << std::endl ;
+      WriteAppMsg() << std::endl ;
     }
 
   auto makename = [addversion, xdl](const std::string val)
     {
       for(auto requiredby_sos : reptree.node)
         {
-          Log::AppMessage() << "file " << requiredby_sos.first << " needs:\n";
+          WriteAppMsg() << "file " << requiredby_sos.first << " needs:\n";
           for(auto so_files : requiredby_sos.second.node)
             {
-              Log::AppMessage() << "  " << so_files.first << " found in:\n";
+              WriteAppMsg() << "  " << so_files.first << " found in:\n";
               for(auto file_pkgs : so_files.second.node)
                 {
-                  Log::AppMessage() << "    " << file_pkgs.first << "( "
+                  WriteAppMsg() << "    " << file_pkgs.first << "( "
                       << utils::joinToString(getKeySet(file_pkgs.second.node), " | ", makename)
                       << " )\n";
                 }
             pkglist.insert( utils::joinToString(pkgsofso, " | ", makename ) ) ;
         }
 
-      Log::AppMessage() << utils::joinToString(pkglist, addversion ? "\n" : ", " ) ;
+      WriteAppMsg() << utils::joinToString(pkglist, addversion ? "\n" : ", " ) ;
 
     }
-    Log::AppMessage() << std::endl;
+    WriteAppMsg() << std::endl;
 
 
 
     if(not notFounds.empty())
       {
-        Log::AppMessage() <<std::endl;
-        Log::AppMessage() << "sonames not found via " <<
+        WriteAppMsg() <<std::endl;
+        WriteAppMsg() << "sonames not found via " <<
             (ldd ? "ldd\n" : "standard paths: \n") ;
 
         for(auto val : notFounds){
-            Log::AppMessage() << " for " << val.first << ": "<<utils::joinToString(val.second, ", ")
+            WriteAppMsg() << " for " << val.first << ": "<<utils::joinToString(val.second, ", ")
             << "\n" ;
         }
 
-        Log::AppMessage() << "this does not necessarily mean there is a problem\n";
+        WriteAppMsg() << "this does not necessarily mean there is a problem\n";
         if(not ldd)
           {
-            Log::AppMessage() << "the application can either have its own environment or the soname is resolved via a link name \n" ;
-            Log::AppMessage() << "you can re-check the affected files with --ldd \n" ;
+            WriteAppMsg() << "the application can either have its own environment or the soname is resolved via a link name \n" ;
+            WriteAppMsg() << "you can re-check the affected files with --ldd \n" ;
           }
         else
           {
-            Log::AppMessage() << "but it's very likely that there is one\n";
+            WriteAppMsg() << "but it's very likely that there is one\n";
           }
 
-        Log::AppMessage() << std::endl;
+        WriteAppMsg() << std::endl;
       }
 
-    Log::AppMessage() << std::endl;
+    WriteAppMsg() << std::endl;
 }
 
 
           [&printChild]( utils::ReportElement elem , int level ){
         for(auto node: elem.node){
            for(int i = 0; i < level; ++i)
-             Log::AppMessage() << " " ;
+             WriteAppMsg() << " " ;
 
-           Log::AppMessage() << node.first << "\n";
+           WriteAppMsg() << node.first << "\n";
           printChild(node.second, level+2);
         }
       };
 
       for( auto elem : reptree.node )
       {
-        Log::AppMessage() << elem.first << " is used from:"<<std::endl;
+        WriteAppMsg() << elem.first << " is used from:"<<std::endl;
         printChild(elem.second, 2) ;
       }
-      Log::AppMessage() << std::endl;
+      WriteAppMsg() << std::endl;
       //printTree(reptree) ; // TODO, better format
     }
   else
               row.getField(0).getString() : PkgName(row.getField(0).getString()).Name() ) ;
         }
 
-      Log::AppMessage()<< utils::joinToString( pkgnames, addversion ? "\n": ", " ) << std::endl ;
+      WriteAppMsg()<< utils::joinToString( pkgnames, addversion ? "\n": ", " ) << std::endl ;
     }
 
 
       catch ( const a4sqlt3::SQLite3Error& e )
         {
           LogError() << e << "\n" ;
-          A4Z_THROW_NESTED("");
+          throw ErrGeneric("sqlite error");
         }
-      catch ( const a4z::Err& e )
+      catch ( ... )
         {
-          A4Z_THROW_NESTED("");
+          LogError() << "Unknown exception" << "\n" ;
+          throw;
         }
       
     }
 
   if (m_db.isNew())
     {
-      Log::Info() << "create cache (" << m_db.Name() <<")" << std::endl;
+      LogInfo() << "create cache (" << m_db.Name() <<")" << std::endl;
 
       auto newfiles_cb = [&toinsert](const std::string& d,const std::string&& f) -> bool {
         toinsert.emplace_back( f);
     }
   else
     {
-      Log::Info() << "sync cache (" << m_db.Name() <<")" << std::endl;
+      LogInfo() << "sync cache (" << m_db.Name() <<")" << std::endl;
 
       syncdata = getSyncData() ;
 

src/sbbdep/cachedb.cpp

 #include <sbbdep/pkgadmdir.hpp>
 #include <sbbdep/config.hpp> // generated
 #include <sbbdep/lddirs.hpp>
+#include <sbbdep/error.hpp>
 
 #include <a4sqlt3/sqlcommand.hpp>
 #include <a4sqlt3/dataset.hpp>
 
 #include <a4sqlt3/error.hpp>
 
-#include <a4z/err.hpp>
+
 
 #include <cstdlib>
 #include <algorithm>
 
           transact.commit();
         }
-      catch ( const a4z::Err& e )
+      catch ( const a4sqlt3::Error& e )
         {
-          LogError() << e << "\n ^ at creating db schema\n";
-          A4Z_THROW_NESTED("");
+          LogError() << e << "\n ^ at creating schema\n";
+          throw;
+        }
+      catch ( ... )
+        {
+          LogError() << "Unknown exception" << " at creating  schema\n";
+          throw;
         }
 
       CacheSQL::register_own_sql_functions(_sql3db);
           Execute(CacheSQL::CreateViews());
           transact.commit();
         }
-      catch ( const a4z::Err& e )
+      catch ( const a4sqlt3::Error& e )
         {
-          LogError() << e << "\n ^ at creating db indexes\n";
-          A4Z_THROW_NESTED("");
+          LogError() << e << "\n ^ at creating indexes\n";
+          throw;
         }
-
+      catch ( ... )
+        {
+          LogError() << "Unknown exception " << " at creating indexes\n";
+          throw;
+        }
 
     }
   else
       a4sqlt3::DbValue rc = this->selectSingleValue(sql);
 
       if(rc.isNull())
-        throw a4z::ErrorTodo();
+        throw ErrToDo();
 
       if( rc.getInt64() != 1 )
         {
           if( rc.getInt64() > 1 )
             {
               LogError() << "more than one entry in version table, confused and can not continue\n";
-              throw a4z::ErrorTodo();
+              throw ErrToDo();
             }
           Execute(CacheSQL::CreateVersion(0, 1, 0)); // set default to 1, so update steps gi from one.
         }
           LogError() << "please create a new cache by using the -c option or removing " <<
               _name << ".\n";
           LogError() << "Sorry for the inconvenience caused.\n\n" ;
-          throw a4z::ErrorMessage("old db version in use");
+          throw ErrGeneric("old db version in use");
         }
 
       Transaction trans(*this);
 
 #ifdef DEBUG
   if( calcVersion(major, minor, patchlevel) != getDbVersion() )
-    throw a4z::ErrorNeverReach("version update incorrect");
+    throw ErrUnexpected("version update incorrect");
 #endif
 
 }
   dsldtime.Reset();
   Execute("SELECT value FROM keyvalstore WHERE key='ldsoconf';", dsldtime);
   if(dsldtime.getRowCount()!= 1)
-    throw a4z::ErrorMessage("keyval ldsoconf count != 1");
+    throw ErrGeneric("keyval ldsoconf count != 1");
 
   if(lddirs.getLdSoConfTime() > dsldtime.getField(0).asInt64())
       {

src/sbbdep/dircontent.cpp

   m_dirstm = opendir(m_name.c_str());
 
   if( !m_dirstm )
-    throw ErrDirContent ("opendir(" + m_name + ") faild");
+    throw ErrGeneric ("opendir(" + m_name + ") faild");
 
 }
 //--------------------------------------------------------------------------------------------------

src/sbbdep/elffile.cpp

 #include <sbbdep/elffile.hpp>
 #include <sbbdep/log.hpp>
 #include <sbbdep/path.hpp>
+#include <sbbdep/error.hpp>
 
 #include <elfio/elfio.hpp>
 
 
   int elfclass = elfreader.get_class();
   if (elfclass == ELFCLASSNONE)
-    throw a4z::ErrorNeverReach("should already have returned false");
+    throw ErrUnexpected("should already have returned false");
   else if (elfclass == ELFCLASS32)
     m_arch = Arch32;
   else if (elfclass == ELFCLASS64)
     m_arch = Arch64;
   else
-    throw a4z::ErrorNeverReach("unknown arch should not happen");
+    throw ErrUnexpected("unknown arch should not happen");
 
 
   ELFIO::Elf_Half type = elfreader.get_type();
+/*
+--------------Copyright (c) 2009-2013 H a r a l d  A c h i t z---------------
+-----------< h a r a l d dot a c h i t z at g m a i l dot c o m >------------
+Permission is hereby granted, free of charge, to any person obtaining a copy
+of this software and associated documentation files (the "Software"), to deal
+in the Software without restriction, including without limitation the rights
+to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+copies of the Software, and to permit persons to whom the Software is
+furnished to do so, subject to the following conditions:
+
+The above copyright notice and this permission notice shall be included in
+all copies or substantial portions of the Software.
+
+THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
+THE SOFTWARE.
+-----------------------------------------------------------------------------
+*/
+
+#include <sbbdep/error.hpp>
+
+#include <ostream>
+#include <map>
+
+namespace sbbdep{
+
+
+namespace {
+  std::string ErrCodeName(ErrCode ec)
+  {
+    static const std::map<ErrCode, std::string> names{
+      { ErrCode::TODO               , "TODO" } ,
+      { ErrCode::UNEXPECTED         , "UNEXPECTED" }
+    };
+
+    auto i = names.find( ec );
+    if( i != std::end( names ) )
+      return i->second;
+
+    return std::to_string( (int)ec );
+  }
+}//------------------------------------------------------------------------------------------------
+//--------------------------------------------------------------------------------------------------
+
+Error::Error( std::string info )
+:_info(std::move(info))
+{
+}
+//--------------------------------------------------------------------------------------------------
+Error::~Error() noexcept
+{
+}
+//--------------------------------------------------------------------------------------------------
+
+const std::string&
+Error::info() const
+{
+  return _info ;
+}
+//--------------------------------------------------------------------------------------------------
+
+void
+Error::toStream(std::ostream& os) const
+{
+  os << "sbbdep::" << ErrCodeName(id()) << ":" << info();
+}
+//--------------------------------------------------------------------------------------------------
+
+
+//--------------------------------------------------------------------------------------------------
+
+std::ostream& operator<< (std::ostream& os, const Error& e)
+{
+  e.toStream(os) ;
+  return os;
+}
+//--------------------------------------------------------------------------------------------------
+
+
+}

src/sbbdep/lddirs.cpp

     }
   else 
     {
-      throw ErrStat("unable to read /etc/ld.so.conf");                
+      throw ErrGeneric("unable to read /etc/ld.so.conf");
     }
   
   
 /*
---------------Copyright (c) 2010-2013 H a r a l d  A c h i t z---------------
+--------------Copyright (c) 2009-2013 H a r a l d  A c h i t z---------------
 -----------< h a r a l d dot a c h i t z at g m a i l dot c o m >------------
 Permission is hereby granted, free of charge, to any person obtaining a copy
 of this software and associated documentation files (the "Software"), to deal
 -----------------------------------------------------------------------------
 */
 
+#include <sbbdep/log.hpp>
+#include <boost/iostreams/stream.hpp>
 
-#include <sbbdep/log.hpp>
-#include <iostream>
+#include <mutex>
 
-namespace sbbdep {
 
-
-Log::~Log(  )
+namespace sbbdep
 {
 
+  
+class LogWriter
+{
+
+public:
+  
+
+  LogWriter( log_stream_type& stm )
+    : _stm( stm )
+  {
+  }
+
+  std::streamsize
+  flush( const char* c, std::streamsize n )
+  {
+    std::lock_guard<std::mutex> lock(_mtx);  
+    typedef std::ostream_iterator<char,char> iter_type;
+    std::copy( c, c + n, iter_type( _stm ) );
+    return n;
+  }//---------------------------------------------------------------------------------------------
+
+private:
+  log_stream_type& _stm;
+  std::mutex _mtx;
+};
+  
+//--------------------------------------------------------------------------------------------------  
+  
+
+
+class LogSink
+{
+  std::shared_ptr<class LogWriter> _writer ;
+  
+public:
+  typedef char char_type;
+  typedef boost::iostreams::sink_tag category;
+
+  
+  LogSink( std::shared_ptr<class LogWriter> writer )
+    : _writer( writer )
+  {
+  }  
+ 
+  std::streamsize
+  write( const char_type* c, std::streamsize n )
+  {
+    return _writer->flush(c,n);
+  }
+
+};
+//--------------------------------------------------------------------------------------------------
+
+  
+class LogStream : public boost::iostreams::stream<LogSink>
+{
+  LogSink _sink;
+public:
+  LogStream(std::shared_ptr<class LogWriter> writer): _sink(writer) {open(_sink);}
+};  
+//--------------------------------------------------------------------------------------------------
+
+
+
+struct DevNullSink
+{
+  typedef char char_type;
+  typedef boost::iostreams::sink_tag category;
+
+  std::streamsize
+  write( const char_type* c, std::streamsize n )
+  {
+    return n;
+  }
+};
+//--------------------------------------------------------------------------------------------------
+
+
+class  DevNullStream : public boost::iostreams::stream< DevNullSink >
+{
+  DevNullSink m_sink;
+public:
+  DevNullStream(): m_sink(){ open(m_sink); }
+};
+//--------------------------------------------------------------------------------------------------
+
+
+
+
+std::unique_ptr<LogSetup::Setup> LogSetup::_setup{nullptr}; 
+
+//--------------------------------------------------------------------------------------------------
+void LogSetup::create(std::ostream& appstm, bool quiet)
+{
+  if( _setup != nullptr )
+    throw "TODO"; 
+  
+  _setup.reset(new Setup{appstm, quiet});
 }
+//--------------------------------------------------------------------------------------------------
+bool LogSetup::Quiet()
+{
+  return _setup->quiet ; 
+}
+//--------------------------------------------------------------------------------------------------
+std::ostream& LogSetup::AppSream()
+{
+  return _setup->appstm ; 
+}
+//--------------------------------------------------------------------------------------------------  
+LogChannel LogDebug()
+{
+#ifdef DEBUG
+  static std::shared_ptr<LogWriter> writer = std::make_shared<LogWriter>(std::cerr) ;
+  return LogChannel( std::make_shared<DevNullStream>() ) ;  
+#else
+  return LogChannel( std::make_shared<DevNullStream>() ) ;  
+#endif
 
 }
+//--------------------------------------------------------------------------------------------------
+LogChannel LogError()
+{
+  
+  static std::shared_ptr<LogWriter> writer = std::make_shared<LogWriter>(std::cerr);
+  
+  return LogChannel(std::make_shared<LogStream>(writer)); 
+}
+//--------------------------------------------------------------------------------------------------
+LogChannel LogInfo()
+{
+  
+  if ( LogSetup::Quiet() )
+    return LogChannel( std::make_shared<DevNullStream>() ) ;    
+  
+  
+  static std::shared_ptr<LogWriter> writer = std::make_shared<LogWriter>(std::cout);
+  return LogChannel(std::make_shared<LogStream>(writer));  
+  
+}
+//--------------------------------------------------------------------------------------------------
+
+LogChannel WriteAppMsg()
+{
+  static std::shared_ptr<LogWriter> writer = std::make_shared<LogWriter>(LogSetup::AppSream());
+  return LogChannel(std::make_shared<LogStream>(writer));  
+  
+}
+//--------------------------------------------------------------------------------------------------
+
+
+
+}// ns
+
+
+
 #include <sbbdep/pkg.hpp>
 #include <sbbdep/path.hpp>
 #include <sbbdep/pkgadmdir.hpp>
-
+#include <sbbdep/error.hpp>
 #include <sbbdep/log.hpp>
 
 #include <fstream>
           if(isToCheck(pn))
             checkFile(pn);
         }
-      catch( const a4z::Err& e )
+      catch( const Error& e )
         {
-          LogError() << e << " (readpkg " << m_path.getURL() << " line:"<< line << ")\n";
+          LogError() << e
+              << " (readpkg " << m_path.getURL() << " line:"<< line << ")\n";
+        }
+      catch( ... )
+        {
+          LogError() << "Unknown exception (readpkg "
+              << m_path.getURL() << " line:"<< line << ")\n";
         }
     }