mirror of
https://github.com/hyprwm/hyprutils.git
synced 2025-12-20 03:30:22 +01:00
roll
This commit is contained in:
parent
b3657e3135
commit
319f4dd938
4 changed files with 23 additions and 5 deletions
|
|
@ -35,6 +35,7 @@ namespace Hyprutils::CLI {
|
|||
void setTime(bool enabled);
|
||||
void setEnableStdout(bool enabled);
|
||||
void setEnableColor(bool enabled);
|
||||
void setEnableRolling(bool enabled);
|
||||
std::expected<void, std::string> setOutputFile(const std::string_view& file);
|
||||
const std::string& rollingLog();
|
||||
|
||||
|
|
|
|||
|
|
@ -29,6 +29,10 @@ void CLogger::setEnableColor(bool enabled) {
|
|||
m_impl->m_colorEnabled = enabled;
|
||||
}
|
||||
|
||||
void CLogger::setEnableRolling(bool enabled) {
|
||||
m_impl->m_rollingEnabled = enabled;
|
||||
}
|
||||
|
||||
std::expected<void, std::string> CLogger::setOutputFile(const std::string_view& file) {
|
||||
if (file.empty()) {
|
||||
m_impl->m_fileEnabled = false;
|
||||
|
|
@ -132,6 +136,7 @@ void CLoggerImpl::log(eLogLevel level, const std::string_view& msg, const std::s
|
|||
if (m_fileEnabled)
|
||||
m_logOfs << logPrefix << logMsg << "\n";
|
||||
|
||||
if (m_rollingEnabled)
|
||||
appendToRolling(logPrefix + logMsg);
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -25,6 +25,7 @@ namespace Hyprutils::CLI {
|
|||
bool m_stdoutEnabled = true;
|
||||
bool m_fileEnabled = false;
|
||||
bool m_colorEnabled = true;
|
||||
bool m_rollingEnabled = false;
|
||||
|
||||
std::mutex m_logMtx;
|
||||
|
||||
|
|
|
|||
|
|
@ -10,6 +10,9 @@ using namespace Hyprutils;
|
|||
|
||||
TEST(CLI, Logger) {
|
||||
CLogger logger;
|
||||
|
||||
logger.setEnableRolling(true);
|
||||
|
||||
logger.log(Hyprutils::CLI::LOG_DEBUG, "Hello!");
|
||||
|
||||
EXPECT_EQ(logger.rollingLog(), "DEBUG ]: Hello!");
|
||||
|
|
@ -37,6 +40,12 @@ TEST(CLI, Logger) {
|
|||
|
||||
EXPECT_EQ(logger.rollingLog(), "DEBUG ]: Hello!\nTRACE ]: Hello, Trace!\nTRACE from conn ]: Hello from connection!");
|
||||
|
||||
logger.setEnableRolling(false);
|
||||
|
||||
connection.log(Hyprutils::CLI::LOG_ERR, "Err!");
|
||||
|
||||
EXPECT_EQ(logger.rollingLog(), "DEBUG ]: Hello!\nTRACE ]: Hello, Trace!\nTRACE from conn ]: Hello from connection!");
|
||||
|
||||
logger.setEnableStdout(false);
|
||||
|
||||
logger.log(Hyprutils::CLI::LOG_ERR, "Error");
|
||||
|
|
@ -69,6 +78,8 @@ TEST(CLI, Logger) {
|
|||
|
||||
logger.log(Hyprutils::CLI::LOG_CRIT, "rip");
|
||||
|
||||
logger.setEnableRolling(true);
|
||||
|
||||
// spam some logs to check rolling
|
||||
for (size_t i = 0; i < 200; ++i) {
|
||||
logger.log(LOG_ERR, "Oh noes!!!");
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue