encfs/vendor/github.com/muflihun/easyloggingpp/test/global-configurations-test.h
Valient Gough 5f0806c5cc Add "easylogging" from "https://github.com/muflihun/easyloggingpp@master"
git-vendor-name: easylogging
git-vendor-dir: vendor/github.com/muflihun/easyloggingpp
git-vendor-repository: https://github.com/muflihun/easyloggingpp
git-vendor-ref: master
2017-08-05 23:23:41 -07:00

56 lines
2.4 KiB
C++

#ifndef GLOBAL_CONFIGURATIONS_TEST_H_
#define GLOBAL_CONFIGURATIONS_TEST_H_
#include "test.h"
TEST(GlobalConfigurationTest, Parse) {
const char* globalConfFile = "/tmp/global-conf-test.conf";
std::fstream confFile(globalConfFile, std::fstream::out);
confFile
<< "-- performance\n"
<< " ## This just skips configuring performance logger any more.\n"
<< "-- global-test-logger\n"
<< "* GLOBAL:\n"
<< " FORMAT = GLOBAL_TEST\n"
<< "* INFO:\n"
// Following should be included in format because its inside the quotes
<< "* DEBUG:\n"
<< " FORMAT = %datetime %level [%user@%host] [%func] [%loc] %msg ## Comment before EOL char\n"
<< "## Comment on empty line\n"
// WARNING is defined by GLOBAL
<< "* ERROR:\n"
<< " FORMAT = %datetime %level %msg\n"
<< "* FATAL:\n"
<< " FORMAT = %datetime %level %msg\n"
<< "* VERBOSE:\n"
<< " FORMAT = %datetime %level-%vlevel %msg\n"
<< "* TRACE:\n"
<< " FORMAT = %datetime %level [%func] [%loc] %msg\n";
confFile.close();
Logger* perfLogger = Loggers::getLogger("performance", false);
CHECK_NOTNULL(perfLogger);
std::string perfFormatConf = perfLogger->configurations()->get(Level::Info, ConfigurationType::Format)->value();
std::string perfFilenameConf = perfLogger->configurations()->get(Level::Info, ConfigurationType::Filename)->value();
std::size_t totalLoggers = elStorage->registeredLoggers()->size();
EXPECT_EQ(Loggers::getLogger("global-test-logger", false), nullptr);
Loggers::configureFromGlobal(globalConfFile);
EXPECT_EQ(totalLoggers + 1, elStorage->registeredLoggers()->size());
EXPECT_EQ(perfFormatConf, perfLogger->configurations()->get(Level::Info, ConfigurationType::Format)->value());
EXPECT_EQ(perfFilenameConf, perfLogger->configurations()->get(Level::Info, ConfigurationType::Filename)->value());
// Not nullptr anymore
Logger* testLogger = Loggers::getLogger("global-test-logger", false);
EXPECT_NE(testLogger, nullptr);
EXPECT_EQ("GLOBAL_TEST", testLogger->configurations()->get(Level::Info, ConfigurationType::Format)->value());
EXPECT_EQ("%datetime %level [%user@%host] [%func] [%loc] %msg", testLogger->configurations()->get(Level::Debug, ConfigurationType::Format)->value());
}
#endif // GLOBAL_CONFIGURATIONS_TEST_H_