1 /*---------------------------------------------------------------------\
3 | |__ / \ / / . \ . \ |
8 \---------------------------------------------------------------------*/
9 /** \file zypp/target/HistoryLog.h
12 #ifndef ZYPP_TARGET_COMMITLOG_H
13 #define ZYPP_TARGET_COMMITLOG_H
17 #include "zypp/Pathname.h"
24 ///////////////////////////////////////////////////////////////////
26 // CLASS NAME : HistoryLog
29 * Enumeration of known history actions.
31 * \ingroup g_EnumerationClass
33 struct HistoryActionID
35 static const HistoryActionID NONE;
37 static const HistoryActionID INSTALL;
38 static const HistoryActionID REMOVE;
39 static const HistoryActionID REPO_ADD;
40 static const HistoryActionID REPO_REMOVE;
41 static const HistoryActionID REPO_CHANGE_ALIAS;
42 static const HistoryActionID REPO_CHANGE_URL;
56 HistoryActionID() : _id(NONE_e) {}
58 HistoryActionID(ID id) : _id(id) {}
60 explicit HistoryActionID(const std::string & strval_r);
62 ID toEnum() const { return _id; }
64 HistoryActionID::ID parse(const std::string & strval_r);
66 const std::string & asString(bool pad = false) const;
71 /** \relates HistoryActionID */
72 std::ostream & operator << (std::ostream & str, const HistoryActionID & id);
73 ///////////////////////////////////////////////////////////////////
76 ///////////////////////////////////////////////////////////////////
78 // CLASS NAME : HistoryLog
80 * Simple wrapper for progress log. Refcnt, filename and corresponding
81 * ofstream are static members. Logfile constructor raises, destructor
82 * lowers refcounter. On refcounter changing from 0->1, file is opened.
83 * Changing from 1->0 the file is closed. Thus Logfile objects should be
84 * local to those functions, writing the log, and must not be stored
93 * HistoryLog().install(pi);
95 * HistoryLog().comment(someMessage);
99 * \note Take care to set proper target root dir if needed. Either pass
100 * it via the constructor, or set it via setRoot(Pathname) method.
101 * The default location of the file is determined by
102 * \ref ZConfig::historyLogPath() which defaults to
103 * /var/log/zypp/history.
105 * \see http://en.opensuse.org/Libzypp/Package_History
109 HistoryLog( const HistoryLog & );
110 HistoryLog & operator=( const HistoryLog & );
112 static std::ofstream _log;
113 static unsigned _refcnt;
114 static Pathname _fname;
115 static const char _sep;
117 static void openLog();
118 static void closeLog();
120 static void refDown();
124 * Constructor with an optional root directory.
126 * \param rootdir actual target root directory
128 HistoryLog( const Pathname & rootdir = Pathname() );
133 * Set new root directory to the default history log file path.
135 * This path will be prepended to the default log file path. This should
136 * be done where there is a potential that the target root has changed.
138 * \param root new root directory.
140 static void setRoot( const Pathname & root );
143 * Get the current log file path.
145 static const Pathname & fname();
148 * Log a comment (even multiline).
150 * \param comment the comment
151 * \param timestamp whether to include a timestamp at the start of the comment
153 void comment( const std::string & comment, bool timestamp = false );
156 * Log installation (or update) of a package.
158 void install( const PoolItem & pi );
161 * Log removal of a package
163 void remove( const PoolItem & pi );
166 * Log a newly added repository.
168 * \param repo info about the added repository
170 void addRepository( const RepoInfo & repo );
173 * Log recently removed repository.
175 * \param repo info about the removed repository
177 void removeRepository( const RepoInfo & repo );
180 * Log certain modifications to a repository.
182 * \param oldrepo info about the old repository
183 * \param newrepo info about the new repository
185 void modifyRepository( const RepoInfo & oldrepo, const RepoInfo & newrepo );
187 ///////////////////////////////////////////////////////////////////
191 #endif // ZYPP_TARGET_COMMITLOG_H