Commit ffbce869 authored by Julien Wintz's avatar Julien Wintz
Browse files

Reverting logging framework.

parent 6d23af4e
......@@ -24,6 +24,7 @@ set(dtk_INCLUDE_DIRS
"@CMAKE_CURRENT_SOURCE_DIR@"
"@CMAKE_CURRENT_SOURCE_DIR@/include"
"@CMAKE_CURRENT_SOURCE_DIR@/src"
"@CMAKE_CURRENT_SOURCE_DIR@/src/dtkLog"
"@CMAKE_CURRENT_SOURCE_DIR@/src/dtkCore"
"@CMAKE_CURRENT_SOURCE_DIR@/src/dtkDistributed"
"@CMAKE_CURRENT_SOURCE_DIR@/src/dtkMath"
......
......@@ -104,7 +104,7 @@ int dtkComposerEvaluatorProcess::exec(void)
{
if (!d->factory) {
dtkCritical() << "No factory set ! abort process execution";
dtkError() << "No factory set ! abort process execution";
return 1;
}
......@@ -128,7 +128,7 @@ int dtkComposerEvaluatorProcess::exec(void)
}
if (new_composition && composition.isEmpty()) {
dtkCritical() << "Empty composition, abort" ;
dtkError() << "Empty composition, abort" ;
return 1;
}
......@@ -141,7 +141,7 @@ int dtkComposerEvaluatorProcess::exec(void)
spawn->setInternalCommunicator(d->comm);
spawn->setApplication(d->application);
} else {
dtkCritical() << "Can't find spawn node in composition, abort";
dtkError() << "Can't find spawn node in composition, abort";
return 1;
}
}
......
......@@ -132,7 +132,7 @@ int dtkComposerEvaluatorSlave::exec(void)
{
if (!d->factory) {
dtkCritical() << "No factory set ! abort slave execution";
dtkError() << "No factory set ! abort slave execution";
return 1;
}
......@@ -169,7 +169,7 @@ int dtkComposerEvaluatorSlave::exec(void)
this->communicator()->flush();
this->communicator()->socket()->setParent(0);
} else {
dtkCritical() << "Can't connect to server" << d->server;
dtkError() << "Can't connect to server" << d->server;
return 1;
}
}
......@@ -181,7 +181,7 @@ int dtkComposerEvaluatorSlave::exec(void)
if (d->composition_socket->bytesAvailable() > 10) {
dtkInfo() << "data already available, try to parse composition " << d->composition_socket->bytesAvailable();
} else if (!d->composition_socket->waitForReadyRead(600000)) {
dtkCritical() << "No data received from server after 10mn, abort " ;
dtkError() << "No data received from server after 10mn, abort " ;
return 1;
} else
dtkDebug() << "Ok, data received, parse" ;
......@@ -202,12 +202,12 @@ int dtkComposerEvaluatorSlave::exec(void)
composition = d->composition_cache.value(d->last_controller_rank);
}
} else {
dtkCritical() << "Bad composition type, abort" << msg->type() << msg->content();
dtkError() << "Bad composition type, abort" << msg->type() << msg->content();
return 1;
}
if (new_composition && composition.isEmpty()) {
dtkCritical() << "Empty composition, abort" ;
dtkError() << "Empty composition, abort" ;
return 1;
}
......@@ -234,7 +234,7 @@ int dtkComposerEvaluatorSlave::exec(void)
remote->setJob(this->jobId());
remote->setCommunicator(d->communicator_i);
} else {
dtkCritical() << "Can't find remote node in composition, abort";
dtkError() << "Can't find remote node in composition, abort";
return 1;
}
}
......@@ -287,7 +287,7 @@ int dtkComposerEvaluatorSlave::exec(void)
workerThread->deleteLater();
dtkDebug() << "finished" ;
} else {
dtkCritical() << "Can't find remote node in composition, abort";
dtkError() << "Can't find remote node in composition, abort";
return 1;
}
}
......
......@@ -70,8 +70,6 @@ void dtkComposerNodeLogger::run(void)
dtkWarn() << output;
else if (level == "error")
dtkError() << output;
else if (level == "critical")
dtkCritical() << output;
else
dtkInfo() << output;
} else {
......
......@@ -78,7 +78,7 @@ void dtkDistributedServerDaemon::setManager(QString name)
} else if (name =="local") {
d->manager = new dtkDistributedResourceManagerLocal;
} else {
dtkCritical() << "unknown resource manager type" << name;
dtkError() << "unknown resource manager type" << name;
}
}
......
......@@ -15,15 +15,21 @@
project(dtkLog)
## #################################################################
## Input
## Sources
## #################################################################
set(${PROJECT_NAME}_HEADERS
dtkLog
dtkLog.h)
dtkLog.h
dtkLogger.h
dtkLogger_p.h
dtkLogEngine.h
dtkLogDestination.h)
set(${PROJECT_NAME}_SOURCES
dtkLog.cpp)
dtkLog.cpp
dtkLogger.cpp
dtkLogEngine.cpp
dtkLogDestination.cpp)
## #################################################################
## Build rules
......@@ -31,18 +37,20 @@ set(${PROJECT_NAME}_SOURCES
add_library(${PROJECT_NAME} SHARED
${${PROJECT_NAME}_SOURCES}
${${PROJECT_NAME}_HEADERS})
${${PROJECT_NAME}_HEADERS}
${${PROJECT_NAME}_SOURCES_MOC})
qt5_use_modules(${PROJECT_NAME} Core)
qt5_use_modules(${PROJECT_NAME} Widgets)
## #################################################################
## Target properties
## #################################################################
set_target_properties(${PROJECT_NAME} PROPERTIES MACOSX_RPATH 0)
set_target_properties(${PROJECT_NAME} PROPERTIES INSTALL_NAME_DIR "${CMAKE_INSTALL_PREFIX}/${CMAKE_INSTALL_LIBDIR}")
set_target_properties(${PROJECT_NAME} PROPERTIES INSTALL_RPATH "${CMAKE_INSTALL_PREFIX}/${CMAKE_INSTALL_LIBDIR}")
## ###################################################################
## Link rules
## ###################################################################
qt5_use_modules(${PROJECT_NAME} Core)
## #################################################################
## Export header file
## #################################################################
......
#include "dtkLog.h"
#include "dtkLog.h"
\ No newline at end of file
// Version: $Id$
//
//
// Commentary:
//
//
// Change Log:
//
//
// Code:
/* dtkLog.cpp ---
*
* Author: Julien Wintz
* Copyright (C) 2008-2011 - Julien Wintz, Inria.
* Created: Thu Mar 1 14:40:12 2012 (+0100)
* Version: $Id$
* Last-Updated: Mon Mar 18 12:49:06 2013 (+0100)
* By: Julien Wintz
* Update #: 46
*/
/* Commentary:
*
*/
/* Change log:
*
*/
#include "dtkLog.h"
#include "dtkLogExport.h"
#include <iostream>
// /////////////////////////////////////////////////////////////////
//
// /////////////////////////////////////////////////////////////////
namespace dtkLogPrivate {
void installFileHandler(void);
void uninstallFileHandler(void);
void handler(QtMsgType type, const QMessageLogContext &context, const QString &message);
};
namespace dtkLogPrivate {
QFile file;
dtkLog::HandlerFlags flags;
};
// /////////////////////////////////////////////////////////////////
//
// /////////////////////////////////////////////////////////////////
namespace dtkLogPrivate {
void installFileHandler(void)
{
file.setFileName(QStandardPaths::standardLocations(QStandardPaths::DataLocation).first() + "/dtk.log");
file.open(QIODevice::WriteOnly);
}
void uninstallFileHandler(void)
{
file.close();
}
#include <QtCore>
#include <QtGui>
void handler(QtMsgType type, const QMessageLogContext &context, const QString &message)
QString DTKLOG_EXPORT dtkLogPath(QCoreApplication *application)
{
std::cerr << qPrintable(Q_FUNC_INFO);
return QDir(QStandardPaths::standardLocations(QStandardPaths::DataLocation).first()).filePath(QString("%1.log").arg(application->applicationName()));
}
};
// /////////////////////////////////////////////////////////////////
//
// /////////////////////////////////////////////////////////////////
void dtkInstallLoggerHandler(dtkLog::HandlerFlags flags)
{
dtkLogPrivate::flags = flags;
if (dtkLogPrivate::flags & dtkLog::File)
dtkLogPrivate::installFileHandler();
qInstallMessageHandler(dtkLogPrivate::handler);
}
void dtkUninstallLoggerHandler()
{
if (dtkLogPrivate::flags & dtkLog::File)
dtkLogPrivate::uninstallFileHandler();
qInstallMessageHandler(0);
}
//
// dtkLog.cpp ends here
......@@ -14,34 +14,92 @@
#pragma once
#include "dtkLogExport.h"
#include <QtCore>
namespace dtkLog {
enum HandlerFlag {
Console = 0x00,
File = 0x01
namespace dtkLog
{
enum Level {
Trace = 0x000,
Debug = 0x001,
Info = 0x010,
Warn = 0x011,
Error = 0x100,
Fatal = 0x101
};
}
#include "dtkLogger.h"
#include "dtkLogEngine.h"
// /////////////////////////////////////////////////////////////////
// Trace level stream
// /////////////////////////////////////////////////////////////////
#define dtkTrace() \
if (dtkLogger::instance().level() > dtkLog::Trace) \
; \
else \
dtkLogEngine(dtkLog::Trace).stream()
// /////////////////////////////////////////////////////////////////
// Debug level stream
// /////////////////////////////////////////////////////////////////
#define dtkDebug() \
if (dtkLogger::instance().level() > dtkLog::Debug) \
; \
else \
dtkLogEngine(dtkLog::Debug).stream()
// /////////////////////////////////////////////////////////////////
// Info level stream
// /////////////////////////////////////////////////////////////////
#define dtkInfo() \
if (dtkLogger::instance().level() > dtkLog::Info) \
; \
else \
dtkLogEngine(dtkLog::Info).stream()
// /////////////////////////////////////////////////////////////////
// Warn level stream
// /////////////////////////////////////////////////////////////////
#define dtkWarn() \
if (dtkLogger::instance().level() > dtkLog::Warn) \
; \
else \
dtkLogEngine(dtkLog::Warn).stream()
// /////////////////////////////////////////////////////////////////
// Error level stream
// /////////////////////////////////////////////////////////////////
#define dtkError() \
if (dtkLogger::instance().level() > dtkLog::Error) \
; \
else \
dtkLogEngine(dtkLog::Error).stream()
// /////////////////////////////////////////////////////////////////
// Fatal level stream
// /////////////////////////////////////////////////////////////////
#define dtkFatal() \
dtkLogEngine(dtkLog::Fatal).stream()
Q_DECLARE_FLAGS(HandlerFlags, HandlerFlag);
Q_DECLARE_OPERATORS_FOR_FLAGS(HandlerFlags);
};
// ///////////////////////////////////////////////////////////////////
// Custom level stream
// ///////////////////////////////////////////////////////////////////
DTKLOG_EXPORT void dtkInstallLoggerHandler(dtkLog::HandlerFlags);
DTKLOG_EXPORT void dtkUninstallLoggerHandler(void);
#define dtkLog(level) \
dtkLogEngine(level, true).stream()
// #define qCritical \
// for (bool enabled = dtkLoggingCategory::defaultCategory().isEnabled(QtCriticalMsg); enabled; enabled = false) \
// QMessageLogger(__FILE__, __LINE__, Q_FUNC_INFO, dtkLoggingCategory::defaultCategory().categoryName()).critical
// /////////////////////////////////////////////////////////////////
// Helper functions
// /////////////////////////////////////////////////////////////////
#define dtkDebug qDebug
#define dtkInfo qDebug
#define dtkTrace qDebug
#define dtkError qDebug
#define dtkWarn qWarning
#define dtkCritical qCritical
QString DTKLOG_EXPORT dtkLogPath(QCoreApplication *application);
//
// dtkLog.h ends here
#include "dtkLogDestination.h"
\ No newline at end of file
/* dtkLogDestination.cpp ---
*
* Author: Julien Wintz
* Copyright (C) 2008-2011 - Julien Wintz, Inria.
* Created: Thu Mar 1 15:15:19 2012 (+0100)
* Version: $Id$
* Last-Updated: Wed Apr 4 10:00:39 2012 (+0200)
* By: tkloczko
* Update #: 85
*/
/* Commentary:
*
*/
/* Change log:
*
*/
#include "dtkLogDestination.h"
// /////////////////////////////////////////////////////////////////
// dtkLogDestination
// /////////////////////////////////////////////////////////////////
dtkLogDestination::~dtkLogDestination(void)
{
}
// /////////////////////////////////////////////////////////////////
// dtkLogDestinationConsole
// /////////////////////////////////////////////////////////////////
void dtkLogDestinationConsole::write(const QString& message)
{
fprintf(stderr, "%s\n", qPrintable(message));
fflush(stderr);
}
// /////////////////////////////////////////////////////////////////
// dtkLogDestinationFile
// /////////////////////////////////////////////////////////////////
class dtkLogDestinationFilePrivate
{
public:
QFile file;
public:
QTextStream stream;
};
dtkLogDestinationFile::dtkLogDestinationFile(const QString& path) : d(new dtkLogDestinationFilePrivate)
{
d->file.setFileName(path);
QFileInfo info(path);
QDir dir(info.absoluteDir());
if(!dir.exists()) {
QString name = dir.path();
dir.mkpath(name);
}
if(!d->file.open(QFile::WriteOnly | QFile::Text | QIODevice::Append))
qDebug() << "Unable to open" << path << "for writing";
d->stream.setDevice(&(d->file));
}
dtkLogDestinationFile::~dtkLogDestinationFile(void)
{
delete d;
d = NULL;
}
void dtkLogDestinationFile::write(const QString& message)
{
d->stream << message << endl;
d->stream.flush();
}
/* dtkLogDestination.h ---
*
* Author: Julien Wintz
* Copyright (C) 2008-2011 - Julien Wintz, Inria.
* Created: Thu Mar 1 15:10:22 2012 (+0100)
* Version: $Id$
* Last-Updated: Wed Apr 4 10:00:13 2012 (+0200)
* By: tkloczko
* Update #: 49
*/
/* Commentary:
*
*/
/* Change log:
*
*/
#ifndef DTKLOGDESTINATION_H
#define DTKLOGDESTINATION_H
#include "dtkLogExport.h"
#include <QtCore>
#include <QtGui>
class dtkLogModel;
// /////////////////////////////////////////////////////////////////
// dtkLogDestination
// /////////////////////////////////////////////////////////////////
class DTKLOG_EXPORT dtkLogDestination
{
public:
virtual ~dtkLogDestination(void);
public:
virtual void write(const QString& message) = 0;
};
// /////////////////////////////////////////////////////////////////
// dtkLogDestinationConsole
// /////////////////////////////////////////////////////////////////
class DTKLOG_EXPORT dtkLogDestinationConsole : public dtkLogDestination
{
public:
void write(const QString& message);
};
// /////////////////////////////////////////////////////////////////
// dtkLogDestinationFile
// /////////////////////////////////////////////////////////////////
class dtkLogDestinationFilePrivate;
class DTKLOG_EXPORT dtkLogDestinationFile : public dtkLogDestination
{
public:
dtkLogDestinationFile(const QString& path);
~dtkLogDestinationFile(void);
public:
void write(const QString& message);
private:
dtkLogDestinationFilePrivate *d;
};
// /////////////////////////////////////////////////////////////////
// dtkLogDestinationPointer
// /////////////////////////////////////////////////////////////////
typedef QSharedPointer<dtkLogDestination> dtkLogDestinationPointer;
#endif
#include "dtkLogEngine.h"
\ No newline at end of file
// Version: $Id$
//
//
// Commentary:
//
//
// Change Log:
//
//
// Code:
#include "dtkLog.h"
#include "dtkLogger.h"
#include "dtkLogger_p.h"
#include "dtkLogEngine.h"
#include "dtkLogEngine_p.h"
// /////////////////////////////////////////////////////////////////
// Helper functions
// /////////////////////////////////////////////////////////////////
QString dtkLogLevel2String(dtkLog::Level level)
{
switch(level) {
case dtkLog::Trace: return "TRACE"; break;
case dtkLog::Debug: return "DEBUG"; break;
case dtkLog::Info: return "INFO "; break;
case dtkLog::Warn: return "WARN "; break;
case dtkLog::Error: return "ERROR"; break;
case dtkLog::Fatal: return "FATAL"; break;
default:
return "UNKNOWN";
break;
};
}
// /////////////////////////////////////////////////////////////////
// dtkLogEnginePrivate
// /////////////////////////////////////////////////////////////////
void dtkLogEnginePrivate::write(void)
{
const QString message = QString("%1 - %2 - %3")
.arg(qPrintable(dtkLogLevel2String(this->level)))
.arg(QDateTime::currentDateTime().toString())
.arg(this->buffer);
QMutexLocker lock(&(dtkLogger::instance().d->mutex));
if(!this->custom)
dtkLogger::instance().write(message);
else
dtkLogger::instance().write(message, level);
}
// /////////////////////////////////////////////////////////////////
// dtkLogEngine