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 static HistoryActionID::ID parse(const std::string & strval_r);
66 const std::string & asString(bool pad = false) const;
72 /** \relates HistoryActionID */
73 std::ostream & operator << (std::ostream & str, const HistoryActionID & id);
74 ///////////////////////////////////////////////////////////////////
77 ///////////////////////////////////////////////////////////////////
79 // CLASS NAME : HistoryLog
81 * Simple wrapper for progress log. Refcnt, filename and corresponding
82 * ofstream are static members. Logfile constructor raises, destructor
83 * lowers refcounter. On refcounter changing from 0->1, file is opened.
84 * Changing from 1->0 the file is closed. Thus Logfile objects should be
85 * local to those functions, writing the log, and must not be stored
94 * HistoryLog().install(pi);
96 * HistoryLog().comment(someMessage);
100 * \note Take care to set proper target root dir if needed. Either pass
101 * it via the constructor, or set it via setRoot(Pathname) method.
102 * The default location of the file is determined by
103 * \ref ZConfig::historyLogPath() which defaults to
104 * /var/log/zypp/history.
106 * \see http://en.opensuse.org/Libzypp/Package_History
108 * \todo Static private stuff does not need to be mentioned here in the
109 * header (use an annon. namespace in the .cc). Appart from that the
110 * implementation as signleton is questionable. Use shared_ptr instead of
111 * handcrafted ref/unref. Manage multiple logs at different locations.
115 HistoryLog( const HistoryLog & );
116 HistoryLog & operator=( const HistoryLog & );
118 static std::ofstream _log;
119 static unsigned _refcnt;
120 static Pathname _fname;
121 static const char _sep;
123 static void openLog();
124 static void closeLog();
126 static void refDown();
130 * Constructor with an optional root directory.
132 * \param rootdir actual target root directory
134 HistoryLog( const Pathname & rootdir = Pathname() );
139 * Set new root directory to the default history log file path.
141 * This path will be prepended to the default log file path. This should
142 * be done where there is a potential that the target root has changed.
144 * \param root new root directory.
146 static void setRoot( const Pathname & root );
149 * Get the current log file path.
151 static const Pathname & fname();
154 * Log a comment (even multiline).
156 * \param comment the comment
157 * \param timestamp whether to include a timestamp at the start of the comment
159 void comment( const std::string & comment, bool timestamp = false );
162 * Log installation (or update) of a package.
164 void install( const PoolItem & pi );
167 * Log removal of a package
169 void remove( const PoolItem & pi );
172 * Log a newly added repository.
174 * \param repo info about the added repository
176 void addRepository( const RepoInfo & repo );
179 * Log recently removed repository.
181 * \param repo info about the removed repository
183 void removeRepository( const RepoInfo & repo );
186 * Log certain modifications to a repository.
188 * \param oldrepo info about the old repository
189 * \param newrepo info about the new repository
191 void modifyRepository( const RepoInfo & oldrepo, const RepoInfo & newrepo );
193 ///////////////////////////////////////////////////////////////////
197 #endif // ZYPP_TARGET_COMMITLOG_H