Add formated loging for device detection
Commits merged and amended for code style by Adam Honse <calcprogrammer1@gmail.com>
This commit is contained in:
parent
5a7879415f
commit
4af8614fce
19 changed files with 213 additions and 111 deletions
|
|
@ -2,14 +2,18 @@
|
|||
|
||||
#include <stdarg.h>
|
||||
#include <iostream>
|
||||
#include <iomanip>
|
||||
#include <ctime>
|
||||
|
||||
#include "ResourceManager.h"
|
||||
|
||||
#include "filesystem.h"
|
||||
|
||||
static const char* log_codes[] = {"CRITICAL", "ERROR", "Message", "Warning", "Notice", "[verbose]", "Debug"};
|
||||
static const char* log_codes[] = {"FATAL:", "ERROR:", "Warning:", "Info:", "[verbose]", "Debug:", "Trace:"};
|
||||
|
||||
LogManager::LogManager()
|
||||
{
|
||||
base_clock = clock();
|
||||
}
|
||||
|
||||
LogManager* LogManager::get()
|
||||
|
|
@ -132,7 +136,9 @@ void LogManager::_flush()
|
|||
if(temp_messages[msg]->level <= loglevel)
|
||||
{
|
||||
// Put the timestamp here
|
||||
log_stream << log_codes[temp_messages[msg]->level] << ": ";
|
||||
clock_t counter = temp_messages[msg]->counted_second;
|
||||
log_stream << std::left << std::setw(6) << counter/ ( CLOCKS_PER_SEC / 1000 ) << "|";
|
||||
log_stream << std::left << std::setw(9) << log_codes[temp_messages[msg]->level];
|
||||
log_stream << temp_messages[msg]->buffer;
|
||||
|
||||
if(print_source)
|
||||
|
|
@ -168,7 +174,7 @@ void LogManager::_append(const char* filename, int line, unsigned int level, con
|
|||
| If a critical message occurs, enable source |
|
||||
| printing and set loglevel and verbosity to highest|
|
||||
\*-------------------------------------------------*/
|
||||
if(level == LL_CRITICAL)
|
||||
if(level == LL_FATAL)
|
||||
{
|
||||
print_source = true;
|
||||
loglevel = LL_DEBUG;
|
||||
|
|
@ -193,9 +199,10 @@ void LogManager::_append(const char* filename, int line, unsigned int level, con
|
|||
/*-------------------------------------------------*\
|
||||
| Fill in message information |
|
||||
\*-------------------------------------------------*/
|
||||
mes->level = level;
|
||||
mes->filename = filename;
|
||||
mes->line = line;
|
||||
mes->level = level;
|
||||
mes->filename = filename;
|
||||
mes->line = line;
|
||||
mes->counted_second = clock() - base_clock;
|
||||
|
||||
/*-------------------------------------------------*\
|
||||
| If the message is within the current verbosity, |
|
||||
|
|
@ -212,18 +219,6 @@ void LogManager::_append(const char* filename, int line, unsigned int level, con
|
|||
std::cout << std::endl;
|
||||
}
|
||||
|
||||
/*-------------------------------------------------*\
|
||||
| If the message level is LL_MESSAGE or lower, add |
|
||||
| it to the error queue |
|
||||
\*-------------------------------------------------*/
|
||||
if(level <= LL_MESSAGE)
|
||||
{
|
||||
for(size_t idx = 0; idx < error_callbacks.size(); ++idx)
|
||||
{
|
||||
error_callbacks[idx].first(error_callbacks[idx].second, mes);
|
||||
}
|
||||
}
|
||||
|
||||
/*-------------------------------------------------*\
|
||||
| Add the message to the logfile queue |
|
||||
\*-------------------------------------------------*/
|
||||
|
|
@ -233,6 +228,18 @@ void LogManager::_append(const char* filename, int line, unsigned int level, con
|
|||
| Flush the queues |
|
||||
\*-------------------------------------------------*/
|
||||
_flush();
|
||||
|
||||
/*-------------------------------------------------*\
|
||||
| If the message level is LL_WARNING or lower, add |
|
||||
| it to the error queue |
|
||||
\*-------------------------------------------------*/
|
||||
if(level <= LL_WARNING)
|
||||
{
|
||||
for(size_t idx = 0; idx < error_callbacks.size(); ++idx)
|
||||
{
|
||||
error_callbacks[idx].first(error_callbacks[idx].second, mes);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void LogManager::append(const char* filename, int line, unsigned int level, const char* fmt, ...)
|
||||
|
|
@ -252,14 +259,9 @@ void LogManager::setLoglevel(unsigned int level)
|
|||
| Check that the new log level is valid, otherwise |
|
||||
| set it within the valid range |
|
||||
\*-------------------------------------------------*/
|
||||
if(level < LL_CRITICAL)
|
||||
if(level > LL_TRACE)
|
||||
{
|
||||
level = LL_CRITICAL;
|
||||
}
|
||||
|
||||
if(level > LL_DEBUG)
|
||||
{
|
||||
level = LL_DEBUG;
|
||||
level = LL_TRACE;
|
||||
}
|
||||
|
||||
LOG_DEBUG("Loglevel set to %d", level);
|
||||
|
|
@ -276,14 +278,10 @@ void LogManager::setVerbosity(unsigned int level)
|
|||
| Check that the new verbosity is valid, otherwise |
|
||||
| set it within the valid range |
|
||||
\*-------------------------------------------------*/
|
||||
if(level < LL_CRITICAL)
|
||||
{
|
||||
level = LL_CRITICAL;
|
||||
}
|
||||
|
||||
if(level > LL_DEBUG)
|
||||
if(level > LL_TRACE)
|
||||
{
|
||||
level = LL_DEBUG;
|
||||
level = LL_TRACE;
|
||||
}
|
||||
|
||||
LOG_DEBUG("Verbosity set to %d", level);
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue