-
Notifications
You must be signed in to change notification settings - Fork 35
/
Copy pathLog.hpp
45 lines (36 loc) · 1.07 KB
/
Log.hpp
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
40
41
42
43
44
45
/* SPDX-License-Identifier: LGPL-2.1-or-later */
/* SPDX-FileCopyrightText: 2020 SUSE LLC */
/*
Provide logging facitlies by including this header file
*/
#ifndef T_U_LOG_H
#define T_U_LOG_H
#include <iomanip>
#include <iostream>
enum class TULogLevel {
None=0, Error, Info, Debug
};
// There's no threading in this application, so no locking is implemented
class TULog {
public:
TULogLevel level = TULogLevel::Error;
template<typename... T> void error(const T&... args) {
if (level >=TULogLevel::Error)
log(args...);
}
template<typename... T> void info(const T&... args) {
if (level >= TULogLevel::Info)
log(args...);
}
template<typename... T> void debug(const T&... args) {
if (level >= TULogLevel::Debug)
log(args...);
}
template<typename... T> void log(const T&... args) {
std::time_t now = std::time(0);
std::cout << std::put_time(std::localtime(&now), "%F %T ");
((std::cout << args),...) << std::endl;
}
};
inline TULog tulog{};
#endif // T_U_LOG_H