summaryrefslogblamecommitdiffstats
path: root/src/loggerengine.cpp
blob: 5638908acbee7aebab047ef451b3d71ebf4029ba (plain) (tree)


































































                                                                                                     
#include "loggerengine.h"

// --------------------------------------------------------------------------------------------------
//                   Custom Logger Engine for debugging on framebuffer
//---------------------------------------------------------------------------------------------------
LoggerEngine_fb::LoggerEngine_fb(QTextEdit *parent) : QxtLoggerEngine(){
	// TODO: silly parent storing ... to change!
	_debugConsole = parent;
	_initialized = false;
	setLogLevelsEnabled(QxtLogger::DebugLevel);
	enableLogging();
}
LoggerEngine_fb::~LoggerEngine_fb(){}

void LoggerEngine_fb::initLoggerEngine(){
	_initialized = true;
	return;
}

void LoggerEngine_fb::killLoggerEngine(){return;}

void LoggerEngine_fb::setLogLevelEnabled(QxtLogger::LogLevels level, bool enable){
    QxtLoggerEngine::setLogLevelsEnabled(level, enable);
    if (!enable) QxtLoggerEngine::setLogLevelsEnabled(QxtLogger::DebugLevel);
}
bool LoggerEngine_fb::isInitialized() const{
	return _initialized;
}

void LoggerEngine_fb::writeFormatted(QxtLogger::LogLevel level, const QList<QVariant> & msgs){
	// TODO: handle different log levels
	if (msgs.isEmpty()) return;
	Q_FOREACH(const QVariant& out, msgs)
	{
		if (!out.isNull())
			_debugConsole->insertPlainText(out.toString());
	}
	_debugConsole->insertPlainText(QString("\n"));
	// autoscroll
	QTextCursor c = _debugConsole->textCursor();
	c.movePosition(QTextCursor::End);
	_debugConsole->setTextCursor(c);
}
//---------------------------------------------------------------------------------------------------
//                              Modified QxtBasicSTDLoggerEngine
//---------------------------------------------------------------------------------------------------
LoggerEngine_std::LoggerEngine_std() : QxtBasicSTDLoggerEngine(){}

LoggerEngine_std::~LoggerEngine_std(){}

void LoggerEngine_std::writeToStdErr(const QString& str_level, const QList<QVariant> &msgs){
	if (msgs.isEmpty()) return;
	QString header = '[' + QTime::currentTime().toString("hh:mm:ss.zzz") + "] ";
    QTextStream* errstream = stdErrStream();
    Q_ASSERT(errstream);
    *errstream << header;
    Q_FOREACH(const QVariant& out, msgs)
    {
    	if (!out.isNull())
        	*errstream << out.toString();
    }
    *errstream << endl;
}
void LoggerEngine_std::writeToStdOut(const QString& level, const QList<QVariant> & msgs){
	// reimplementing this is needed for compiling,
	// we only need write to std::err, so this function is not needed
}