Commit 9879871c authored by Hugo Beauzée-Luyssen's avatar Hugo Beauzée-Luyssen

VlmcDebug: Allow loglevel to change dynamicly

parent ef8b63a7
...@@ -29,7 +29,13 @@ ...@@ -29,7 +29,13 @@
VlmcDebug::VlmcDebug() : m_logFile( NULL ) VlmcDebug::VlmcDebug() : m_logFile( NULL )
{ {
//setup log level : //setup log level :
VLMC_CREATE_PRIVATE_PREFERENCE_INT( "private/LogLevel", 0 ); {
SettingValue* logLevel = VLMC_CREATE_PREFERENCE( SettingValue::Int, "private/LogLevel", (int)VlmcDebug::Quiet,
"", "", SettingValue::Private | SettingValue::Clamped );
logLevel->setLimits((int)Debug, (int)Verbose);
// Purposedly destroying the setting value, as we need to use the manager for other operations.
//FIXME: Actually I'm not sure for setting the value since this is a private variable.
}
QStringList args = qApp->arguments(); QStringList args = qApp->arguments();
if ( args.indexOf( QRegExp( "-vv+" ) ) >= 0 ) if ( args.indexOf( QRegExp( "-vv+" ) ) >= 0 )
m_currentLogLevel = VlmcDebug::Debug; m_currentLogLevel = VlmcDebug::Debug;
...@@ -37,7 +43,10 @@ VlmcDebug::VlmcDebug() : m_logFile( NULL ) ...@@ -37,7 +43,10 @@ VlmcDebug::VlmcDebug() : m_logFile( NULL )
m_currentLogLevel = VlmcDebug::Verbose; m_currentLogLevel = VlmcDebug::Verbose;
else else
m_currentLogLevel = VlmcDebug::Quiet; m_currentLogLevel = VlmcDebug::Quiet;
SettingsManager::getInstance()->setValue( "private/LogLevel", m_currentLogLevel, SettingsManager::Vlmc ); SettingsManager* settingsManager = SettingsManager::getInstance();
settingsManager->setValue( "private/LogLevel", m_currentLogLevel, SettingsManager::Vlmc );
settingsManager->watchValue( "private/LogLevel", this, SLOT(logLevelChanged( const QVariant& )),
SettingsManager::Vlmc, Qt::DirectConnection );
// int pos = args.indexOf( QRegExp( "--logfile=.*" ) ); // int pos = args.indexOf( QRegExp( "--logfile=.*" ) );
// if ( pos > 0 ) // if ( pos > 0 )
...@@ -97,11 +106,22 @@ VlmcDebug::logFileChanged( const QVariant& logFileV ) ...@@ -97,11 +106,22 @@ VlmcDebug::logFileChanged( const QVariant& logFileV )
m_logFile->open( QFile::Append | QFile::Truncate ); m_logFile->open( QFile::Append | QFile::Truncate );
} }
void
VlmcDebug::logLevelChanged( const QVariant &logLevel )
{
Q_ASSERT_X(logLevel.toInt() >= (int)VlmcDebug::Debug &&
logLevel.toInt() <= (int)VlmcDebug::Quiet,
"Setting log level", "Invalid value for log level");
m_currentLogLevel = (VlmcDebug::LogLevel)logLevel.toInt();
}
void void
VlmcDebug::vlmcMessageHandler( QtMsgType type, const char* msg ) VlmcDebug::vlmcMessageHandler( QtMsgType type, const char* msg )
{ {
//FIXME: This is ok as long as we guarantee no log messages will happen after we //FIXME: This is ok as long as we guarantee no log message will arrive after
// uninstall the hook // we uninstall the hook
VlmcDebug* self = VlmcDebug::getInstance(); VlmcDebug* self = VlmcDebug::getInstance();
if ( self->m_logFile != NULL ) if ( self->m_logFile != NULL )
{ {
......
...@@ -59,6 +59,7 @@ class VlmcDebug : public QObject, public Singleton<VlmcDebug> ...@@ -59,6 +59,7 @@ class VlmcDebug : public QObject, public Singleton<VlmcDebug>
private slots: private slots:
void logFileChanged( const QVariant& logFile ); void logFileChanged( const QVariant& logFile );
void logLevelChanged( const QVariant& logLevel );
friend class Singleton<VlmcDebug>; friend class Singleton<VlmcDebug>;
}; };
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment