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