easyloggingpp
easyloggingpp copied to clipboard
How to use loggerID?
Hello together, from the readme file I try desperately to extract how to get the loggerID to work. I want to write measurements to a discrete file and I think, loggerID is the thing which will help me. But I don't get it to work from the configuration file and the readme talks about this topic in a few lines only.
What I tried was
-- loggerID
* GLOBAL:
FORMAT = "%datetime %msg"
FILENAME = "logs/%datetime{%Y%M%d
...
and
* GLOBAL:
-- loggerID
FORMAT = "%datetime %msg"
FILENAME = "logs/%datetime{%Y%M%d
...
Using this code:
el::Configurations conf("C:/Users/<absolutePath>/logging.conf");
el::Loggers::addFlag(el::LoggingFlag::FixedTimeFormat);
el::Loggers::addFlag(el::LoggingFlag::AutoSpacing);
el::Loggers::addFlag(el::LoggingFlag::ImmediateFlush);
el::Loggers::reconfigureAllLoggers(conf);
el::Loggers::setDefaultConfigurations(conf, false);
el::Logger* l = el::Loggers::getLogger("loggerID");
l->info("test");
CLOG(INFO, "loggerID") << "test2";
But the startup of the project gives this failures:
ASSERTION FAILURE FROM EASYLOGGING++ (LINE: 2831) [*currLevel != Level::Unknown] WITH MESSAGE "Unrecognized severity level []" ASSERTION FAILURE FROM EASYLOGGING++ (LINE: 2832) [currConfig != ConfigurationType::Unknown] WITH MESSAGE "Unrecognized configuration []" ASSERTION FAILURE FROM EASYLOGGING++ (LINE: 2716) [parsedSuccessfully] WITH MESSAGE "Unable to parse configuration line: -- loggerID"
And the test strings are landing in the standard info_log location. How to use loggerID correctly what lets the parse error disappear? Thanks a lot!
have you see https://github.com/easylogging/easyloggingpp/blob/master/samples/STL/multiple-loggers.cpp ?
Can you please provide a compilable minimal sample and not the snippet for me to try to compile and see what's going on :)?
Okay, no I haven't seen this. Thanks, this makes it clearer. Can could you please add a link into the readme.md section, to make the loggerID functionality clearer?
I haven't set el::LoggingFlag::MultiLoggerSupport
-flag and read the config file before setting the flags. Maybe this changed something.
But anyhow, I still get can parsing error when reading the global.conf. My global.conf looks like
*GLOBAL:
FORMAT = "%datetime %msg"
FILENAME = "logs/%datetime{%Y%M%d_%H%m%s}_log_global.log"
ENABLED = true
TO_FILE = true
TO_STANDARD_OUTPUT = true
MILLISECONDS_WIDTH = 1
PERFORMANCE_TRACKING = true
MAX_LOG_FILE_SIZE = 2097152 ## 2MB - Comment starts with two hashes (##)
LOG_FLUSH_THRESHOLD = 100 ## Flush after every 100 logs
*DEBUG:
FORMAT = "%datetime{%Y.%M.%d %H:%m:%s:%g} %func %msg"
FILENAME = "logs/%datetime{%Y%M%d_%H%m%s}_log_debug.log"
-- loggerID
*INFO:
FORMAT = "%datetime{%Y.%M.%d %H:%m:%s:%g} %msg %msg" ## write twice to see a difference to loggerID2
FILENAME = "logs/%datetime{%Y%M%d_%H%m%s}_log_logger1_info.log"
-- loggerID2
*INFO:
FORMAT = "%datetime{%Y.%M.%d %H:%m:%s:%g} %msg" ## write twice to see difference
FILENAME = "logs/%datetime{%Y%M%d_%H%m%s}_log_logger2_info.log"
and the code which runs is:
main.cpp
#include "SomeClass.hpp"
#include "easyloggingpp\src\easylogging++.h"
#include <conio.h>
INITIALIZE_EASYLOGGINGPP
using namespace std;
int main(int argc, char **argv)
{
START_EASYLOGGINGPP(argc, argv);
SomeClass sc = SomeClass()
}
SomeClass.cpp
#define _ELPP_THREAD_SAFE
#include "SomeClass.hpp"
SomeClass::SomeClass()
{
el::Loggers::addFlag(el::LoggingFlag::MultiLoggerSupport);
el::Loggers::addFlag(el::LoggingFlag::FixedTimeFormat);
el::Loggers::addFlag(el::LoggingFlag::AutoSpacing);
el::Loggers::addFlag(el::LoggingFlag::ImmediateFlush);
el::Configurations conf("<path>/global.conf");
el::Loggers::reconfigureAllLoggers(conf);
el::Loggers::setDefaultConfigurations(conf, false);
el::Logger* l = el::Loggers::getLogger("loggerID");
el::Logger* l2 = el::Loggers::getLogger("loggerID2");
CLOG(INFO, "loggerID") << "test";
CLOG(INFO, "loggerID2") << "test2";
CLOG(INFO, "loggerID") << "test";
}
But still during running the test class, I get this message out:
ASSERTION FAILURE FROM EASYLOGGING++ (LINE: 2831) [*currLevel != Level::Unknown] WITH MESSAGE "Unrecognized severity level []" ASSERTION FAILURE FROM EASYLOGGING++ (LINE: 2832) [currConfig != ConfigurationType::Unknown] WITH MESSAGE "Unrecognized configuration []" ASSERTION FAILURE FROM EASYLOGGING++ (LINE: 2716) [parsedSuccessfully] WITH MESSAGE "Unable to parse configuration line: -- default" ASSERTION FAILURE FROM EASYLOGGING++ (LINE: 2832) [currConfig != ConfigurationType::Unknown] WITH MESSAGE "Unrecognized configuration [FILENAME]" ASSERTION FAILURE FROM EASYLOGGING++ (LINE: 2716) [parsedSuccessfully] WITH MESSAGE "Unable to parse configuration line: -- loggerID" ASSERTION FAILURE FROM EASYLOGGING++ (LINE: 2832) [currConfig != ConfigurationType::Unknown] WITH MESSAGE "Unrecognized configuration [FILENAME]" ASSERTION FAILURE FROM EASYLOGGING++ (LINE: 2716) [parsedSuccessfully] WITH MESSAGE "Unable to parse configuration line: -- loggerID2"
And all the messages go into the last defined location 20161130_231728_log_logger2_info.log to the last defined format:
2016.11.30 19:40:21:1 test
2016.11.30 19:40:21:2 test2 2016.11.30 19:40:21:2 test
Have you an idea why the config is not read into two separate configurations? Thanks for your time in advance!
I can see, that the separate loggers exist, but they write both to the same log file pattern, since the -- loggerID
can't be parsed, and the last parameter definition of (FILENAME
) is taken. How can I fix this?
I didn't quite understand your requirements. Does this compile for you and works fine?
@mga0 I have the same needs as you, have you solved this problem?
@mmabluesky sorry, I don't remember. It was too long ago.
@mmabluesky it's your turn now, just 2 years :)
@easylogging I think in this issue, we want to configure several loggers (even without levels), that log to different files
-- default
* GLOBAL:
FORMAT = "%datetime{%Y-%M-%d %H:%m:%s.%g} %level: %msg"
FILENAME = "log.txt"
ENABLED = true
TO_FILE = true
TO_STANDARD_OUTPUT = true
SUBSECOND_PRECISION = 3
PERFORMANCE_TRACKING = true
MAX_LOG_FILE_SIZE = 268435456 ## 256MB
LOG_FLUSH_THRESHOLD = 100
-- output
* GLOBAL:
FORMAT = "%datetime{%Y-%M-%d %H:%m:%s.%g} %msg"
FILENAME = "output.txt"
int main(int argc, char* argv[]) {
START_EASYLOGGINGPP(argc, argv);
el::Loggers::addFlag(el::LoggingFlag::MultiLoggerSupport); // Enables support for multiple loggers
el::Loggers::getLogger("default");
el::Loggers::getLogger("output");
el::Configurations conf("./easylogging++.conf");
//el::Loggers::reconfigureAllLoggers(conf);
CLOG(INFO, "default", "output") << "default and output";
CLOG(INFO, "output") << "output";
CLOG(INFO, "default") << "default";
return 1;
I have commented reconfigureAllLoggers for now, so it just load configuration, and
ASSERTION FAILURE FROM EASYLOGGING++ (LINE: 531) [*currLevel != Level::Unknown] WITH MESSAGE "Unrecognized severity level []"
ASSERTION FAILURE FROM EASYLOGGING++ (LINE: 532) [currConfig != ConfigurationType::Unknown] WITH MESSAGE "Unrecognized configuration []"
ASSERTION FAILURE FROM EASYLOGGING++ (LINE: 424) [parsedSuccessfully] WITH MESSAGE "Unable to parse configuration line: -- default"
ASSERTION FAILURE FROM EASYLOGGING++ (LINE: 532) [currConfig != ConfigurationType::Unknown] WITH MESSAGE "Unrecognized configuration [LOG_FLUSH_THRESHOLD]"
ASSERTION FAILURE FROM EASYLOGGING++ (LINE: 424) [parsedSuccessfully] WITH MESSAGE "Unable to parse configuration line: -- output"
I found: https://github.com/abumq/easyloggingpp/blob/master/README.md#global-configurations
it isn't the el::Configurations, but
el::Loggers::addFlag(el::LoggingFlag::MultiLoggerSupport); // Enables support for multiple loggers
el::Loggers::configureFromGlobal("./easylogging++.conf");
CLOG(INFO, "default", "output") << "default and output";
CLOG(INFO, "output") << "output";
CLOG(INFO, "default") << "default";