blob: ccafd98ce3f5806ab022372961ad8b2485f906c6 [file] [log] [blame]
Zane Shelley0c44c2f2020-06-05 17:14:31 -05001#pragma once
2
3#include <inttypes.h>
4#include <stdio.h>
5
Zane Shelley30984d12021-12-22 17:17:54 -06006#include <phosphor-logging/lg2.hpp>
7
Zane Shelley0c44c2f2020-06-05 17:14:31 -05008#include <cstdarg>
9
10#ifndef TEST_TRACE
11#include <phosphor-logging/log.hpp>
12#endif
13
14namespace trace
15{
16
17#ifndef TEST_TRACE
18constexpr size_t MSG_MAX_LEN = 256;
19#endif
20
21/** @brief Information trace (va_list format). */
22inline 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). */
39inline 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). */
56inline 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). */
65inline 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