P4C
The P4 Compiler
Loading...
Searching...
No Matches
p4tools/common/lib/logging.h
1#ifndef BACKENDS_P4TOOLS_COMMON_LIB_LOGGING_H_
2#define BACKENDS_P4TOOLS_COMMON_LIB_LOGGING_H_
3
4#include <filesystem>
5#include <optional>
6#include <string>
7#include <utility>
8
9#include <boost/format.hpp>
10
11#include "lib/log.h"
12
13namespace P4::P4Tools {
14
16inline std::string logHelper(boost::format &f) { return f.str(); }
17
19template <class T, class... Args>
20std::string logHelper(boost::format &f, T &&t, Args &&...args) {
21 return logHelper(f % std::forward<T>(t), std::forward<Args>(args)...);
22}
23
26// https://stackoverflow.com/a/25859856
27template <typename... Arguments>
28void printFeature(const std::string &label, int level, const std::string &fmt,
29 Arguments &&...args) {
30 // Do not print logging messages when logging is not enabled.
31 if (!Log::fileLogLevelIsAtLeast(label.c_str(), level)) {
32 return;
33 }
34
35 boost::format f(fmt);
36 LOG_FEATURE(label.c_str(), level, logHelper(f, std::forward<Arguments>(args)...));
37}
38
41template <typename... Arguments>
42void printInfo(const std::string &fmt, Arguments &&...args) {
43 printFeature("tools_info", 4, fmt, std::forward<Arguments>(args)...);
44}
45
49template <typename... Arguments>
50void printDebug(const std::string &fmt, Arguments &&...args) {
51 printFeature("tools_debug", 4, fmt, std::forward<Arguments>(args)...);
52}
53
56
59
62void printPerformanceReport(const std::optional<std::filesystem::path> &basePath = std::nullopt);
63
64} // namespace P4::P4Tools
65
66#endif /* BACKENDS_P4TOOLS_COMMON_LIB_LOGGING_H_ */
Definition common/compiler/compiler_result.cpp:3
std::string logHelper(boost::format &f)
Helper function for @printFeature.
Definition p4tools/common/lib/logging.h:16
void enablePerformanceLogging()
Enable printing of timing reports.
Definition common/lib/logging.cpp:14
void enableInformationLogging()
Enable the printing of basic run information.
Definition common/lib/logging.cpp:12
void printDebug(const std::string &fmt, Arguments &&...args)
Definition p4tools/common/lib/logging.h:50
void printFeature(const std::string &label, int level, const std::string &fmt, Arguments &&...args)
Definition p4tools/common/lib/logging.h:28
void printInfo(const std::string &fmt, Arguments &&...args)
Definition p4tools/common/lib/logging.h:42
void printPerformanceReport(const std::optional< std::filesystem::path > &basePath)
Definition common/lib/logging.cpp:16