Kea 3.1.1
rotating_file.h
Go to the documentation of this file.
1// Copyright (C) 2016-2025 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
84
88 virtual ~RotatingFile();
89
120 void apply(const isc::db::DatabaseConnection::ParameterMap& parameters);
121
141 virtual void open();
142
146 virtual void close();
147
168 virtual void writeln(const std::string& text, const std::string& addr);
169
175 virtual std::string getType() const {
176 return (std::string("logfile"));
177 }
178
182 std::string getFileName() const {
183 return (file_name_);
184 }
185
189 std::string getBaseName() const {
190 return (base_name_);
191 }
192
196 std::string getPath() const {
197 return (path_);
198 }
199
204 static std::string getYearMonthDay(const struct tm& time_info);
205
213 void updateFileNameAndTimestamp(struct tm& time_info, bool use_existing);
214
215protected:
216
222 virtual void openInternal(struct tm& time_info, bool use_existing);
223
227 void useExistingFiles(struct tm& time_info);
228
234 virtual void rotate();
235
239 virtual bool isOpen() const;
240
241private:
249 void writelnInternal(const std::string& text);
250
252 std::string path_;
253
255 std::string base_name_;
256
258 TimeUnit time_unit_;
259
263 uint32_t count_;
264
266 std::string file_name_;
267
269 std::ofstream file_;
270
272 std::string prerotate_;
273
275 std::string postrotate_;
276
278 time_t timestamp_;
279
281 std::mutex mutex_;
282
283public:
292};
293
296 // Constructor registers
300
301 // Destructor deregisters
305};
306
307} // namespace legal_log
308} // namespace isc
309
310#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.
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.