Develop Biology
The language of life
bio::log::Engine Class Referenceabstract

#include <Engine.h>

Public Member Functions

 Engine ()
 
virtual ~Engine ()
 
Level FilterGet (Filter filter) const
 
bool FilterPass (Filter filter, Level level) const
 
bool FilterSet (Filter filter, Level level)
 
bool FilterSet (Name filter, Name level)
 
void Log (Filter filter, Level level, const char *format, va_list args)
 
void Log (Filter filter, Level level, const char *format,...)
 
virtual void Output (const std::string &logString)=0
 

Protected Attributes

std::ostringstream m_logMessage
 

Detailed Description

log::Engines are responsible for printing logs. Create your own Engine, if you have your own output schema you'd like to use (e.g. to the screen of a gui instead of to a file or standard out).

Definition at line 37 of file Engine.h.

Constructor & Destructor Documentation

◆ Engine()

bio::log::Engine::Engine ( )

Definition at line 37 of file Engine.cpp.

38{
39 //Set all filters to only log if level is >= Info
40 m_levelFilter.assign(
41 FilterPerspective::Instance().GetNumUsedIds(),
42 level::Info());
43}

References bio::log::level::Info().

◆ ~Engine()

bio::log::Engine::~Engine ( )
virtual

Definition at line 45 of file Engine.cpp.

46{
47
48}

Member Function Documentation

◆ FilterGet()

Level bio::log::Engine::FilterGet ( Filter  filter) const
Parameters
filter
Returns
Current level for the given filter.

Definition at line 135 of file Engine.cpp.

136{
137 return m_levelFilter[filter];
138}

◆ FilterPass()

bool bio::log::Engine::FilterPass ( Filter  filter,
Level  level 
) const
Parameters
filter
level
Returns
true if level is enabled for the filter, false if disabled; false if filter is ALL or out of range; false if level is out of range.

Definition at line 108 of file Engine.cpp.

112{
113 return level >= m_levelFilter[filter];
114}

Referenced by Log(), and bio::log::Writer::Log().

◆ FilterSet() [1/2]

bool bio::log::Engine::FilterSet ( Filter  filter,
Level  level 
)

Change filter level for the filter

Parameters
filterwhat to affect; use ALL to set the level of all filters.
levelvalue to set for the given filter (Log() calls must be >= to this to be seen).
Returns
true on success, false otherwise.

Definition at line 116 of file Engine.cpp.

120{
121 m_levelFilter[filter] = level;
122 return true; //SUCCESS
123}

Referenced by FilterSet().

◆ FilterSet() [2/2]

bool bio::log::Engine::FilterSet ( Name  filter,
Name  level 
)

Change filter level for the filter

Parameters
filterwhat to affect; use ALL to set the level of all filters.
levelvalue to set for the given filter (Log() calls must be >= to this to be seen).
Returns
true on success, false otherwise.

Definition at line 125 of file Engine.cpp.

129{
130 return FilterSet(
131 FilterPerspective::Instance().GetIdFromName(filter),
132 LevelPerspective::Instance().GetIdFromName(level));
133}
bool FilterSet(Filter filter, Level level)
Definition: Engine.cpp:116

References FilterSet().

◆ Log() [1/2]

void bio::log::Engine::Log ( Filter  filter,
Level  level,
const char *  format,
va_list  args 
)

Generates a log string and calls Output (caller is responsible for using filters).

Parameters
filter
level
format
args

Definition at line 50 of file Engine.cpp.

56{
58 filter,
59 level
60 ), ,
61 return);
62
63 char str[BIO_LOG_PRINTF_MAX_LINE_SIZE + 1];
64
65 vsnprintf(
66 str,
67 sizeof(str),
68 format,
69 args
70 );
71 va_end(args);
73
74 m_logMessage.clear();
75 m_logMessage.str(""); //TODO: is seekp good enough? what is faster?
76
77 m_logMessage << physical::GetCurrentTimestamp() << " " << FilterPerspective::Instance().GetNameFromId(filter) << " " << LevelPerspective::Instance().GetNameFromId(level) << ": " << str << "\n";
78 Output(m_logMessage.str());
79}
#define BIO_SANITIZE_AT_SAFETY_LEVEL_2(test, success, failure)
std::ostringstream m_logMessage
Definition: Engine.h:131
virtual void Output(const std::string &logString)=0
bool FilterPass(Filter filter, Level level) const
Definition: Engine.cpp:108
#define BIO_LOG_PRINTF_MAX_LINE_SIZE
Definition: Macros.h:24
Timestamp GetCurrentTimestamp()
Definition: Time.cpp:41

References BIO_LOG_PRINTF_MAX_LINE_SIZE, BIO_SANITIZE_AT_SAFETY_LEVEL_2, FilterPass(), bio::physical::GetCurrentTimestamp(), m_logMessage, and Output().

Referenced by bio::log::Writer::ExternalLog(), Log(), and bio::log::Writer::Log().

◆ Log() [2/2]

void bio::log::Engine::Log ( Filter  filter,
Level  level,
const char *  format,
  ... 
)

Create a log string that will be Output(). *this can be invoked directly or via Writer::ExternalLog Both calls will have the same effect.

Parameters
filter
level
format
...

Definition at line 81 of file Engine.cpp.

87{
88 if (FilterPass(
89 filter,
90 level
91 ))
92 {
93 return; //filter off, don't log
94 }
95
96 va_list args;
97 va_start(args,
98 format);
99 Log(
100 filter,
101 level,
102 format,
103 args
104 );
105 va_end(args);
106}
void Log(Filter filter, Level level, const char *format, va_list args)
Definition: Engine.cpp:50

References FilterPass(), and Log().

◆ Output()

virtual void bio::log::Engine::Output ( const std::string &  logString)
pure virtual

Required override for outputting logs. logString will include a newline (
) character.

Parameters
logStringfully prepared text to be logged.

Referenced by Log().

Member Data Documentation

◆ m_logMessage

std::ostringstream bio::log::Engine::m_logMessage
protected

This should not need to be accessed from children, as it is passed to Output but is here for convenience. TODO: see if there is a faster data type for logging.

Definition at line 131 of file Engine.h.

Referenced by Log().


The documentation for this class was generated from the following files: