This commit is contained in:
Erik Frojdh
2020-03-04 15:38:21 +01:00
parent 661adaf4ed
commit c6ddd19c0f
3 changed files with 32 additions and 28 deletions

View File

@ -3,8 +3,9 @@
#include <iostream>
#include <chrono>
int main(){
int main() {
//compare old and new
std::cout << "Compare output between old and new:\n";
FILE_LOG(logINFO) << "Old message";
LOG(logINFO) << "New message";
@ -13,20 +14,33 @@ int main(){
FILE_LOG(logWARNING) << "Old warning";
LOG(logWARNING) << "New warning";
// // sls::Logger::ReportingLevel() = logERROR;
//Logging level can be configure at runtime
std::cout << "\n\n";
std::cout << "The default macro controlled level is: "
<< sls::Logger::ToString(LOG_MAX_REPORTING_LEVEL) << '\n';
sls::Logger::ReportingLevel() = logERROR;
LOG(logINFO) << "Now this is not written";
LOG(logWARNING) << "and also not this";
// const auto N = 100000;
// auto t0 = std::chrono::steady_clock::now();
// for (int i = 0; i!=N; ++i){
// // LOG(logWARNING) << "HEY";
// FILE_LOG(logWARNING) << "HEY";
// }
// auto t1 = std::chrono::steady_clock::now();
// for (int i = 0; i!=N; ++i){
// LOG(logWARNING) << "HEY";
// }
// auto t2 = std::chrono::steady_clock::now();
sls::Logger::ReportingLevel() = logINFO;
LOG(logINFO) << "But now we can see it";
// std::cout << "Old: " << (t1-t0).count() << "\n";
// std::cout << "New: " << (t2-t1).count() << "\n";
//The output can be redirected to another buffer
std::ostringstream local;
auto clog_buff = std::clog.rdbuf();
std::clog.rdbuf(local.rdbuf());
LOG(logINFOBLUE) << "A message";
LOG(logWARNING) << "And another one";
std::clog.rdbuf(clog_buff); // restore
std::cout << "local buf:\n" << local.str();
LOG(logINFO) << "After reset we should print directly";
LOG(logINFOBLUE) << "some infoBLUE text";
LOG(logINFOGREEN) << "some infoGREEN text";
LOG(logINFORED) << "some infoRED text";
}