10c44c2feSZane Shelley #pragma once
20c44c2feSZane Shelley
30c44c2feSZane Shelley #include <inttypes.h>
40c44c2feSZane Shelley #include <stdio.h>
50c44c2feSZane Shelley
6*30984d15SZane Shelley #include <phosphor-logging/lg2.hpp>
7*30984d15SZane Shelley
80c44c2feSZane Shelley #include <cstdarg>
90c44c2feSZane Shelley
100c44c2feSZane Shelley #ifndef TEST_TRACE
110c44c2feSZane Shelley #include <phosphor-logging/log.hpp>
120c44c2feSZane Shelley #endif
130c44c2feSZane Shelley
140c44c2feSZane Shelley namespace trace
150c44c2feSZane Shelley {
160c44c2feSZane Shelley
170c44c2feSZane Shelley #ifndef TEST_TRACE
180c44c2feSZane Shelley constexpr size_t MSG_MAX_LEN = 256;
190c44c2feSZane Shelley #endif
200c44c2feSZane Shelley
210c44c2feSZane Shelley /** @brief Information trace (va_list format). */
inf(const char * format,va_list args)220c44c2feSZane Shelley inline void inf(const char* format, va_list args)
230c44c2feSZane Shelley {
240c44c2feSZane Shelley #ifdef TEST_TRACE
250c44c2feSZane Shelley
260c44c2feSZane Shelley vfprintf(stdout, format, args);
270c44c2feSZane Shelley fprintf(stdout, "\n");
280c44c2feSZane Shelley
290c44c2feSZane Shelley #else
300c44c2feSZane Shelley
310c44c2feSZane Shelley char msg[MSG_MAX_LEN];
320c44c2feSZane Shelley vsnprintf(msg, MSG_MAX_LEN, format, args);
330c44c2feSZane Shelley phosphor::logging::log<phosphor::logging::level::INFO>(msg);
340c44c2feSZane Shelley
350c44c2feSZane Shelley #endif
360c44c2feSZane Shelley }
370c44c2feSZane Shelley
380c44c2feSZane Shelley /** @brief Error trace (va_list format). */
err(const char * format,va_list args)390c44c2feSZane Shelley inline void err(const char* format, va_list args)
400c44c2feSZane Shelley {
410c44c2feSZane Shelley #ifdef TEST_TRACE
420c44c2feSZane Shelley
430c44c2feSZane Shelley vfprintf(stderr, format, args);
440c44c2feSZane Shelley fprintf(stderr, "\n");
450c44c2feSZane Shelley
460c44c2feSZane Shelley #else
470c44c2feSZane Shelley
480c44c2feSZane Shelley char msg[MSG_MAX_LEN];
490c44c2feSZane Shelley vsnprintf(msg, MSG_MAX_LEN, format, args);
500c44c2feSZane Shelley phosphor::logging::log<phosphor::logging::level::ERR>(msg);
510c44c2feSZane Shelley
520c44c2feSZane Shelley #endif
530c44c2feSZane Shelley }
540c44c2feSZane Shelley
550c44c2feSZane Shelley /** @brief Information trace (printf format). */
inf(const char * format,...)560c44c2feSZane Shelley inline void inf(const char* format, ...)
570c44c2feSZane Shelley {
580c44c2feSZane Shelley va_list args;
590c44c2feSZane Shelley va_start(args, format);
600c44c2feSZane Shelley trace::inf(format, args);
610c44c2feSZane Shelley va_end(args);
620c44c2feSZane Shelley }
630c44c2feSZane Shelley
640c44c2feSZane Shelley /** @brief Error trace (printf format). */
err(const char * format,...)650c44c2feSZane Shelley inline void err(const char* format, ...)
660c44c2feSZane Shelley {
670c44c2feSZane Shelley va_list args;
680c44c2feSZane Shelley va_start(args, format);
690c44c2feSZane Shelley trace::err(format, args);
700c44c2feSZane Shelley va_end(args);
710c44c2feSZane Shelley }
720c44c2feSZane Shelley
730c44c2feSZane Shelley } // namespace trace
74