00001 /*---------------------------------------------------------------------\ 00002 | ____ _ __ __ ___ | 00003 | |__ / \ / / . \ . \ | 00004 | / / \ V /| _/ _/ | 00005 | / /__ | | | | | | | 00006 | /_____||_| |_| |_| | 00007 | | 00008 \---------------------------------------------------------------------*/ 00012 #include <iostream> 00013 #include <fstream> 00014 00015 #include "zypp/base/Logger.h" 00016 00017 #include "zypp/target/CommitLog.h" 00018 #include "zypp/Date.h" 00019 00020 using std::endl; 00021 00022 namespace zypp { 00023 namespace target { 00024 00026 00027 Pathname CommitLog::_fname; 00028 std::ofstream CommitLog::_log; 00029 unsigned CommitLog::_refcnt = 0; 00030 00032 00033 void CommitLog::openLog() { 00034 if ( !_fname.empty() ) { 00035 _log.clear(); 00036 _log.open( _fname.asString().c_str(), std::ios::out|std::ios::app ); 00037 if( !_log ) 00038 ERR << "Could not open logfile '" << _fname << "'" << endl; 00039 } 00040 } 00041 void CommitLog::closeLog() { 00042 _log.clear(); 00043 _log.close(); 00044 } 00045 void CommitLog::refUp() { 00046 if ( !_refcnt ) 00047 openLog(); 00048 ++_refcnt; 00049 } 00050 void CommitLog::refDown() { 00051 --_refcnt; 00052 if ( !_refcnt ) 00053 closeLog(); 00054 } 00055 00056 std::ostream & CommitLog::operator()( bool timestamp ) { 00057 if ( timestamp ) { 00058 _log << Date(Date::now()).form( "%Y-%m-%d %H:%M:%S "); 00059 } 00060 return _log; 00061 } 00062 00063 void CommitLog::setFname( const Pathname & fname_r ) { 00064 MIL << "installation log file " << fname_r << endl; 00065 if ( _refcnt ) 00066 closeLog(); 00067 _fname = fname_r; 00068 if ( _refcnt ) 00069 openLog(); 00070 } 00071 00072 } // namespace target 00073 } // namespace zypp
1.5.3