Kea 3.3.1
rotating_file.h
Go to the documentation of this file.
1// Copyright (C) 2016-2026 Internet Systems Consortium, Inc. ("ISC")
2//
3// This Source Code Form is subject to the terms of the Mozilla Public
4// License, v. 2.0. If a copy of the MPL was not distributed with this
5// file, You can obtain one at http://mozilla.org/MPL/2.0/.
6
7#ifndef ROTATING_FILE_H
8#define ROTATING_FILE_H
9
11
12#include <mutex>
13
16
17namespace isc {
18namespace legal_log {
19
51public:
52
54 enum class TimeUnit {
59 };
60
85
89 virtual ~RotatingFile();
90
125 void apply(const isc::db::DatabaseConnection::ParameterMap& parameters);
126
146 virtual void open();
147
151 virtual void close();
152
179 virtual void writeln(const std::string& text, const std::string& addr);
180
186 virtual std::string getType() const {
187 return (std::string("logfile"));
188 }
189
193 std::string getFileName() const {
194 return (file_name_);
195 }
196
200 std::string getBaseName() const {
201 return (base_name_);
202 }
203
207 std::string getPath() const {
208 return (path_);
209 }
210
215 static std::string getYearMonthDay(const struct tm& time_info);
216
224 void updateFileNameAndTimestamp(struct tm& time_info, bool use_existing);
225
226protected:
227
233 virtual void openInternal(struct tm& time_info, bool use_existing);
234
238 void useExistingFiles(struct tm& time_info);
239
245 virtual void rotate();
246
250 virtual bool isOpen() const;
251
252private:
260 void writelnInternal(const std::string& text);
261
263 std::string path_;
264
266 std::string base_name_;
267
269 TimeUnit time_unit_;
270
274 uint32_t count_;
275
277 std::string file_name_;
278
280 std::ofstream file_;
281
283 std::string prerotate_;
284
286 std::string postrotate_;
287
289 time_t timestamp_;
290
292 std::mutex mutex_;
293
294protected:
297
298public:
307};
308
311 // Constructor registers
315
316 // Destructor deregisters
320};
321
322} // namespace legal_log
323} // namespace isc
324
325#endif
std::map< std::string, std::string > ParameterMap
Database configuration parameter map.
static bool unregisterBackendFactory(const std::string &db_type, bool no_log=false)
Unregisters the backend factory function for a given backend type.
static bool registerBackendFactory(const std::string &db_type, const Factory &factory, bool no_log=false, DBVersion db_version=DBVersion())
Registers new backend factory function for a given backend type.
LegalLogMgr abstract class.
virtual void writeln(const std::string &text, const std::string &addr)
Appends a string to the current file.
bool mark_continuation_lines_
The mark continuation lines flag.
virtual void close()
Closes the underlying file.
std::string getFileName() const
Returns the current file name.
std::string getBaseName() const
Returns the file base name.
static std::string getYearMonthDay(const struct tm &time_info)
Build the year-month-day string from a date.
virtual ~RotatingFile()
Destructor.
static isc::dhcp::LegalLogMgrPtr factory(const isc::db::DatabaseConnection::ParameterMap &parameters)
Factory class method.
void useExistingFiles(struct tm &time_info)
Update file name with previously created file.
virtual void open()
Opens the current file for writing.
RotatingFile(const isc::db::DatabaseConnection::ParameterMap &parameters)
Constructor.
virtual void rotate()
Rotates the file if necessary.
void apply(const isc::db::DatabaseConnection::ParameterMap &parameters)
Parse file specification and create forensic log backend.
virtual std::string getType() const
Return backend type.
std::string getPath() const
Returns the file path.
virtual bool isOpen() const
Returns true if the file is open.
TimeUnit
Time unit type used to rotate file.
void updateFileNameAndTimestamp(struct tm &time_info, bool use_existing)
Function which updates the file name and internal timestamp from previously created file name (if it ...
virtual void openInternal(struct tm &time_info, bool use_existing)
Open file using specified timestamp.
boost::shared_ptr< LegalLogMgr > LegalLogMgrPtr
Defines a smart pointer to a LegalLogMgr.
Defines the logger used by the top-level component of kea-lfc.