Sto utilizzando il registro di boost nel mio programma C++ e ho un numero personalizzato severity_logger<severity_level>
utilizzando un enum severity_level che ho definito. Quindi creo il mio sink di registro con la stringa di formato "%TimeStamp% [%ThreadID%] %Severity% %Module% - %Message%"
ma non visualizza la gravità in cui ho %Severity%
ma è invece vuoto in quella posizione. Ad esempio, 2013-07-29 10:31 [0xDEADBEEF] my.Module - Hello World
. Cosa devo fare nella stringa di formato per visualizzare il livello di gravità?In Boost Log, come posso formattare un severity_level personalizzato utilizzando una stringa di formato?
Ecco una parte del mio codice:
#define NUM_SEVERITY_LEVELS 6
enum severity_level
{
// These are deliberately the same levels that log4j uses
trace = 0,
debug = 1,
info = 2,
warning = 3,
error = 4,
fatal = 5
};
typedef src::severity_logger<severity_level> logger_t;
const char* severity_level_str[NUM_SEVERITY_LEVELS] = {
"TRACE",
"DEBUG",
"INFO",
"WARNING",
"ERROR",
"FATAL"
};
template< typename CharT, typename TraitsT >
std::basic_ostream< CharT, TraitsT >&
operator<< (
std::basic_ostream< CharT, TraitsT >& strm,
severity_level lvl
)
{
const char* str = severity_level_str[lvl];
if (lvl < NUM_SEVERITY_LEVELS && lvl >= 0)
strm << str;
else
strm << static_cast<int>(lvl);
return strm;
}
#define FORMAT_STRING "%TimeStamp% [%ThreadID%] %Severity% %Module% - %Message%"
boost::shared_ptr< sinks::synchronous_sink<sinks::text_file_backend> >
LOG_CREATE_SINK(const std::string& strLogFilename, bool fAutoFlush)
{
return logging::add_file_log(
keywords::file_name = strLogFilename,
keywords::open_mode = (std::ios_base::app | std::ios_base::out) & ~std::ios_base::in,
keywords::auto_flush = fAutoFlush,
keywords::format = FORMAT_STRING);
}
questione sembra essere correlato a http://stackoverflow.com/questions/15853981/boost-log-2-0-empty-severity-level- in-log. Ho lo stesso problema, fornendo% Severity% nella stringa di formato insieme a severity_logger non funziona. – SebastianK