97 lines
3.1 KiB
C++
Executable File
97 lines
3.1 KiB
C++
Executable File
/**
|
|
* @RDE_HEADER@
|
|
* Logger handling stuff for NGL(Core|Gui)Application
|
|
* $Id$
|
|
* $HeadURL$
|
|
* $Author$
|
|
*/
|
|
|
|
#include "nglloggerhandler.h"
|
|
#include "ngl_qt_msg_handler.inc"
|
|
|
|
#include <NGLLogger/NGLLoggerBootstrap.h>
|
|
#include <nglsettings/nglsettings_settings.h>
|
|
#include <nglcoreapplication.h>
|
|
|
|
namespace NGL
|
|
{
|
|
|
|
static QByteArray username()
|
|
{
|
|
#ifdef Q_OS_WIN
|
|
return qgetenv("USERNAME");
|
|
#else
|
|
return qgetenv("USER");
|
|
#endif
|
|
}
|
|
|
|
static void setEnvVars()
|
|
{
|
|
// set LOGPATH to the globally configured path
|
|
const QString logPath = NGL::Settings::logPath();
|
|
qputenv("LOG4QT_LOGDIR", logPath.toLocal8Bit());
|
|
qputenv("LOG4QT_USER", username());
|
|
}
|
|
|
|
//----------------------------------------------------------------------------
|
|
void LoggerHandler::createLogger(const QByteArray &baseName, const char *configFileName, bool quiet)
|
|
{
|
|
setEnvVars();
|
|
m_baseLoggerName = baseName;
|
|
|
|
const QString bnStr(QString::fromLatin1(baseName.toLower()));
|
|
const QString logPath = NGL::Settings::logPath();
|
|
m_loggerFilenamePostfix = logPath + QLatin1Char('/') + QString::fromLocal8Bit(username()) + QLatin1Char('_') + bnStr;
|
|
m_loggerFilenamePrefix = QLatin1String(".log");
|
|
|
|
const QString logOutputName = m_loggerFilenamePostfix + m_loggerFilenamePrefix;
|
|
NGL::NGLLoggerBootstrap::createNGLRootLogger(QString::fromLatin1(configFileName), false, logOutputName, quiet);
|
|
|
|
// Qt-Messages abfangen
|
|
qInstallMessageHandler(&qtMsgHandler);
|
|
}
|
|
|
|
//----------------------------------------------------------------------------
|
|
void LoggerHandler::createLogger(const QByteArray &baseName, int exerciseId, int additionalId, bool quiet)
|
|
{
|
|
setEnvVars();
|
|
|
|
const QString bnStr(QString::fromLatin1(baseName.toLower()));
|
|
const QString configFileName = QLatin1String("log4cxx_") + bnStr + QLatin1String(".props");
|
|
const QString logPath = NGL::Settings::logPath();
|
|
m_loggerFilenamePostfix = logPath + QLatin1Char('/') + QString::fromLocal8Bit(username()) + QLatin1Char('_') + bnStr;
|
|
if (exerciseId > 0)
|
|
m_loggerFilenamePostfix += QLatin1Char('_') + QString::number(exerciseId);
|
|
if (additionalId > 0)
|
|
m_loggerFilenamePostfix += QLatin1Char('_') + QString::number(additionalId);
|
|
|
|
m_loggerFilenamePrefix = QLatin1String(".log");
|
|
m_baseLoggerName = baseName + QByteArray(".main");
|
|
|
|
const QString logOutputName = m_loggerFilenamePostfix + m_loggerFilenamePrefix;
|
|
NGL::NGLLoggerBootstrap::createNGLRootLogger(configFileName, false, logOutputName, quiet);
|
|
|
|
// Qt-Messages abfangen
|
|
qInstallMessageHandler(&qtMsgHandler);
|
|
}
|
|
|
|
//----------------------------------------------------------------------------
|
|
NGL::INGLLogger &LoggerHandler::baseLogger() const
|
|
{
|
|
return NGL::NGLLoggerBootstrap::getNGLRootLogger().getNGLLogger(m_baseLoggerName.data());
|
|
}
|
|
|
|
//----------------------------------------------------------------------------
|
|
NGL::INGLLogger &LoggerHandler::logger(const char *loggerName) const
|
|
{
|
|
return NGL::NGLLoggerBootstrap::getNGLRootLogger().getNGLLogger(loggerName);
|
|
}
|
|
|
|
//----------------------------------------------------------------------------
|
|
LoggerHandler *LoggerHandler::getLoggerHandler()
|
|
{
|
|
return dynamic_cast<LoggerHandler*>(QCoreApplication::instance());
|
|
}
|
|
|
|
} // namespace NGL
|