31#define __attribute__(X)
41extern int maximumLogLevel;
44extern bool enableLoggingGlobally;
45extern bool enableLoggingInContext;
48int fileLogLevel(
const char *file);
49std::ostream &fileLogOutput(
const char *file);
56 static int ostream_xalloc;
57 static void setup_ostream_xalloc(std::ostream &);
58 friend std::ostream &operator<<(std::ostream &,
const OutputLogPrefix &);
59 friend std::ostream &clearPrefix(std::ostream &out);
62 mutable lock_t *lock =
nullptr;
67 static void indent(std::ostream &out);
70void addInvalidateCallback(
void (*)(
void));
71std::ostream &clearPrefix(std::ostream &out);
74inline std::ostream &endl(std::ostream &out) {
76 Detail::OutputLogPrefix::indent(out);
79using ::P4::IndentCtl::indent;
80using ::P4::IndentCtl::TempIndent;
81using ::P4::IndentCtl::unindent;
83inline bool fileLogLevelIsAtLeast(
const char *file,
int level) {
86 if (Detail::maximumLogLevel < level) {
90 return Detail::fileLogLevel(file) >= level;
94void addDebugSpec(
const char *spec);
96inline bool verbose() {
return Detail::verbosity > 0; }
97inline int verbosity() {
return Detail::verbosity; }
98inline bool enableLogging() {
99 return Detail::enableLoggingGlobally || Detail::enableLoggingInContext;
101void increaseVerbosity();
106#ifndef MAX_LOGGING_LEVEL
108#define MAX_LOGGING_LEVEL 10
112#define LOGGING_FEATURE(TAG, N) \
113 ((N) <= MAX_LOGGING_LEVEL && P4::Log::fileLogLevelIsAtLeast(TAG, N) && P4::Log::enableLogging())
114#define LOGGING(N) LOGGING_FEATURE(__FILE__, N)
117 (LOGGING(N) ? P4::Log::Detail::fileLogOutput(__FILE__) \
118 << P4::Log::Detail::OutputLogPrefix(__FILE__, N) << X \
119 << P4::Log::Detail::clearPrefix << std::endl \
121#define LOG1(X) LOGN(1, X)
122#define LOG2(X) LOGN(2, X)
123#define LOG3(X) LOGN(3, X)
124#define LOG4(X) LOGN(4, X)
125#define LOG5(X) LOGN(5, X)
126#define LOG6(X) LOGN(6, X)
127#define LOG7(X) LOGN(7, X)
128#define LOG8(X) LOGN(8, X)
129#define LOG9(X) LOGN(9, X)
131#define LOGN_UNINDENT(N) \
132 (LOGGING(N) ? P4::Log::Detail::fileLogOutput(__FILE__) << P4::IndentCtl::unindent : std::clog)
133#define LOG1_UNINDENT LOGN_UNINDENT(1)
134#define LOG2_UNINDENT LOGN_UNINDENT(2)
135#define LOG3_UNINDENT LOGN_UNINDENT(3)
136#define LOG4_UNINDENT LOGN_UNINDENT(4)
137#define LOG5_UNINDENT LOGN_UNINDENT(5)
138#define LOG6_UNINDENT LOGN_UNINDENT(6)
139#define LOG7_UNINDENT LOGN_UNINDENT(7)
140#define LOG8_UNINDENT LOGN_UNINDENT(8)
141#define LOG9_UNINDENT LOGN_UNINDENT(9)
143#define LOG_FEATURE(TAG, N, X) \
144 (LOGGING_FEATURE(TAG, N) ? P4::Log::Detail::fileLogOutput(TAG) \
145 << P4::Log::Detail::OutputLogPrefix(TAG, N) << X << std::endl \
148#define P4C_ERROR(X) (std::clog << "ERROR: " << X << std::endl)
149#define P4C_WARNING(X) (P4::Log::verbose() ? std::clog << "WARNING: " << X << std::endl : std::clog)
150#define ERRWARN(C, X) ((C) ? P4C_ERROR(X) : P4C_WARNING(X))
155static inline std::ostream &operator<<(std::ostream &out,
156 std::function<std::ostream &(std::ostream &)> fn) {
164std::ostream &
format_container(std::ostream &out,
const Cont &container,
char lbrace,
char rbrace) {
165 std::vector<std::string> elems;
166 bool foundnl =
false;
167 for (
auto &el : container) {
168 std::stringstream tmp;
170 elems.emplace_back(tmp.str());
171 if (!foundnl) foundnl = elems.back().find(
'\n') != std::string::npos;
174 for (
auto &el : elems) {
175 out << Log::endl << Log::indent;
176 for (
auto &ch : el) {
182 out << Log::unindent;
185 const char *sep =
" ";
187 for (
auto &el : elems) {
191 out << (sep + 1) << rbrace;
198std::ostream &operator<<(std::ostream &out,
const std::vector<T> &vec) {
203std::ostream &operator<<(std::ostream &out,
const std::set<T> &set) {
TODO: this is not really specific to BMV2, it should reside somewhere else.
Definition applyOptionsPragmas.cpp:24
std::ostream & format_container(std::ostream &out, const Cont &container, char lbrace, char rbrace)
Definition log.h:164