-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
logging: Simplify rotating file sink
- Loading branch information
Showing
3 changed files
with
94 additions
and
133 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,10 +1,45 @@ | ||
#include "fmt/core.h" | ||
#include "fmt/std.h" | ||
|
||
#include <hage/logging/rotating_file_sink.hpp> | ||
|
||
using namespace hage; | ||
|
||
void | ||
hage::RotatingFileSink::receive(hage::LogLevel level, const hage::Sink::timestamp_type& ts, std::string_view line) | ||
RotatingFileSink::receive(LogLevel level, const Sink::timestamp_type& ts, std::string_view line) | ||
{ | ||
std::ignore = level; | ||
std::ignore = ts; | ||
std::ignore = line; | ||
} | ||
|
||
hage::RotatingFileSink::~RotatingFileSink() {} | ||
RotatingFileSink::~RotatingFileSink() {} | ||
|
||
bool | ||
SizeRotater::shouldRotate(const LogFileStats& stats) | ||
{ | ||
return m_maxSize <= stats.bytes; | ||
} | ||
|
||
std::vector<std::filesystem::path> | ||
SizeRotater::generateNames(const LogFileStats& stats, int times) | ||
{ | ||
if (times <= 0) | ||
return {}; | ||
|
||
// We are simply delivering the messages. | ||
std::vector<std::filesystem::path> ans; | ||
ans.push_back(m_base); | ||
|
||
for (int i = 1; i < times; i++) { | ||
ans.emplace_back(fmt::format("{}.{}", m_base, i)); | ||
} | ||
|
||
return ans; | ||
} | ||
|
||
SizeRotater::SizeRotater(std::filesystem::path base, std::size_t maxSize) | ||
: m_maxSize{ maxSize } | ||
, m_base{ std::move(base) } | ||
{ | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters