File: default-configurations.cpp

package info (click to toggle)
easyloggingpp 9.97.0%2Bdfsg-1
  • links: PTS, VCS
  • area: main
  • in suites: bookworm, bullseye
  • size: 2,840 kB
  • sloc: cpp: 11,415; python: 2,336; sh: 337; makefile: 29
file content (34 lines) | stat: -rw-r--r-- 1,260 bytes parent folder | download | duplicates (5)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
 //
 // This file is part of Easylogging++ samples
 //
 // Demonstrates setting default configurations for existing and future loggers
 //
 // Revision 1.1
 // @author mkhan3189
 //

#include "easylogging++.h"

INITIALIZE_EASYLOGGINGPP

using namespace el;

int main(void) {
    
    Configurations c;
    c.setGlobally(ConfigurationType::Format, "[%logger] %level: %msg");
    c.setGlobally(ConfigurationType::Filename, "/tmp/logs/custom.log");
    // Set default configuration for any future logger - existing logger will not use this configuration unless
    // either true is passed in second argument or set explicitly using Loggers::reconfigureAllLoggers(c);
    Loggers::setDefaultConfigurations(c);
    LOG(INFO) << "Set default configuration but existing loggers not updated yet"; // Logging using trivial logger
    Loggers::getLogger("testDefaultConf");
    CLOG(INFO, "testDefaultConf") << "Logging using new logger 1"; // You can also use CINFO << "..."
    // Now setting default and also resetting existing loggers
    Loggers::setDefaultConfigurations(c, true);
    LOG(INFO) << "Existing loggers updated as well";
    Loggers::getLogger("testDefaultConf2");
    CLOG(INFO, "testDefaultConf2") << "Logging using new logger 2";

    return 0;
}