1#include <gtest/gtest.h>
9#include <source_location>
12#include "quill/LogMacros.h"
14std::string
TEST_CONFIG = std::string(getenv(
"MESON_SOURCE_ROOT")) +
"/tests/testsConfig.yaml";
17 std::ifstream file(filename);
18 std::string line, lastLine;
20 if (!file.is_open()) {
21 throw std::runtime_error(
"Could not open file");
24 while (std::getline(file, line)) {
32 std::regex logPattern(R
"(\d+:\d+:\d+\.\d+\s+\[\d+\]\s+probeTest\.cpp:\d+\s+LOG_INFO\s+[A-Za-z]*\s+(.*))");
34 if (std::regex_match(logLine, match, logPattern) && match.size() > 1) {
35 return match[1].str();
44 serif::config::Config::getInstance().loadConfig(
TEST_CONFIG);
49 auto start = std::chrono::high_resolution_clock::now();
51 auto end = std::chrono::high_resolution_clock::now();
52 std::chrono::duration<double> elapsed = end - start;
53 EXPECT_LE(elapsed.count(), 1.1);
57 serif::config::Config::getInstance().loadConfig(
TEST_CONFIG);
59 const std::string loggerName =
"testLog";
60 const std::string filename =
"test.log";
61 quill::Logger* logger = logManager.
newFileLogger(filename, loggerName);
62 EXPECT_NE(logger,
nullptr);
63 LOG_INFO(logger,
"This is a test message");
66 while (lastLine.empty()) {
73 serif::config::Config::getInstance().loadConfig(
TEST_CONFIG);
75 const std::string loggerName =
"newLog";
76 const std::string filename =
"newLog.log";
77 quill::Logger* logger = logManager.
newFileLogger(filename, loggerName);
78 EXPECT_NE(logger,
nullptr);
79 LOG_INFO(logger,
"This is a new test message");
82 while (lastLine.empty()) {
89 serif::config::Config::getInstance().loadConfig(
TEST_CONFIG);
91 std::vector<std::string> loggerNames = logManager.
getLoggerNames();
92 EXPECT_EQ(loggerNames.size(), 4);
93 EXPECT_EQ(loggerNames.at(0),
"log");
94 EXPECT_EQ(loggerNames.at(1),
"newLog");
95 EXPECT_EQ(loggerNames.at(2),
"stdout");
96 EXPECT_EQ(loggerNames.at(3),
"testLog");
Class to manage logging operations.
quill::Logger * newFileLogger(const std::string &filename, const std::string &loggerName)
Create a new file logger.
static LogManager & getInstance()
Get the singleton instance of LogManager.
std::vector< std::string > getLoggerNames()
Get the names of all loggers.
void wait(int seconds)
Wait for a specified number of seconds.
std::string stripTimestamps(const std::string &logLine)
std::string getLastLine(const std::string &filename)
TEST_F(probeTest, DefaultConstructorTest)