[vlmc-devel] VlmcDebug: Re-enable file logging
Hugo Beauzée-Luyssen
git at videolan.org
Sat Feb 8 18:48:25 CET 2014
vlmc | branch: master | Hugo Beauzée-Luyssen <hugo at beauzee.fr> | Sat Feb 8 17:10:18 2014 +0200| [42d286f1c0188af8aef9e3158080b14f36418a29] | committer: Hugo Beauzée-Luyssen
VlmcDebug: Re-enable file logging
> http://git.videolan.org/gitweb.cgi/vlmc.git/?a=commit;h=42d286f1c0188af8aef9e3158080b14f36418a29
---
src/Tools/VlmcDebug.cpp | 51 ++++++++++++++++++++++++++++++++---------------
src/Tools/VlmcDebug.h | 8 +++++---
2 files changed, 40 insertions(+), 19 deletions(-)
diff --git a/src/Tools/VlmcDebug.cpp b/src/Tools/VlmcDebug.cpp
index 31b757f..b8262c1 100644
--- a/src/Tools/VlmcDebug.cpp
+++ b/src/Tools/VlmcDebug.cpp
@@ -20,12 +20,14 @@
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
*****************************************************************************/
-#include <QCoreApplication>
-#include <QStringList>
-
#include "SettingsManager.h"
#include "VlmcDebug.h"
+#include <QCoreApplication>
+#include <QDesktopServices>
+#include <QStringList>
+#include <QThread>
+
VlmcDebug::VlmcDebug() : m_logFile( NULL )
{
//setup log level :
@@ -48,16 +50,18 @@ VlmcDebug::VlmcDebug() : m_logFile( NULL )
settingsManager->watchValue( "private/LogLevel", this, SLOT(logLevelChanged( const QVariant& )),
SettingsManager::Vlmc, Qt::DirectConnection );
-// int pos = args.indexOf( QRegExp( "--logfile=.*" ) );
-// if ( pos > 0 )
-// {
-// QString arg = args[pos];
-// QString logFile = arg.mid( 10 );
-// if ( logFile.length() <= 0 )
-// qWarning() << tr("Invalid value supplied for argument --logfile" );
-// else
-// SettingsManager::getInstance()->setValue( "private/LogFile", logFile, SettingsManager::Vlmc );
-// }
+ int pos = args.indexOf( QRegExp( "--logfile=.*" ) );
+ if ( pos > 0 )
+ {
+ QString arg = args[pos];
+ QString logFile = arg.mid( 10 );
+ if ( logFile.length() <= 0 )
+ qWarning() << tr("Invalid value supplied for argument --logfile" );
+ else
+ {
+ m_logFile = fopen(logFile.toLocal8Bit().data(), "w");
+ }
+ }
// QVariant setVal = SettingsManager::getInstance()->value( "private/LogFile", "log.vlmc", SettingsManager::Vlmc );
@@ -78,7 +82,8 @@ VlmcDebug::VlmcDebug() : m_logFile( NULL )
VlmcDebug::~VlmcDebug()
{
- delete m_logFile;
+ if ( m_logFile )
+ fclose( m_logFile );
}
void
@@ -97,16 +102,30 @@ VlmcDebug::logLevelChanged( const QVariant &logLevel )
m_currentLogLevel = (VlmcDebug::LogLevel)logLevel.toInt();
}
+/*********************************************************************
+* Don't use anything which might use qDebug/qWarning/... below here. *
+*********************************************************************/
+
+void
+VlmcDebug::writeToFile(const char *msg)
+{
+ flockfile( m_logFile );
+ fputs( msg, m_logFile );
+ fputc( '\n', m_logFile );
+ funlockfile( m_logFile );
+}
+
void
VlmcDebug::vlmcMessageHandler( QtMsgType type, const char* msg )
{
//FIXME: This is ok as long as we guarantee no log message will arrive after
// we uninstall the hook
+
VlmcDebug* self = VlmcDebug::getInstance();
if ( self->m_logFile != NULL )
{
- self->m_logFile->write( msg );
- self->m_logFile->write( "\n" );
+ //FIXME: Messages are not guaranteed to arrive in order
+ self->writeToFile(msg);
}
if ( (int)type < (int)self->m_currentLogLevel )
return ;
diff --git a/src/Tools/VlmcDebug.h b/src/Tools/VlmcDebug.h
index c76c603..8344d30 100644
--- a/src/Tools/VlmcDebug.h
+++ b/src/Tools/VlmcDebug.h
@@ -25,7 +25,8 @@
#include <QObject>
#include <QDebug>
-#include <QFile>
+
+#include <cstdio>
#include "Singleton.hpp"
@@ -45,7 +46,7 @@ class VlmcDebug : public QObject, public Singleton<VlmcDebug>
Debug = QtDebugMsg,
Verbose = QtWarningMsg,
// This means both qCritical() & qFatal() will be displayed in quiet mode
- Quiet = QtCriticalMsg,
+ Quiet = QtCriticalMsg
};
static void vlmcMessageHandler( QtMsgType type, const char* msg );
@@ -53,8 +54,9 @@ class VlmcDebug : public QObject, public Singleton<VlmcDebug>
private:
VlmcDebug();
virtual ~VlmcDebug();
+ void writeToFile(const char* msg);
- QFile* m_logFile;
+ FILE* m_logFile;
LogLevel m_currentLogLevel;
private slots:
More information about the Vlmc-devel
mailing list