1#include "log.h"
2
3#include <cstdlib>
4#include <thread>
5
6int main() {
7 const int n_thread = 8;
8
9 std::thread threads[n_thread];
10 for (int i = 0; i < n_thread; i++) {
11 threads[i] = std::thread([i]() {
12 const int n_msg = 1000;
13
14 for (int j = 0; j < n_msg; j++) {
15 const int log_type = std::rand() % 4;
16
17 switch (log_type) {
18 case 0: LOG_INF("Thread %d: %d\n", i, j); break;
19 case 1: LOG_WRN("Thread %d: %d\n", i, j); break;
20 case 2: LOG_ERR("Thread %d: %d\n", i, j); break;
21 case 3: LOG_DBG("Thread %d: %d\n", i, j); break;
22 default:
23 break;
24 }
25
26 if (rand () % 10 < 5) {
27 common_log_set_timestamps(log: common_log_main(), timestamps: rand() % 2);
28 common_log_set_prefix (log: common_log_main(), prefix: rand() % 2);
29 }
30 }
31 });
32 }
33
34 for (int i = 0; i < n_thread; i++) {
35 threads[i].join();
36 }
37
38 return 0;
39}
40