Commit c2d87043 authored by Dirk Wilden's avatar Dirk Wilden

added a logfile

git-svn-id: http://www.openflipper.org/svnrepo/OpenFlipper/branches/Free@2830 383ad7c9-94d9-4d36-a494-682f7c89f535
parent 8f370c8e
......@@ -106,6 +106,11 @@ Core() :
set_random_base_color_(true),
coreWidget_(0)
{
//init logFile
logStream_ = 0;
logFile_ = 0;
OpenFlipper::Options::logFileEnabled(true);
//init nodes
root_node_scenegraph_ = new ACG::SceneGraph::SeparatorNode(0, "SceneGraph Root Node");
root_node_ = new ACG::SceneGraph::SeparatorNode(root_node_scenegraph_, "Data Root Node");
......@@ -199,6 +204,8 @@ Core::init() {
connect(newlog,SIGNAL(log(Logtype, QString )),this,SLOT(slotLog(Logtype, QString )),Qt::DirectConnection);
// connection to file logger
connect(newlog,SIGNAL(log(Logtype, QString )),this,SLOT(slotLogToFile(Logtype, QString )),Qt::DirectConnection);
// ======================================================================
// Create a logger class for CoreWidget
......@@ -214,6 +221,8 @@ Core::init() {
// Connect it to the Master logger
connect(widgetlog,SIGNAL(log(Logtype, QString )),coreWidget_,SLOT(slotLog(Logtype, QString )),Qt::DirectConnection);
connect(widgetlog,SIGNAL(log(Logtype, QString )),this,SLOT(slotLog(Logtype, QString )),Qt::DirectConnection);
// connection to file logger
connect(widgetlog,SIGNAL(log(Logtype, QString )),this,SLOT(slotLogToFile(Logtype, QString )),Qt::DirectConnection);
}
// ======================================================================
......@@ -230,7 +239,8 @@ Core::init() {
connect(newlog,SIGNAL(log(Logtype, QString )),coreWidget_,SLOT(slotLog(Logtype, QString )),Qt::DirectConnection);
connect(newlog,SIGNAL(log(Logtype, QString )),this,SLOT(slotLog(Logtype, QString )),Qt::DirectConnection);
// connection to file logger
connect(newlog,SIGNAL(log(Logtype, QString )),this,SLOT(slotLogToFile(Logtype, QString )),Qt::DirectConnection);
// ======================================================================
// Catch OpenMesh omout logs with an own Logger
......@@ -246,7 +256,8 @@ Core::init() {
connect(newlog,SIGNAL(log(Logtype, QString )),coreWidget_,SLOT(slotLog(Logtype, QString )),Qt::DirectConnection);
connect(newlog,SIGNAL(log(Logtype, QString )),this,SLOT(slotLog(Logtype, QString )),Qt::DirectConnection);
// connection to file logger
connect(newlog,SIGNAL(log(Logtype, QString )),this,SLOT(slotLogToFile(Logtype, QString )),Qt::DirectConnection);
// ======================================================================
// Catch OpenMesh omlog logs with an own Logger
......@@ -261,6 +272,8 @@ Core::init() {
connect(newlog,SIGNAL(log(Logtype, QString )),coreWidget_,SLOT(slotLog(Logtype, QString )),Qt::DirectConnection);
connect(newlog,SIGNAL(log(Logtype, QString )),this,SLOT(slotLog(Logtype, QString )),Qt::DirectConnection);
// connection to file logger
connect(newlog,SIGNAL(log(Logtype, QString )),this,SLOT(slotLogToFile(Logtype, QString )),Qt::DirectConnection);
// ======================================================================
// Log Scripting stuff through a separate logger
......@@ -274,7 +287,9 @@ Core::init() {
connect(newlog,SIGNAL(log(Logtype, QString )),coreWidget_,SLOT(slotLog(Logtype, QString )),Qt::DirectConnection);
connect(newlog,SIGNAL(log(Logtype, QString )),this,SLOT(slotLog(Logtype, QString )),Qt::DirectConnection);
// connection to file logger
connect(newlog,SIGNAL(log(Logtype, QString )),this,SLOT(slotLogToFile(Logtype, QString )),Qt::DirectConnection);
// connect signal to logger
connect(this,SIGNAL(scriptLog(QString )),newlog,SLOT(slotLog(QString )),Qt::DirectConnection);
......@@ -638,6 +653,10 @@ Core::writeOnExit() {
void Core::slotExit() {
writeOnExit();
if (logFile_)
logFile_->close();
qApp->quit();
}
......@@ -656,7 +675,41 @@ bool Core::add_sync_host(const QString& _name)
return false;
}
/// log to file
void Core::slotLogToFile(Logtype _type, QString _message){
if (!OpenFlipper::Options::logFileEnabled())
return;
if (logStream_ == 0){
//check if a logfile has been specified
if (OpenFlipper::Options::logFile() == "")
OpenFlipper::Options::logFile(QDir::home().absolutePath() + OpenFlipper::Options::dirSeparator() + ".OpenFlipper" +
OpenFlipper::Options::dirSeparator() + "OpenFlipper.log");
logFile_ = new QFile( OpenFlipper::Options::logFile() );
if ( logFile_->open(QFile::WriteOnly) ) {
logStream_ = new QTextStream (logFile_);
}else{
emit log(LOGERR, "Unable to open logfile!");
return;
}
}
switch (_type) {
case LOGINFO:
(*logStream_) << "INFO:"; break;
case LOGOUT:
(*logStream_) << "OUT :"; break;
case LOGWARN:
(*logStream_) << "WARN:"; break;
case LOGERR:
(*logStream_) << "ERR :"; break;
}
(*logStream_) << _message << "\n" << flush;
}
//=============================================================================
......@@ -469,6 +469,16 @@ private:
/// Console logger
void slotLog(Logtype _type, QString _message);
/// log to file
void slotLogToFile(Logtype _type, QString _message);
private:
///stream for logging to file
QTextStream* logStream_;
///logfile
QFile* logFile_;
public :
void scriptLogFunction( QString _output);
......
......@@ -202,6 +202,20 @@ void Core::readApplicationOptions(INIFile& _ini) {
std::vector< QString > draw_modes;
if( _ini.get_entry(draw_modes, "Options", "StandardDrawModes") )
standard_draw_mode_ = ListToDrawMode(draw_modes);
//============================================================================
// Load logFile status
//============================================================================
bool logFileEnabled = true;
if( _ini.get_entry(logFileEnabled, "Options", "LogFileEnabled") )
OpenFlipper::Options::logFileEnabled(logFileEnabled);
//============================================================================
// Load logFile location
//============================================================================
QString logFile = "";
if( _ini.get_entry(logFile, "Options", "LogFileLocation") )
OpenFlipper::Options::logFile(logFile);
}
}
......@@ -258,6 +272,13 @@ void Core::writeApplicationOptions(INIFile& _ini) {
//write default ToolboxMode
_ini.add_entry("Options","DefaultToolboxMode",OpenFlipper::Options::defaultToolboxMode() );
//============================================================================
// logfile
//============================================================================
//write logfile status
_ini.add_entry("Options","LogFileEnabled",OpenFlipper::Options::logFileEnabled() );
//write logfile location
_ini.add_entry("Options","LogFileLocation",OpenFlipper::Options::logFile() );
//============================================================================
//dontLoad Plugins
......
......@@ -459,6 +459,9 @@ void Core::loadPlugin(QString filename, bool silent){
// connection to console logger
connect(newlog,SIGNAL(log(Logtype, QString )),this,SLOT(slotLog(Logtype, QString )),Qt::DirectConnection);
// connection to file logger
connect(newlog,SIGNAL(log(Logtype, QString )),this,SLOT(slotLogToFile(Logtype, QString )),Qt::DirectConnection);
// connection to external plugin logger
if ( checkSlot(plugin,"logOutput(Logtype,QString)") )
connect(this,SIGNAL(externalLog(Logtype,QString)), plugin, SLOT(logOutput(Logtype,QString)) ) ;
......
......@@ -97,10 +97,23 @@ void Core::applyOptions(){
coreWidget_->dockViewMode_->setVisible(false);
}
//setup logFile
if (logFile_ != 0){
if (OpenFlipper::Options::logFile() != logFile_->fileName() ){
logFile_->close();
delete logFile_;
logFile_ = 0;
if (logStream_ != 0){
delete logStream_;
logStream_ = 0;
}
}
}
updateView();
}
}
void Core::saveOptions(){
......
......@@ -117,6 +117,12 @@ static bool logToConsole_ = false;
/// Extra debug info
static bool debug_ = false;
/// enable logging to file
static bool logFileEnabled_;
/// logfile location (path + filename)
static QString logFile_;
/// last used DataType
static QString lastDataType_ = "Triangle Mesh";
......@@ -429,7 +435,21 @@ void debug(bool _debug ) {
debug_ = _debug;
}
void logFileEnabled(bool _enable ){
logFileEnabled_ = _enable;
}
bool logFileEnabled(){
return logFileEnabled_;
}
void logFile(QString _filename){
logFile_ = _filename;
}
QString logFile(){
return logFile_;
}
bool backupEnabled( ) {
return enableBackup_;
......
......@@ -408,6 +408,22 @@ bool iconDir(QString _dir);
DLLEXPORT
void debug(bool _debug );
/// enable logging to file
DLLEXPORT
void logFileEnabled(bool _enable );
/// is logging to file enabled?
DLLEXPORT
bool logFileEnabled();
/// logfile location (path + filename)
DLLEXPORT
void logFile(QString _filename);
/// logfile location (path + filename)
DLLEXPORT
QString logFile();
/** @} */
//===========================================================================
......
......@@ -57,6 +57,10 @@ void OptionsWidget::showEvent ( QShowEvent * event ) {
splash->setChecked( OpenFlipper::Options::splash() );
toolbox->setChecked( !OpenFlipper::Options::hideToolbox() );
logger->setChecked( !OpenFlipper::Options::hideLogger() );
enableLogFile->setChecked( OpenFlipper::Options::logFileEnabled() );
//paths
logFile->setText( OpenFlipper::Options::logFile() );
//viewer
backfaceCulling->setChecked( OpenFlipper::Options::backfaceCulling() );
......@@ -118,6 +122,10 @@ void OptionsWidget::slotApply() {
OpenFlipper::Options::splash( splash->isChecked() );
OpenFlipper::Options::hideToolbox( !toolbox->isChecked() );
OpenFlipper::Options::hideLogger( !logger->isChecked() );
OpenFlipper::Options::logFileEnabled( enableLogFile->isChecked() );
//paths
OpenFlipper::Options::logFile( logFile->text() );
//viewer
OpenFlipper::Options::backfaceCulling( backfaceCulling->isChecked() );
......
......@@ -22,7 +22,7 @@
<string/>
</property>
<property name="currentIndex" >
<number>2</number>
<number>0</number>
</property>
<property name="usesScrollButtons" >
<bool>true</bool>
......@@ -92,6 +92,26 @@
</property>
</widget>
</item>
<item>
<widget class="Line" name="line" >
<property name="orientation" >
<enum>Qt::Horizontal</enum>
</property>
</widget>
</item>
<item>
<widget class="QCheckBox" name="enableLogFile" >
<property name="toolTip" >
<string>Enable the logfile</string>
</property>
<property name="statusTip" >
<string>Enable the logfile</string>
</property>
<property name="text" >
<string>Logfile enabled</string>
</property>
</widget>
</item>
<item>
<spacer name="verticalSpacer" >
<property name="orientation" >
......@@ -107,6 +127,30 @@
</item>
</layout>
</widget>
<widget class="QWidget" name="paths" >
<attribute name="title" >
<string>Paths</string>
</attribute>
<layout class="QFormLayout" name="formLayout_2" >
<item row="0" column="0" >
<widget class="QLabel" name="label" >
<property name="text" >
<string>Logfile:</string>
</property>
</widget>
</item>
<item row="0" column="1" >
<widget class="QLineEdit" name="logFile" >
<property name="toolTip" >
<string>filename (including path) of the logfile</string>
</property>
<property name="statusTip" >
<string>filename (including path) of the logfile</string>
</property>
</widget>
</item>
</layout>
</widget>
<widget class="QWidget" name="viewer" >
<property name="geometry" >
<rect>
......
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