File: multi-loggers-to-same-file.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 (39 lines) | stat: -rw-r--r-- 781 bytes parent folder | download | duplicates (4)
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
35
36
37
38
39
//
// This file is part of Easylogging++ samples
//
// Revision 1.0
//

#include <thread>
#include "easylogging++.h"

INITIALIZE_EASYLOGGINGPP

void def() {
    for (int i = 0; i < 1000; ++i)
        CLOG(INFO, "first") << "This is from first " << i;
}

void second() {
    for (int i = 0; i < 1000; ++i)
        CLOG(INFO, "second") << "This is from second" << i;
}

int main(int,char**){
    el::Loggers::addFlag(el::LoggingFlag::CreateLoggerAutomatically);

    el::Configurations confFromFile("../default-logger.conf");

    el::Loggers::setDefaultConfigurations(confFromFile, true);

    LOG(INFO)<<"The program has started!";
    
    std::thread t1(def);
    std::thread t2(second);
    
    t1.join();
    t2.join();
    
    LOG(INFO) << "Shutting down.";
    return 0;
}