3#include <Core/RaCore.hpp>
35 static TLogLevel& ReportingLevel();
37 static TLogLevel FromString(
const std::string& level );
44 Log& operator=(
const Log& );
52 os <<
"- " << NowTime();
53 os <<
" " << ToString( level ) <<
": ";
54 os <<
std::string( level > logDEBUG ? level - logDEBUG : 0,
'\t' );
61 T::Output( os.str() );
65TLogLevel& Log<T>::ReportingLevel() {
66 static TLogLevel reportingLevel = logDEBUG4;
67 return reportingLevel;
72 static const char*
const buffer[] = {
73 "ERROR",
"WARNING",
"INFO",
"DEBUG",
"DEBUG1",
"DEBUG2",
"DEBUG3",
"DEBUG4" };
78TLogLevel Log<T>::FromString(
const std::string& level ) {
79 if ( level ==
"DEBUG4" ) {
return logDEBUG4; }
80 if ( level ==
"DEBUG3" ) {
return logDEBUG3; }
81 if ( level ==
"DEBUG2" ) {
return logDEBUG2; }
82 if ( level ==
"DEBUG1" ) {
return logDEBUG1; }
83 if ( level ==
"DEBUG" ) {
return logDEBUG; }
84 if ( level ==
"INFO" ) {
return logINFO; }
85 if ( level ==
"WARNING" ) {
return logWARNING; }
86 if ( level ==
"ERROR" ) {
return logERROR; }
87 Log<T>().Get( logWARNING ) <<
"Unknown logging level '" << level
88 <<
"'. Using INFO level as default.";
95 static FILE*& Stream();
99inline FILE*& Output2FILE::Stream() {
100 static FILE* pStream = stderr;
104inline void Output2FILE::Output(
const std::string& msg ) {
105 FILE* pStream = Stream();
106 if ( !pStream ) {
return; }
111class FILELog :
public Log<Output2FILE>
118 ON_ASSERT(
int ok = )
std::strftime( buffer, 100, "%X",
std::localtime( &t ) );
119 CORE_ASSERT( ok, "Increase buffer size." );
120 std::
string result( buffer );
130#ifndef FILELOG_MAX_LEVEL
132# define FILELOG_MAX_LEVEL Ra::Core::Utils::logDEBUG4
134# define FILELOG_MAX_LEVEL Ra::Core::Utils::logINFO
138#define FILE_LOG( level ) \
139 if ( level > FILELOG_MAX_LEVEL ) \
141 else if ( level > Ra::Core::Utils::FILELog::ReportingLevel() || \
142 !Ra::Core::Utils::Output2FILE::Stream() ) \
145 Ra::Core::Utils::FILELog().Get( level )
148# define LOG( level ) FILE_LOG( Ra::Core::Utils::TLogLevel( FILELOG_MAX_LEVEL + 1 ) )
150# define LOG( level ) FILE_LOG( level )
hepler function to manage enum as underlying types in VariableSet