-
Notifications
You must be signed in to change notification settings - Fork 24
/
Copy pathVlmcDebug.cpp
121 lines (111 loc) · 4.19 KB
/
VlmcDebug.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
/*****************************************************************************
* VlmcDebug.cpp: Debug tools for VLMC
*****************************************************************************
* Copyright (C) 2008-2010 VideoLAN
*
* Authors: Hugo Beauzee-Luyssen <[email protected]>
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation; either version 2
* of the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
*****************************************************************************/
#include <QCoreApplication>
#include <QStringList>
#include "SettingsManager.h"
#include "VlmcDebug.h"
VlmcDebug::VlmcDebug() : m_logFile( NULL )
{
//setup log level :
QStringList args = qApp->arguments();
if ( args.indexOf( QRegExp( "-vvv*" ) ) >= 0 )
SettingsManager::getInstance()->setImmediateValue( "private/LogLevel", QtDebugMsg, SettingsManager::Vlmc );
else if ( args.contains( "-v" ) == true )
SettingsManager::getInstance()->setImmediateValue( "private/LogLevel", QtWarningMsg, SettingsManager::Vlmc );
else
SettingsManager::getInstance()->setImmediateValue( "private/LogLevel", QtCriticalMsg, 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
SettingsManager::getInstance()->setImmediateValue( "private/LogFile", logFile, SettingsManager::Vlmc );
}
// QVariant setVal = SettingsManager::getInstance()->value( "private/LogFile", "log.vlmc", SettingsManager::Vlmc );
// SettingsManager::getInstance()->watchValue( "private/LogFile", this,
// SLOT( logFileChanged( const QVariant& ) ),
// SettingsManager::Vlmc );
// QObject::connect( qApp,
// SIGNAL( aboutToQuit() ),
// this,
// SLOT( deleteLater() ) );
// QString logFile = setVal.toString();
// if ( logFile.isEmpty() == false )
// {
// m_logFile = new QFile( logFile );
// m_logFile->open( QFile::WriteOnly | QFile::Truncate );
// }
}
VlmcDebug::~VlmcDebug()
{
delete m_logFile;
}
void VlmcDebug::setup()
{
// qInstallMsgHandler( VlmcDebug::vlmcMessageHandler );
}
void VlmcDebug::logFileChanged( const QVariant& logFileV )
{
QString logFile = logFileV.toString();
if ( logFile.isEmpty() == true )
{
m_logFile->close();
return ;
}
if ( logFile == m_logFile->fileName() )
{
fprintf( stderr, "Trying to use the same log file. Nothing will be done" );
return ;
}
m_logFile->close();
m_logFile->setFileName( logFile );
m_logFile->open( QFile::Append | QFile::Truncate );
}
void VlmcDebug::vlmcMessageHandler( QtMsgType type, const char* msg )
{
if ( VlmcDebug::getInstance()->m_logFile != NULL )
{
VlmcDebug::getInstance()->m_logFile->write( msg );
VlmcDebug::getInstance()->m_logFile->write( "\n" );
}
// if ( type != QtFatalMsg
// && type < SettingsManager::getInstance()->value( "private/LogLevel", QtDebugMsg, SettingsManager::Vlmc ).toInt() )
// return ;
switch ( type )
{
case QtDebugMsg:
fprintf(stderr, "%s\n", msg);
break;
case QtWarningMsg:
fprintf(stderr, "%s\n", msg);
break;
case QtCriticalMsg:
fprintf(stderr, "%s\n", msg);
break;
case QtFatalMsg:
fprintf(stderr, "%s\n", msg);
abort();
}
}