Skip to content

Commit

Permalink
Allow/disallow control over log level in message display. Refs #6202
Browse files Browse the repository at this point in the history
  • Loading branch information
martyngigg committed Apr 15, 2013
1 parent 5a26f0a commit b490094
Show file tree
Hide file tree
Showing 4 changed files with 59 additions and 66 deletions.
13 changes: 11 additions & 2 deletions Code/Mantid/MantidQt/API/inc/MantidQtAPI/MessageDisplay.h
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,15 @@ namespace MantidQt
Q_OBJECT

public:
/// Constructor
MessageDisplay(QWidget *parent=NULL);
/// Controls whether the display is allowed to set the log levels
enum LogLevelControl {
EnableLogLevelControl = 0,
DisableLogLevelControl = 1
};

/// Default constructor
MessageDisplay(LogLevelControl logLevelControl=DisableLogLevelControl,
QWidget *parent=NULL);
///Destructor
~MessageDisplay();

Expand All @@ -56,6 +63,8 @@ namespace MantidQt
/// Set the properties of the text display
void setupTextArea();

/// Are we allowed to affect the log level
LogLevelControl m_logLevelControl;
/// A reference to the
QtSignalChannel *m_logChannel;
/// The actual widget holding the text
Expand Down
11 changes: 8 additions & 3 deletions Code/Mantid/MantidQt/API/inc/MantidQtAPI/QtSignalChannel.h
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,6 @@ namespace MantidQt
Q_OBJECT

public:

/// Constructor
QtSignalChannel();
/// Destructor
Expand All @@ -48,11 +47,17 @@ namespace MantidQt
/// Converts the Poco::Message to a Qt signal
void log(const Poco::Message& msg);

signals:
public slots:
/// Set the log level for all loggers
void setGlobalLogLevel(int level);

signals:
// Emitted when a Poco log message is received in this channel
void messageReceived(const QString & msg);
};

private:
Q_DISABLE_COPY(QtSignalChannel);
};
}
}

Expand Down
88 changes: 28 additions & 60 deletions Code/Mantid/MantidQt/API/src/MessageDisplay.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -27,11 +27,12 @@ namespace MantidQt
// Public member functions
//-------------------------------------------
/**
* @param loggerControl Controls whether the log-level applies globally or only to this channel (default=MessageDisplay::Global)
* @param parent An optional parent widget
*/
MessageDisplay::MessageDisplay(QWidget *parent)
: QWidget(parent), m_logChannel(NULL), m_textDisplay(new QTextEdit(this)),
m_loglevels(new QActionGroup(this)), m_logLevelMapping(new QSignalMapper(this)),
MessageDisplay::MessageDisplay(LogLevelControl logLevelControl, QWidget *parent)
: QWidget(parent), m_logLevelControl(logLevelControl), m_logChannel(new QtSignalChannel),
m_textDisplay(new QTextEdit(this)), m_loglevels(new QActionGroup(this)), m_logLevelMapping(new QSignalMapper(this)),
m_error(new QAction(tr("&Error"), this)), m_warning(new QAction(tr("&Warning"), this)),
m_notice(new QAction(tr("&Notice"), this)), m_information(new QAction(tr("&Information"), this)),
m_debug(new QAction(tr("&Debug"), this))
Expand All @@ -47,7 +48,6 @@ namespace MantidQt
void MessageDisplay::attachLoggingChannel()
{
// Setup logging
m_logChannel = new QtSignalChannel;
auto & rootLogger = Poco::Logger::root();
auto * rootChannel = Poco::Logger::root().getChannel();
// The root channel might be a SplitterChannel
Expand All @@ -62,7 +62,6 @@ namespace MantidQt

connect(m_logChannel, SIGNAL(messageReceived(const QString&)),
this, SLOT(displayMessage(const QString &)));

}


Expand Down Expand Up @@ -93,63 +92,32 @@ namespace MantidQt
QMenu * menu = m_textDisplay->createStandardContextMenu();
if(!m_textDisplay->text().isEmpty()) menu->addAction("Clear",m_textDisplay, SLOT(clear()));

// Change the log level
QMenu *logLevelMenu = menu->addMenu("&Log Level");
logLevelMenu->addAction(m_error);
logLevelMenu->addAction(m_warning);
logLevelMenu->addAction(m_notice);
logLevelMenu->addAction(m_information);
logLevelMenu->addAction(m_debug);

//check the right level
int level = Mantid::Kernel::Logger::get("").getLevel(); //get the root logger logging level
if (level == Poco::Message::PRIO_ERROR)
m_error->setChecked(true);
if (level == Poco::Message::PRIO_WARNING)
m_warning->setChecked(true);
if (level == Poco::Message::PRIO_NOTICE)
m_notice->setChecked(true);
if (level == Poco::Message::PRIO_INFORMATION)
m_information->setChecked(true);
if (level == Poco::Message::PRIO_DEBUG)
m_debug->setChecked(true);
if(m_logLevelControl == MessageDisplay::EnableLogLevelControl)
{
menu->addSeparator();
QMenu *logLevelMenu = menu->addMenu("&Log Level");
logLevelMenu->addAction(m_error);
logLevelMenu->addAction(m_warning);
logLevelMenu->addAction(m_notice);
logLevelMenu->addAction(m_information);
logLevelMenu->addAction(m_debug);

//check the right level
int level = Mantid::Kernel::Logger::get("").getLevel(); //get the root logger logging level
if (level == Poco::Message::PRIO_ERROR)
m_error->setChecked(true);
if (level == Poco::Message::PRIO_WARNING)
m_warning->setChecked(true);
if (level == Poco::Message::PRIO_NOTICE)
m_notice->setChecked(true);
if (level == Poco::Message::PRIO_INFORMATION)
m_information->setChecked(true);
if (level == Poco::Message::PRIO_DEBUG)
m_debug->setChecked(true);
}

menu->exec(this->mapToGlobal(mousePos));
delete menu;

// QMenu *menu = results->createStandardContextMenu();
// if(!menu) return;
// if(results->text().isEmpty())
// {
// actionClearLogInfo->setEnabled(false);
// }
// else
// {
// actionClearLogInfo->setEnabled(true);
// }
//
// menu->addAction(actionClearLogInfo);
// //Mantid log level changes
// QMenu *logLevelMenu = menu->addMenu("&Log Level");
// logLevelMenu->addAction(actionLogLevelError);
// logLevelMenu->addAction(actionLogLevelWarning);
// logLevelMenu->addAction(actionLogLevelNotice);
// logLevelMenu->addAction(actionLogLevelInformation);
// logLevelMenu->addAction(actionLogLevelDebug);
//
// //check the right level
// int level = Mantid::Kernel::Logger::get("").getLevel(); //get the root logger logging level
// if (level == Poco::Message::PRIO_ERROR)
// actionLogLevelError->setChecked(true);
// if (level == Poco::Message::PRIO_WARNING)
// actionLogLevelWarning->setChecked(true);
// if (level == Poco::Message::PRIO_NOTICE)
// actionLogLevelNotice->setChecked(true);
// if (level == Poco::Message::PRIO_INFORMATION)
// actionLogLevelInformation->setChecked(true);
// if (level == Poco::Message::PRIO_DEBUG)
// actionLogLevelDebug->setChecked(true);

}

/*
Expand Down Expand Up @@ -192,7 +160,7 @@ namespace MantidQt
connect(m_information, SIGNAL(activated()), m_logLevelMapping, SLOT (map()));
connect(m_debug, SIGNAL(activated()), m_logLevelMapping, SLOT (map()));

connect(m_logLevelMapping, SIGNAL(mapped(int)), this, SLOT(setGlobalLogLevel(int)));
connect(m_logLevelMapping, SIGNAL(mapped(int)), m_logChannel, SLOT(setGlobalLogLevel(int)));
}

/**
Expand Down
13 changes: 12 additions & 1 deletion Code/Mantid/MantidQt/API/src/QtSignalChannel.cpp
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
#include "MantidQtAPI/QtSignalChannel.h"
#include "MantidKernel/RegistrationHelper.h"
#include "MantidKernel/Logger.h"

#include <Poco/Message.h>

#include <sstream>

namespace MantidQt
{
namespace API
Expand Down Expand Up @@ -30,5 +32,14 @@ namespace MantidQt
emit messageReceived(QString::fromStdString(msg.getText()));
}

/*
* @param priority An integer that must match the Poco::Message priority enumeration
*/
void QtSignalChannel::setGlobalLogLevel(int priority)
{
using Mantid::Kernel::Logger;
Logger::setLevelForAll(priority);
}

}
}

0 comments on commit b490094

Please sign in to comment.