austinfcui | 6a62e40 | 2021-12-01 11:52:45 -0600 | [diff] [blame] | 1 | #pragma once |
| 2 | |
| 3 | #include <inttypes.h> |
| 4 | #include <stdio.h> |
| 5 | |
| 6 | #include <phosphor-logging/log.hpp> |
| 7 | |
| 8 | #include <cstdarg> |
| 9 | |
| 10 | namespace util |
| 11 | { |
| 12 | |
| 13 | /* |
| 14 | * @brief callback function for logging with log level |
| 15 | * |
| 16 | * @param loglevel PDBG log level |
| 17 | * @param format format of output function, same as in printf() |
| 18 | * @param args variable list |
| 19 | * |
| 20 | * @return none |
| 21 | */ |
| 22 | inline void pdbg_log_callback(const int loglevel, const char* format, |
| 23 | va_list args) |
| 24 | { |
| 25 | constexpr size_t MSG_MAX_LEN = 256; |
| 26 | char msg[MSG_MAX_LEN]; |
| 27 | vsnprintf(msg, MSG_MAX_LEN, format, args); |
| 28 | |
| 29 | switch (loglevel) |
| 30 | { |
| 31 | case PDBG_ERROR: |
| 32 | phosphor::logging::log<phosphor::logging::level::ERR>(msg); |
| 33 | break; |
| 34 | case PDBG_WARNING: |
| 35 | phosphor::logging::log<phosphor::logging::level::WARNING>(msg); |
| 36 | break; |
| 37 | case PDBG_NOTICE: |
| 38 | phosphor::logging::log<phosphor::logging::level::NOTICE>(msg); |
| 39 | break; |
| 40 | case PDBG_INFO: |
| 41 | phosphor::logging::log<phosphor::logging::level::INFO>(msg); |
| 42 | break; |
| 43 | case PDBG_DEBUG: |
| 44 | phosphor::logging::log<phosphor::logging::level::DEBUG>(msg); |
| 45 | break; |
| 46 | default: |
| 47 | phosphor::logging::log<phosphor::logging::level::ERR>(msg); |
| 48 | break; |
| 49 | } |
| 50 | } |
| 51 | |
| 52 | } // namespace util |