1 #pragma once
2
3 #include <inttypes.h>
4 #include <stdio.h>
5
6 #include <phosphor-logging/lg2.hpp>
7
8 #include <cstdarg>
9
10 #ifndef TEST_TRACE
11 #include <phosphor-logging/log.hpp>
12 #endif
13
14 namespace trace
15 {
16
17 #ifndef TEST_TRACE
18 constexpr size_t MSG_MAX_LEN = 256;
19 #endif
20
21 /** @brief Information trace (va_list format). */
inf(const char * format,va_list args)22 inline void inf(const char* format, va_list args)
23 {
24 #ifdef TEST_TRACE
25
26 vfprintf(stdout, format, args);
27 fprintf(stdout, "\n");
28
29 #else
30
31 char msg[MSG_MAX_LEN];
32 vsnprintf(msg, MSG_MAX_LEN, format, args);
33 phosphor::logging::log<phosphor::logging::level::INFO>(msg);
34
35 #endif
36 }
37
38 /** @brief Error trace (va_list format). */
err(const char * format,va_list args)39 inline void err(const char* format, va_list args)
40 {
41 #ifdef TEST_TRACE
42
43 vfprintf(stderr, format, args);
44 fprintf(stderr, "\n");
45
46 #else
47
48 char msg[MSG_MAX_LEN];
49 vsnprintf(msg, MSG_MAX_LEN, format, args);
50 phosphor::logging::log<phosphor::logging::level::ERR>(msg);
51
52 #endif
53 }
54
55 /** @brief Information trace (printf format). */
inf(const char * format,...)56 inline void inf(const char* format, ...)
57 {
58 va_list args;
59 va_start(args, format);
60 trace::inf(format, args);
61 va_end(args);
62 }
63
64 /** @brief Error trace (printf format). */
err(const char * format,...)65 inline void err(const char* format, ...)
66 {
67 va_list args;
68 va_start(args, format);
69 trace::err(format, args);
70 va_end(args);
71 }
72
73 } // namespace trace
74