|
@@ -3,7 +3,7 @@
|
|
* Company: Lynar Studios
|
|
* Company: Lynar Studios
|
|
* E-Mail: webmaster@lynarstudios.com
|
|
* E-Mail: webmaster@lynarstudios.com
|
|
* Created: 2020-08-20
|
|
* Created: 2020-08-20
|
|
- * Changed: 2023-03-25
|
|
|
|
|
|
+ * Changed: 2023-04-12
|
|
*
|
|
*
|
|
* */
|
|
* */
|
|
|
|
|
|
@@ -19,6 +19,7 @@ using ls::std::io::FileOutputStream;
|
|
using ls::std::io::FileReader;
|
|
using ls::std::io::FileReader;
|
|
using ls::std::io::Logger;
|
|
using ls::std::io::Logger;
|
|
using ls::std::io::LogLevelValue;
|
|
using ls::std::io::LogLevelValue;
|
|
|
|
+using ls::std::io::NewLine;
|
|
using ls::std::test::TestHelper;
|
|
using ls::std::test::TestHelper;
|
|
using std::dynamic_pointer_cast;
|
|
using std::dynamic_pointer_cast;
|
|
using std::make_shared;
|
|
using std::make_shared;
|
|
@@ -86,6 +87,8 @@ namespace
|
|
|
|
|
|
Logger logger{writer};
|
|
Logger logger{writer};
|
|
logger.setLogLevel(LogLevelValue::DEBUG);
|
|
logger.setLogLevel(LogLevelValue::DEBUG);
|
|
|
|
+ logger.showLogLevel();
|
|
|
|
+ logger.showTimestamp();
|
|
logger.debug("1. line!");
|
|
logger.debug("1. line!");
|
|
logger.info("2. line!");
|
|
logger.info("2. line!");
|
|
logger.error("3. line!");
|
|
logger.error("3. line!");
|
|
@@ -115,6 +118,8 @@ namespace
|
|
|
|
|
|
Logger logger{writer};
|
|
Logger logger{writer};
|
|
logger.setLogLevel(LogLevelValue::ERR);
|
|
logger.setLogLevel(LogLevelValue::ERR);
|
|
|
|
+ logger.showLogLevel();
|
|
|
|
+ logger.showTimestamp();
|
|
logger.debug("1. line!");
|
|
logger.debug("1. line!");
|
|
logger.info("2. line!");
|
|
logger.info("2. line!");
|
|
logger.error("3. line!");
|
|
logger.error("3. line!");
|
|
@@ -144,6 +149,8 @@ namespace
|
|
|
|
|
|
Logger logger{writer};
|
|
Logger logger{writer};
|
|
logger.setLogLevel(LogLevelValue::FATAL);
|
|
logger.setLogLevel(LogLevelValue::FATAL);
|
|
|
|
+ logger.showLogLevel();
|
|
|
|
+ logger.showTimestamp();
|
|
logger.debug("1. line!");
|
|
logger.debug("1. line!");
|
|
logger.info("2. line!");
|
|
logger.info("2. line!");
|
|
logger.error("3. line!");
|
|
logger.error("3. line!");
|
|
@@ -170,6 +177,62 @@ namespace
|
|
ASSERT_EQ(LogLevelValue::INFO, logger.getLogLevel().getValue());
|
|
ASSERT_EQ(LogLevelValue::INFO, logger.getLogLevel().getValue());
|
|
}
|
|
}
|
|
|
|
|
|
|
|
+ TEST_F(LoggerTest, hideLogLevel)
|
|
|
|
+ {
|
|
|
|
+ string logName = "hide-log-level-output-fatal.log";
|
|
|
|
+ shared_ptr<IWriter> writer = createFileLogger(logName);
|
|
|
|
+
|
|
|
|
+ Logger logger{writer};
|
|
|
|
+ logger.setLogLevel(LogLevelValue::DEBUG);
|
|
|
|
+ logger.hideLogLevel();
|
|
|
|
+ logger.fatal("test message");
|
|
|
|
+
|
|
|
|
+ // get content and check
|
|
|
|
+
|
|
|
|
+ dynamic_pointer_cast<FileOutputStream>(writer)->close();
|
|
|
|
+ string content = getContentFromLogFile(logName);
|
|
|
|
+
|
|
|
|
+ ASSERT_TRUE(content.find("FATAL") == string::npos);
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ TEST_F(LoggerTest, hideTimestamp)
|
|
|
|
+ {
|
|
|
|
+ string logName = "hide-time-stamp-output-fatal.log";
|
|
|
|
+ shared_ptr<IWriter> writer = createFileLogger(logName);
|
|
|
|
+
|
|
|
|
+ Logger logger{writer};
|
|
|
|
+ logger.setLogLevel(LogLevelValue::DEBUG);
|
|
|
|
+ logger.hideTimestamp();
|
|
|
|
+ logger.fatal("test message");
|
|
|
|
+
|
|
|
|
+ // get content and check
|
|
|
|
+
|
|
|
|
+ dynamic_pointer_cast<FileOutputStream>(writer)->close();
|
|
|
|
+ string content = getContentFromLogFile(logName);
|
|
|
|
+
|
|
|
|
+ ASSERT_TRUE(content.find('[') == string::npos);
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ TEST_F(LoggerTest, hideInformation)
|
|
|
|
+ {
|
|
|
|
+ string logName = "hide-info-output-fatal.log";
|
|
|
|
+ shared_ptr<IWriter> writer = createFileLogger(logName);
|
|
|
|
+ string message = "test message";
|
|
|
|
+
|
|
|
|
+ Logger logger{writer};
|
|
|
|
+ logger.setLogLevel(LogLevelValue::DEBUG);
|
|
|
|
+ logger.hideLogLevel();
|
|
|
|
+ logger.hideTimestamp();
|
|
|
|
+ logger.fatal(message.c_str());
|
|
|
|
+
|
|
|
|
+ // get content and check
|
|
|
|
+
|
|
|
|
+ dynamic_pointer_cast<FileOutputStream>(writer)->close();
|
|
|
|
+ string content = getContentFromLogFile(logName);
|
|
|
|
+
|
|
|
|
+ ASSERT_STREQ(string(message + NewLine::get()).c_str(), content.c_str());
|
|
|
|
+ }
|
|
|
|
+
|
|
TEST_F(LoggerTest, info)
|
|
TEST_F(LoggerTest, info)
|
|
{
|
|
{
|
|
// write to log file
|
|
// write to log file
|
|
@@ -179,6 +242,8 @@ namespace
|
|
|
|
|
|
Logger logger{writer};
|
|
Logger logger{writer};
|
|
logger.setLogLevel(LogLevelValue::INFO);
|
|
logger.setLogLevel(LogLevelValue::INFO);
|
|
|
|
+ logger.showLogLevel();
|
|
|
|
+ logger.showTimestamp();
|
|
logger.fatal("1. line!");
|
|
logger.fatal("1. line!");
|
|
logger.error("2. line!");
|
|
logger.error("2. line!");
|
|
logger.warn("3. line!");
|
|
logger.warn("3. line!");
|
|
@@ -207,6 +272,42 @@ namespace
|
|
ASSERT_EQ(LogLevelValue::ERR, logger.getLogLevel().getValue());
|
|
ASSERT_EQ(LogLevelValue::ERR, logger.getLogLevel().getValue());
|
|
}
|
|
}
|
|
|
|
|
|
|
|
+ TEST_F(LoggerTest, showLogLevel)
|
|
|
|
+ {
|
|
|
|
+ string logName = "show-log-level-output-fatal.log";
|
|
|
|
+ shared_ptr<IWriter> writer = createFileLogger(logName);
|
|
|
|
+
|
|
|
|
+ Logger logger{writer};
|
|
|
|
+ logger.setLogLevel(LogLevelValue::DEBUG);
|
|
|
|
+ logger.showLogLevel();
|
|
|
|
+ logger.fatal("test message");
|
|
|
|
+
|
|
|
|
+ // get content and check
|
|
|
|
+
|
|
|
|
+ dynamic_pointer_cast<FileOutputStream>(writer)->close();
|
|
|
|
+ string content = getContentFromLogFile(logName);
|
|
|
|
+
|
|
|
|
+ ASSERT_TRUE(content.find("FATAL") != string::npos);
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ TEST_F(LoggerTest, showTimestamp)
|
|
|
|
+ {
|
|
|
|
+ string logName = "hide-time-stamp-output-fatal.log";
|
|
|
|
+ shared_ptr<IWriter> writer = createFileLogger(logName);
|
|
|
|
+
|
|
|
|
+ Logger logger{writer};
|
|
|
|
+ logger.setLogLevel(LogLevelValue::DEBUG);
|
|
|
|
+ logger.showTimestamp();
|
|
|
|
+ logger.fatal("test message");
|
|
|
|
+
|
|
|
|
+ // get content and check
|
|
|
|
+
|
|
|
|
+ dynamic_pointer_cast<FileOutputStream>(writer)->close();
|
|
|
|
+ string content = getContentFromLogFile(logName);
|
|
|
|
+
|
|
|
|
+ ASSERT_TRUE(content.find('[') != string::npos);
|
|
|
|
+ }
|
|
|
|
+
|
|
TEST_F(LoggerTest, trace)
|
|
TEST_F(LoggerTest, trace)
|
|
{
|
|
{
|
|
// write to log file
|
|
// write to log file
|
|
@@ -216,6 +317,8 @@ namespace
|
|
|
|
|
|
Logger logger{writer};
|
|
Logger logger{writer};
|
|
logger.setLogLevel(LogLevelValue::TRACE);
|
|
logger.setLogLevel(LogLevelValue::TRACE);
|
|
|
|
+ logger.showLogLevel();
|
|
|
|
+ logger.showTimestamp();
|
|
logger.fatal("1. line!");
|
|
logger.fatal("1. line!");
|
|
logger.error("2. line!");
|
|
logger.error("2. line!");
|
|
logger.warn("3. line!");
|
|
logger.warn("3. line!");
|
|
@@ -245,6 +348,8 @@ namespace
|
|
|
|
|
|
Logger logger{writer};
|
|
Logger logger{writer};
|
|
logger.setLogLevel(LogLevelValue::WARN);
|
|
logger.setLogLevel(LogLevelValue::WARN);
|
|
|
|
+ logger.showLogLevel();
|
|
|
|
+ logger.showTimestamp();
|
|
logger.fatal("1. line!");
|
|
logger.fatal("1. line!");
|
|
logger.error("2. line!");
|
|
logger.error("2. line!");
|
|
logger.warn("3. line!");
|
|
logger.warn("3. line!");
|