17#include <zypp/base/String.h>
18#include <zypp/base/Logger.h>
19#include <zypp/base/IOStream.h>
21#include <zypp/PathInfo.h>
38 inline string timestamp()
41 inline string userAtHostname()
45 char * tmp = ::cuserid(buf);
49 if (!::gethostname(buf, 255))
50 result +=
"@" + string(buf);
55 static std::string pidAndAppname()
57 static std::string _val;
60 pid_t mypid = getpid();
66 _val += myname.basename();
71 static std::string cmdline()
73 static std::string _val;
76 pid_t mypid = getpid();
80 const char * sep =
"'";
81 while ( cmdlineStr && cmdlineStr.get( ch ) )
90 case '\0': _val +=
'\''; sep =
" '";
break;
91 case '\n': _val +=
' ';
break;
92 case '\\': _val +=
'\\'; _val +=
'\\';
break;
93 case '|': _val +=
'\\'; _val +=
'|';
break;
94 default: _val += ch;
break;
105 const char _sep =
'|';
107 unsigned _refcnt = 0;
109 Pathname _fnameLastFail;
111 inline void openLog()
113 if ( _fname.empty() )
117 _log.open( _fname.asString().c_str(), std::ios::out|std::ios::app );
118 if( !_log && _fnameLastFail != _fname )
120 ERR <<
"Could not open logfile '" << _fname <<
"'" << endl;
121 _fnameLastFail = _fname;
125 inline void closeLog()
138 inline void refDown()
172 if ( _fname !=
"/dev/null" )
173 _fname = rootdir / _fname;
175 MIL <<
"installation log file " << _fname << endl;
183 if ( _fname.empty() )
197 _log << timestamp() <<
" ";
199 const char * s =
comment.c_str();
201 unsigned size =
comment.size();
207 for (
unsigned i = 0; i < size; ++i, ++c )
210 _log << string( s, c + 1 - s ) <<
"# ";
215 _log << std::string( s, c-s );
227 << _sep << userAtHostname()
243 << _sep << p->edition()
244 << _sep << p->arch();
248 _log << _sep << userAtHostname();
250 _log << _sep << pidAndAppname();
255 << _sep << p->repoInfo().alias()
256 << _sep << p->checksum().checksum()
271 << _sep << p->edition()
272 << _sep << p->arch();
276 _log << _sep << userAtHostname();
278 _log << _sep << pidAndAppname();
325 if ( oldrepo.
url() != newrepo.
url() )
346 << _sep << p->edition()
348 << _sep << p->repoInfo().alias()
349 << _sep << p->severity()
350 << _sep << p->category()
#define HISTORY_LOG_DATE_FORMAT
std::string form(const std::string &format_r) const
Return string representation according to format as localtime.
static Date now()
Return the current time.
HistoryLog(const HistoryLog &)
void stampCommand()
Log info about the current process.
static void setRoot(const Pathname &root)
Set new root directory to the default history log file path.
void modifyRepository(const RepoInfo &oldrepo, const RepoInfo &newrepo)
Log certain modifications to a repository.
void remove(const PoolItem &pi)
Log removal of a package.
void addRepository(const RepoInfo &repo)
Log a newly added repository.
void removeRepository(const RepoInfo &repo)
Log recently removed repository.
static const Pathname & fname()
Get the current log file path.
void install(const PoolItem &pi)
Log installation (or update) of a package.
void patchStateChange(const PoolItem &pi, ResStatus::ValidateValue oldstate)
Log state changes in patches.
void comment(const std::string &comment, bool timestamp=false)
Log a comment (even multiline).
TraitsType::constPtrType constPtr
Class representing a patch.
TraitsType::constPtrType constPtr
Combining sat::Solvable and ResStatus.
ResObject::constPtr resolvable() const
Returns the ResObject::constPtr.
ResStatus & status() const
Returns the current status.
What is known about a repository.
Url url() const
Pars pro toto: The first repository url.
bool isByApplHigh() const
std::string validateValueAsString() const
std::string asString() const
Returns a default string representation of the Url object.
Pathname historyLogFile() const
Path where ZYpp install history is logged.
static ZConfig & instance()
Singleton ctor.
bool absolute() const
Test for an absolute path.
std::string alias() const
unique identifier for this source.
int readlink(const Pathname &symlink_r, Pathname &target_r)
Like 'readlink'.
int assert_dir(const Pathname &path, unsigned mode)
Like 'mkdir -p'.
std::string numstring(char n, int w=0)
std::string escape(const C_Str &str_r, const char sep_r)
Escape desired character c using a backslash.
Easy-to use interface to the ZYPP dependency resolver.
static const HistoryActionID REPO_REMOVE
static const HistoryActionID PATCH_STATE_CHANGE
const std::string & asString(bool pad=false) const
static const HistoryActionID REMOVE
static const HistoryActionID STAMP_COMMAND
static const HistoryActionID REPO_ADD
static const HistoryActionID REPO_CHANGE_ALIAS
static const HistoryActionID REPO_CHANGE_URL
static const HistoryActionID INSTALL
bool isKind(const ResKind &kind_r) const