Commit c9a64315 authored by KLOCZKO Thibaud's avatar KLOCZKO Thibaud
Browse files

Replace former logger by new one in every layer.

parent d7b9d1b4
......@@ -4,9 +4,9 @@
## Copyright (C) 2011 - Thibaud Kloczko, Inria.
## Created: Mon Sep 26 09:27:41 2011 (+0200)
## Version: $Id$
## Last-Updated: Tue Sep 27 09:44:50 2011 (+0200)
## By: Thibaud Kloczko
## Update #: 22
## Last-Updated: Wed Apr 4 10:27:10 2012 (+0200)
## By: tkloczko
## Update #: 23
######################################################################
##
### Commentary:
......@@ -34,5 +34,6 @@ add_executable(${PROJECT_NAME} MACOSX_BUNDLE
target_link_libraries(${PROJECT_NAME}
${QT_LIBRARIES}
dtkCore
dtkGui)
dtkGui
dtkLog)
......@@ -4,9 +4,9 @@
* Copyright (C) 2011 - Thibaud Kloczko, Inria.
* Created: Mon Sep 26 09:28:44 2011 (+0200)
* Version: $Id$
* Last-Updated: Tue Apr 3 16:04:07 2012 (+0200)
* Last-Updated: Wed Apr 4 10:27:01 2012 (+0200)
* By: tkloczko
* Update #: 151
* Update #: 152
*/
/* Commentary:
......@@ -22,7 +22,8 @@
#include <dtkCore/dtkAbstractData.h>
#include <dtkCore/dtkAbstractDataComposite.h>
#include <dtkCore/dtkGlobal.h>
#include <dtkCore/dtkLog.h>
#include <dtkLog/dtkLog.h>
#include <dtkGui/dtkAboutBox.h>
......
......@@ -4,9 +4,9 @@
* Copyright (C) 2008 - Julien Wintz, Inria.
* Created: Sat Apr 11 13:49:30 2009 (+0200)
* Version: $Id$
* Last-Updated: Thu Oct 14 21:29:07 2010 (+0200)
* By: Julien Wintz
* Update #: 43
* Last-Updated: Wed Apr 4 10:28:40 2012 (+0200)
* By: tkloczko
* Update #: 46
*/
/* Commentary:
......@@ -33,17 +33,6 @@
#include <dtkGui/dtkInterpreter.h>
// /////////////////////////////////////////////////////////////////
// log message handler
// /////////////////////////////////////////////////////////////////
QWidget *log_output;
void tstRedirectLogHandler(dtkLog::Level level, const QString& msg)
{
QCoreApplication::postEvent(log_output, new dtkLogEvent(level, msg));
}
// /////////////////////////////////////////////////////////////////
//
// /////////////////////////////////////////////////////////////////
......@@ -89,10 +78,7 @@ int main(int argc, char *argv[])
if(!options.getFlag("console") || !options.getFlag('c')) {
log_output = window.interpreter();
window.interpreter()->registerInterpreter(interpreter);
window.interpreter()->registerAsHandler(tstRedirectLogHandler);
window.show();
} else {
interpreter->start();
......
......@@ -4,9 +4,9 @@
## Copyright (C) 2008 - Julien Wintz, Inria.
## Created: Fri Apr 16 09:26:50 2010 (+0200)
## Version: $Id$
## Last-Updated: Mon Apr 19 12:57:49 2010 (+0200)
## By: Julien Wintz
## Update #: 15
## Last-Updated: Wed Apr 4 08:57:18 2012 (+0200)
## By: tkloczko
## Update #: 16
######################################################################
##
### Commentary:
......@@ -34,4 +34,5 @@ add_executable(${PROJECT_NAME} MACOSX_BUNDLE
target_link_libraries(${PROJECT_NAME}
${QT_LIBRARIES}
dtkCore
dtkGui)
dtkGui
dtkLog)
......@@ -4,9 +4,9 @@
* Copyright (C) 2008 - Julien Wintz, Inria.
* Created: Fri Apr 16 09:27:23 2010 (+0200)
* Version: $Id$
* Last-Updated: Mon Apr 19 13:30:24 2010 (+0200)
* By: Julien Wintz
* Update #: 245
* Last-Updated: Wed Apr 4 08:57:10 2012 (+0200)
* By: tkloczko
* Update #: 246
*/
/* Commentary:
......@@ -21,7 +21,8 @@
#include <dtkCore/dtkAbstractObject.h>
#include <dtkCore/dtkGlobal.h>
#include <dtkCore/dtkLog.h>
#include <dtkLog/dtkLog.h>
#include <dtkGui/dtkAboutBox.h>
......
......@@ -4,9 +4,9 @@
* Copyright (C) 2008-2011 - Julien Wintz, Inria.
* Created: Fri Feb 3 14:02:14 2012 (+0100)
* Version: $Id$
* Last-Updated: Tue Apr 3 15:42:21 2012 (+0200)
* Last-Updated: Tue Apr 3 16:49:32 2012 (+0200)
* By: tkloczko
* Update #: 216
* Update #: 217
*/
/* Commentary:
......@@ -178,7 +178,6 @@ void dtkComposerSceneNodeLeaf::paint(QPainter *painter, const QStyleOptionGraphi
QFont font = painter->font();
QFontMetricsF metrics(font);
QString title_text = metrics.elidedText(this->title(), Qt::ElideMiddle, this->boundingRect().width()-2-4*margin);
QRectF title_rect = metrics.boundingRect(title_text);
QPointF title_pos;
......
......@@ -4,9 +4,9 @@
## Copyright (C) 2008 - Julien Wintz, Inria.
## Created: Mon Jul 20 18:39:20 2009 (+0200)
## Version: $Id$
## Last-Updated: Tue Apr 3 12:32:22 2012 (+0200)
## By: Julien Wintz
## Update #: 227
## Last-Updated: Tue Apr 3 17:05:27 2012 (+0200)
## By: tkloczko
## Update #: 229
######################################################################
##
### Commentary:
......@@ -45,7 +45,6 @@ set(${PROJECT_NAME}_HEADERS
dtkAbstractViewNavigator.h
dtkCoreExport.h
dtkGlobal.h
dtkLog.h
dtkPluginManager.h
dtkQuat.h
dtkUpdater.h
......@@ -96,7 +95,6 @@ set(${PROJECT_NAME}_SOURCES
dtkAbstractViewInteractor.cpp
dtkAbstractViewNavigator.cpp
dtkPlugin.cpp
dtkLog.cpp
dtkPluginManager.cpp
dtkQuat.cpp
dtkSignalBlocker.h
......@@ -178,6 +176,9 @@ add_library(${PROJECT_NAME} STATIC
${${PROJECT_NAME}_SOURCES_WRAP})
endif(BUILD_SHARED_LIBS)
target_link_libraries(${PROJECT_NAME}
dtkLog)
target_link_libraries(${PROJECT_NAME} ${QT_LIBRARIES})
......
......@@ -4,9 +4,9 @@
* Copyright (C) 2008 - Julien Wintz, Inria.
* Created: Fri Nov 7 16:01:09 2008 (+0100)
* Version: $Id$
* Last-Updated: Tue Apr 3 15:55:50 2012 (+0200)
* Last-Updated: Wed Apr 4 08:47:38 2012 (+0200)
* By: tkloczko
* Update #: 399
* Update #: 400
*/
/* Commentary:
......@@ -24,7 +24,8 @@
#include <dtkCore/dtkAbstractDataConverter.h>
#include <dtkCore/dtkAbstractDataSerializer.h>
#include <dtkCore/dtkAbstractDataDeserializer.h>
#include <dtkCore/dtkLog.h>
#include <dtkLog/dtkLog.h>
#include <QtGui>
......
......@@ -4,9 +4,9 @@
* Copyright (C) 2011 - Thibaud Kloczko, Inria.
* Created: Wed Sep 21 13:46:31 2011 (+0200)
* Version: $Id$
* Last-Updated: Mon Oct 17 09:03:23 2011 (+0200)
* By: Thibaud Kloczko
* Update #: 259
* Last-Updated: Wed Apr 4 10:29:53 2012 (+0200)
* By: tkloczko
* Update #: 261
*/
/* Commentary:
......@@ -23,7 +23,8 @@
#include <dtkCore/dtkAbstractData>
#include <dtkCore/dtkCoreExport>
#include <dtkCore/dtkGlobal>
#include <dtkCore/dtkLog>
#include <dtkLog/dtkLog.h>
class dtkAbstractDataCompositePrivate;
......
......@@ -4,9 +4,9 @@
* Copyright (C) 2011 - Thibaud Kloczko, Inria.
* Created: Thu Sep 22 14:34:08 2011 (+0200)
* Version: $Id$
* Last-Updated: Mon Sep 26 14:57:41 2011 (+0200)
* By: Thibaud Kloczko
* Update #: 185
* Last-Updated: Wed Apr 4 10:29:28 2012 (+0200)
* By: tkloczko
* Update #: 187
*/
/* Commentary:
......
......@@ -4,9 +4,9 @@
* Copyright (C) 2008 - Julien Wintz, Inria.
* Created: Sat Feb 28 17:54:04 2009 (+0100)
* Version: $Id$
* Last-Updated: Mon Sep 5 12:59:00 2011 (+0200)
* By: Julien Wintz
* Update #: 209
* Last-Updated: Wed Apr 4 08:49:02 2012 (+0200)
* By: tkloczko
* Update #: 210
*/
/* Commentary:
......@@ -18,7 +18,8 @@
*/
#include <dtkCore/dtkAbstractObject.h>
#include <dtkCore/dtkLog.h>
#include <dtkLog/dtkLog.h>
#include <QAtomicInt>
......
......@@ -4,9 +4,9 @@
* Copyright (C) 2008 - Julien Wintz, Inria.
* Created: Fri Nov 7 15:54:10 2008 (+0100)
* Version: $Id$
* Last-Updated: Wed Mar 16 14:56:47 2011 (+0100)
* By: Julien Wintz
* Update #: 115
* Last-Updated: Wed Apr 4 08:46:39 2012 (+0200)
* By: tkloczko
* Update #: 116
*/
/* Commentary:
......@@ -19,9 +19,10 @@
#include <dtkCore/dtkAbstractProcess.h>
#include <dtkCore/dtkAbstractProcessFactory.h>
#include <dtkCore/dtkLog.h>
#include <dtkCore/dtkSmartPointer.h>
#include <dtkLog/dtkLog.h>
class dtkAbstractProcessFactoryPrivate
{
public:
......@@ -110,7 +111,7 @@ QStringList dtkAbstractProcessFactory::implementations(const QString& interface)
if(d->interfaces.keys().contains(interface))
implementations << d->interfaces.values(interface);
else
dtkWarning() << "There is no available implementation of " << interface ;
dtkWarn() << "There is no available implementation of " << interface ;
return implementations;
}
......
......@@ -4,9 +4,9 @@
* Copyright (C) 2008 - Julien Wintz, Inria.
* Created: Fri Nov 7 16:01:09 2008 (+0100)
* Version: $Id$
* Last-Updated: Tue Apr 3 16:00:03 2012 (+0200)
* Last-Updated: Wed Apr 4 08:50:14 2012 (+0200)
* By: tkloczko
* Update #: 293
* Update #: 295
*/
/* Commentary:
......@@ -22,9 +22,10 @@
#include <dtkCore/dtkAbstractViewAnimator.h>
#include <dtkCore/dtkAbstractViewNavigator.h>
#include <dtkCore/dtkAbstractViewInteractor.h>
#include <dtkCore/dtkLog.h>
#include <dtkCore/dtkSmartPointer.h>
#include <dtkLog/dtkLog.h>
class dtkAbstractViewPrivate
{
public:
......@@ -217,7 +218,7 @@ void dtkAbstractView::resize(int width, int height)
void dtkAbstractView::addAnimator(dtkAbstractViewAnimator *animator)
{
if(animator->identifier().isEmpty()) {
qDebug() << "No identifier specified for animator. Not add to" << this->identifier();
dtkDebug() << "No identifier specified for animator. Not add to" << this->identifier();
return;
}
......@@ -227,7 +228,7 @@ void dtkAbstractView::addAnimator(dtkAbstractViewAnimator *animator)
void dtkAbstractView::addNavigator(dtkAbstractViewNavigator *navigator)
{
if(navigator->identifier().isEmpty()) {
qDebug() << "No identifier specified for navigator. Not add to" << this->identifier();
dtkDebug() << "No identifier specified for navigator. Not add to" << this->identifier();
return;
}
......@@ -237,7 +238,7 @@ void dtkAbstractView::addNavigator(dtkAbstractViewNavigator *navigator)
void dtkAbstractView::addInteractor(dtkAbstractViewInteractor *interactor)
{
if(interactor->identifier().isEmpty()) {
qDebug() << "No identifier specified for interactor. Not add to" << this->identifier();
dtkDebug() << "No identifier specified for interactor. Not add to" << this->identifier();
return;
}
......
#include "dtkLog.h"
\ No newline at end of file
/* dtkLog.cpp ---
*
* Author: Jean-Christophe Lombardo
* Copyright (C) 2008-2009 - Jean-Christophe Lombardo, Inria.
* Created: Thu May 14 14:32:46 2009 (+0200)
* Version: $Id$
* Last-Updated: Wed Nov 16 15:06:15 2011 (+0100)
* By: Thibaud Kloczko
* Update #: 132
*/
/* Commentary:
*
*/
/* Change log:
*
*/
#include "dtkLog.h"
QMultiMap<QString, dtkLog::Handler> dtkLog::s_handlers;
// /////////////////////////////////////////////////////////////////
// dtkStandardRedirector
// /////////////////////////////////////////////////////////////////
#include <iostream>
#include <streambuf>
#include <string>
class dtkStandardRedirector : public std::basic_streambuf<char>
{
public:
enum Channel { Out, Err, Log } ;
dtkStandardRedirector(std::ostream &stream, Channel channel);
~dtkStandardRedirector(void);
static bool initialize(void);
static void uninitialize(void);
protected:
virtual int overflow(int v);
virtual std::streamsize xsputn(const char *p, std::streamsize n);
void flush(void);
private:
std::ostream& m_stream;
std::streambuf *m_buffer;
std::string m_string;
Channel m_channel;
static dtkStandardRedirector *s_err;
static dtkStandardRedirector *s_out;
static dtkStandardRedirector *s_log;
};
dtkStandardRedirector *dtkStandardRedirector::s_err = NULL;
dtkStandardRedirector *dtkStandardRedirector::s_out = NULL;
dtkStandardRedirector *dtkStandardRedirector::s_log = NULL;
dtkStandardRedirector::dtkStandardRedirector(std::ostream &stream, Channel channel) : m_stream(stream), m_channel(channel)
{
m_string = " ";
m_buffer = stream.rdbuf();
stream.rdbuf(this);
}
dtkStandardRedirector::~dtkStandardRedirector(void)
{
if (!m_string.empty()) flush();
m_stream.rdbuf(m_buffer);
}
void dtkStandardRedirector::flush(void)
{
switch(m_channel) {
case Err:
dtkLog::error() << QString::fromStdString(m_string);
break;
case Out:
case Log:
dtkLog::output() << QString::fromStdString(m_string);
break;
default:
break;
};
}
int dtkStandardRedirector::overflow(int v)
{
if (v == '\n') {
dtkLog::output() << m_string.c_str();
m_string.erase(m_string.begin(), m_string.end());
} else
m_string += v;
return v;
}
std::streamsize dtkStandardRedirector::xsputn(const char *p, std::streamsize n)
{
if(p)
m_string += QString::fromAscii(p, n).remove('\n').remove('\r').simplified().toStdString();
return n;
}
bool dtkStandardRedirector::initialize(void)
{
if (!s_err) s_err = new dtkStandardRedirector(std::cerr, dtkStandardRedirector::Err);
if (!s_out) s_out = new dtkStandardRedirector(std::cout, dtkStandardRedirector::Out);
if (!s_log) s_log = new dtkStandardRedirector(std::clog, dtkStandardRedirector::Log);
return true;
}
void dtkStandardRedirector::uninitialize(void)
{
if (s_err) { delete s_err; s_err = NULL; }
if (s_out) { delete s_out; s_out = NULL; }
if (s_log) { delete s_log; s_log = NULL; }
}
// /////////////////////////////////////////////////////////////////
// dtkLog
// /////////////////////////////////////////////////////////////////
dtkLog& dtkLog::operator<<(bool value)
{
if (value)
m_log += "true";
else
m_log += "false";
return *this;
}
dtkLog& dtkLog::operator<<(int value)
{
m_log += QString::number(value);
return *this;
}
dtkLog& dtkLog::operator<<(uint value)
{
m_log += QString::number(value);
return *this;
}
dtkLog& dtkLog::operator<<(long value)
{
m_log += QString::number(value);
return *this;
}
dtkLog& dtkLog::operator<<(ulong value)
{
m_log += QString::number(value);
return *this;
}
dtkLog& dtkLog::operator<<(qlonglong value)
{
m_log += QString::number(value);
return *this;
}
dtkLog& dtkLog::operator<<(qulonglong value)
{
m_log += QString::number(value);
return *this;
}
dtkLog& dtkLog::operator<<(float value)
{
m_log += QString::number(value);
return *this;
}
dtkLog& dtkLog::operator<<(double value)
{
m_log += QString::number(value);
return *this;
}
dtkLog& dtkLog::operator<<(const QString& value)
{
m_log += value;
return *this;
}
dtkLog& dtkLog::operator<<(const QStringList& value)
{
QStringList::const_iterator it(value.begin());
if ( it == value.end() ) {
m_log += "()"; // List is empty.
} else {
m_log += "(" + *it; // First entry displayed, no comma.
++it;
for( ; it != value.end(); ++it ) {
m_log += "," + *it;
}
m_log += ")";
}
return *this;
}
dtkLog dtkLog::output(const QString& source)
{
return dtkLog(source, Output);
}
dtkLog dtkLog::error(const QString& source)
{
return dtkLog(source, Error);
}
dtkLog dtkLog::debug(const QString& source)
{
return dtkLog(source, Debug);
}
dtkLog dtkLog::warning(const QString& source)
{
return dtkLog(source, Warning);
}
dtkLog dtkLog::critical(const QString& source)
{
return dtkLog(source, Critical);
}
dtkLog dtkLog::fatal(const QString& source)
{
return dtkLog(source, Fatal);
}
dtkLog::dtkLog(const QString& source, Level level) : m_level(level), m_source(source)
{
}
dtkLog::~dtkLog(void)
{
if (s_handlers.keys().contains(m_source))
foreach(Handler handler, s_handlers.values(m_source)) handler(m_level, m_log);
else
{
switch(m_level)
{
case Debug:
qDebug() << m_log.toAscii().constData();
break;
case Warning:
qWarning() << m_log.toAscii().constData();
break;
case Error:
qCritical() << m_log.toAscii().constData();
break;
case Fatal:
qCritical() << m_log.toAscii().constData();