diff --git a/Framework/Kernel/CMakeLists.txt b/Framework/Kernel/CMakeLists.txt index 78c1b6bb98747d4cfc6e3da3e3d1a4ad770ab00c..43cb3a220b9543aa8ddf2107fdfd3b875e2612c4 100644 --- a/Framework/Kernel/CMakeLists.txt +++ b/Framework/Kernel/CMakeLists.txt @@ -34,7 +34,6 @@ set ( SRC_FILES src/FacilityInfo.cpp src/FileDescriptor.cpp src/FileValidator.cpp - src/FilterChannel.cpp src/FilteredTimeSeriesProperty.cpp src/FloatingPointComparison.cpp src/FreeBlock.cpp @@ -133,7 +132,6 @@ set ( SRC_FILES set ( SRC_UNITY_IGNORE_FILES src/Atom.cpp src/NeutronAtom.cpp src/FacilityInfo.cpp - src/FilterChannel.cpp src/FileValidator.cpp src/DirectoryValidator.cpp src/PropertyManager.cpp @@ -191,7 +189,6 @@ set ( INC_FILES inc/MantidKernel/Fast_Exponential.h inc/MantidKernel/FileDescriptor.h inc/MantidKernel/FileValidator.h - inc/MantidKernel/FilterChannel.h inc/MantidKernel/FilteredTimeSeriesProperty.h inc/MantidKernel/FloatingPointComparison.h inc/MantidKernel/FreeBlock.h @@ -360,7 +357,6 @@ set ( TEST_FILES FacilitiesTest.h FileDescriptorTest.h FileValidatorTest.h - FilterChannelTest.h FilteredTimeSeriesPropertyTest.h FloatingPointComparisonTest.h FreeBlockTest.h @@ -631,12 +627,6 @@ if ( MPI_BUILD ) set ( PV_PLUGINS_DIR "" ) set ( IGNORE_PARAVIEW "1" ) else () - option ( ENABLE_FILE_LOGGING "Enable logging to file for development builds. It is always enabled for packages" ON ) - if ( ENABLE_FILE_LOGGING ) - set ( FILELOGGER_CHANNEL fileFilterChannel ) - else () - set ( FILELOGGER_CHANNEL "" ) - endif () set ( CONSOLEPATTERN "%s-[%p] %t" ) endif () @@ -678,10 +668,8 @@ endif () # Log to file for installed packages but not mpi if ( MPI_BUILD OR MPI_EXPERIMENTAL ) - set ( FILELOGGER_CHANNEL "" ) set ( ENABLE_NETWORK_ACCESS 0 ) else () - set ( FILELOGGER_CHANNEL fileFilterChannel ) set ( ENABLE_NETWORK_ACCESS 1 ) endif () set ( FRAMEWORK_PLUGINS_DIR ${MANTID_ROOT}/plugins ) diff --git a/Framework/Kernel/inc/MantidKernel/ConfigService.h b/Framework/Kernel/inc/MantidKernel/ConfigService.h index 53520fd6fdf70b7ffc00e7f7fa783761c5abc310..c01d3790371b6e6741aea7c645d233a1c151f84c 100644 --- a/Framework/Kernel/inc/MantidKernel/ConfigService.h +++ b/Framework/Kernel/inc/MantidKernel/ConfigService.h @@ -230,15 +230,8 @@ public: const FacilityInfo &getFacility(const std::string &facilityName) const; /// Set the default facility void setFacility(const std::string &facilityName); - - /// registers additional logging filter channels - void registerLoggingFilterChannel(const std::string &filterChannelName, - Poco::Channel *pChannel); - /// Sets the log level priority for the Console log channel - void setConsoleLogLevel(int logLevel); - /// Sets the log level priority for the selected Filter log channel - void setFilterChannelLogLevel(const std::string &filterChannelName, - int logLevel, bool quiet = false); + /// Sets the log level priority for all log channels + void setLogLevel(int logLevel, bool quiet = false); /// Look for an instrument const InstrumentInfo & @@ -303,8 +296,6 @@ private: /// Returns a list of all keys under a given root key void getKeysRecursive(const std::string &root, std::vector<std::string> &allKeys) const; - /// Finds the lowest registered logging filter level - int FindLowestFilterLevel() const; // Forward declaration of inner class template <class T> class WrappedObject; @@ -347,8 +338,6 @@ private: /// whether the proxy has been populated yet bool m_isProxySet; - /// store a list of logging FilterChannels - std::vector<std::string> m_filterChannels; }; EXTERN_MANTID_KERNEL template class MANTID_KERNEL_DLL diff --git a/Framework/Kernel/inc/MantidKernel/FilterChannel.h b/Framework/Kernel/inc/MantidKernel/FilterChannel.h deleted file mode 100644 index fc17c9ebe814359e39d073e3428dbf67601e9878..0000000000000000000000000000000000000000 --- a/Framework/Kernel/inc/MantidKernel/FilterChannel.h +++ /dev/null @@ -1,90 +0,0 @@ -// -// FilterChannel.h -// -// $Id: //poco/1.3/Foundation/include/Poco/SplitterChannel.h#1 $ -// -// Library: Foundation -// Package: Logging -// Module: SplitterChannel -// -// Definition of the FilterChannel class. A small extension to the POCO logging. -// -// Copyright © 2007 ISIS Rutherford Appleton Laboratory, NScD Oak Ridge -// National Laboratory & European Spallation Source -// -// This file is part of Mantid. -// -// Mantid 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 3 of the License, or -// (at your option) any later version. -// -// Mantid 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, see <http://www.gnu.org/licenses/>. -// -// File change history is stored at: <https://github.com/mantidproject/mantid> -// - -#ifndef Foundation_FilterChannel_INCLUDED -#define Foundation_FilterChannel_INCLUDED - -#include "MantidKernel/DllConfig.h" -#include <Poco/Channel.h> -#include <string> -#include <mutex> - -namespace Poco { -// Forward declare -class Message; - -/// This channel sends a message to multiple -/// channels simultaneously. -class MANTID_KERNEL_DLL FilterChannel : public Channel { -public: - /// Creates the FilterChannel. - FilterChannel(); - - /// destructor - ~FilterChannel() override; - - /// Attaches a channel, which may not be null. - void addChannel(Channel *pChannel); - - /// Returns the channel pointer. - Channel *getChannel() { return _channel; } - - /// set the priority cutoff by integer. - const FilterChannel &setPriority(const int &priority); - /// Set the priority cutoff by string. - const FilterChannel &setPriority(const std::string &priority); - - /// Returns the integer representation of the priority - unsigned int getPriority() const { return _priority; } - - /// Sends the given Message to the attached channel. - void log(const Message &msg) override; - - /// Sets or changes a configuration property. - void setProperty(const std::string &name, const std::string &value) override; - - /// Removes all channels. - void close() override; - -protected: -private: - /// private pointer to the channel to pass messages onto - Channel *_channel; - /// The priority used to filter messages - int _priority; - /// A mutex lock to prevent race conditions - mutable std::mutex _mutex; -}; - -} // namespace Poco - -#endif // Foundation_FilterChannel_INCLUDED diff --git a/Framework/Kernel/src/ConfigService.cpp b/Framework/Kernel/src/ConfigService.cpp index 1d0350c9171d4db0c67535c21e6775b764552fb4..cd4ac02408fd2d1f9abfbfc0cbf5f2a08f11fd9b 100644 --- a/Framework/Kernel/src/ConfigService.cpp +++ b/Framework/Kernel/src/ConfigService.cpp @@ -7,7 +7,6 @@ #include "MantidKernel/MantidVersion.h" #include "MantidKernel/Strings.h" #include "MantidKernel/Logger.h" -#include "MantidKernel/FilterChannel.h" #include "MantidKernel/StdoutChannel.h" #include "MantidKernel/System.h" #include "MantidKernel/Exception.h" @@ -160,16 +159,11 @@ ConfigServiceImpl::ConfigServiceImpl() m_user_properties_file_name("Mantid.user.properties"), #endif m_DataSearchDirs(), m_UserSearchDirs(), m_InstrumentDirs(), - m_instr_prefixes(), m_proxyInfo(), m_isProxySet(false), - m_filterChannels() { + m_instr_prefixes(), m_proxyInfo(), m_isProxySet(false) { // getting at system details m_pSysConfig = new WrappedObject<Poco::Util::SystemConfiguration>; m_pConf = nullptr; - // Register the FilterChannel with the Poco logging factory - Poco::LoggingFactory::defaultFactory().registerChannelClass( - "FilterChannel", - new Poco::Instantiator<Poco::FilterChannel, Poco::Channel>); // Register StdChannel with Poco Poco::LoggingFactory::defaultFactory().registerChannelClass( "StdoutChannel", @@ -409,21 +403,6 @@ bool ConfigServiceImpl::readFile(const std::string &filename, return good; } -/** Registers additional logging filter channels -* @param filterChannelName The name to refer to the filter channel, this should -* be unique -* @param pChannel a pointer to the channel to be registered, if blank, then the -* channel must already be registered with the logging registry in Poco -*/ -void ConfigServiceImpl::registerLoggingFilterChannel( - const std::string &filterChannelName, Poco::Channel *pChannel) { - m_filterChannels.push_back(filterChannelName); - if (pChannel) { - Poco::LoggingRegistry::defaultRegistry().registerChannel(filterChannelName, - pChannel); - } -} - /** Configures the Poco logging and starts it up * */ @@ -436,8 +415,6 @@ void ConfigServiceImpl::configureLogging() { std::cerr << "Trouble configuring the logging framework " << e.what() << '\n'; } - // register the filter channels - the order here is important - registerLoggingFilterChannel("consoleFilterChannel", nullptr); } /** @@ -661,17 +638,6 @@ void ConfigServiceImpl::createUserPropertiesFile() const { filestr << "## Valid values are: error, warning, notice, information, debug\n"; filestr << "#logging.loggers.root.level=information\n\n"; - filestr << "## Sets the lowest level messages to be logged to file\n"; - filestr << "## Default is warning\n"; - filestr - << "## Valid values are: error, warning, notice, information, debug\n"; - filestr << "#logging.channels.fileFilterChannel.level=debug\n\n"; - filestr << "## Sets the file to write logs to\n"; - filestr << "#logging.channels.fileChannel.path=../mantid.log\n"; - filestr << "## Uncomment the following line to flush log messages to disk " - "immediately.\n"; - filestr << "## Useful for debugging crashes but it will hurt performance\n"; - filestr << "#logging.channels.fileChannel.flush = true\n\n"; filestr << "##\n"; filestr << "## MantidPlot\n"; filestr << "##\n\n"; @@ -700,25 +666,14 @@ std::string ConfigServiceImpl::defaultConfig() const { std::string propFile = "# logging configuration" "# root level message filter (drop to debug for more messages)" - "logging.loggers.root.level = debug" + "logging.loggers.root.level = notice" "# splitting the messages to many logging channels" "logging.loggers.root.channel.class = SplitterChannel" "logging.loggers.root.channel.channel1 = consoleChannel" - "logging.loggers.root.channel.channel2 = fileFilterChannel" "# output to the console - primarily for console based apps" "logging.channels.consoleChannel.class = ConsoleChannel" "logging.channels.consoleChannel.formatter = f1" "# specfic filter for the file channel raising the level to warning " - "(drop to debug for debugging)" - "logging.channels.fileFilterChannel.class= FilterChannel" - "logging.channels.fileFilterChannel.channel= fileChannel" - "logging.channels.fileFilterChannel.level= warning" - "# output to a file (For error capturing and debugging)" - "logging.channels.fileChannel.class = debug" - "logging.channels.fileChannel.path = ../logs/mantid.log" - "logging.channels.fileChannel.formatter.class = PatternFormatter" - "logging.channels.fileChannel.formatter.pattern = %Y-%m-%d %H:%M:%S,%i " - "[%I] %p %s - %t" "logging.formatters.f1.class = PatternFormatter" "logging.formatters.f1.pattern = %s-[%p] %t" "logging.formatters.f1.times = UTC"; @@ -1984,74 +1939,17 @@ Kernel::ProxyInfo &ConfigServiceImpl::getProxy(const std::string &url) { return m_proxyInfo; } -/** Sets the log level priority for the Console log channel -* @param logLevel the integer value of the log level to set, 1=Critical, 7=Debug -*/ -void ConfigServiceImpl::setConsoleLogLevel(int logLevel) { - setFilterChannelLogLevel(m_filterChannels[0], logLevel); -} - -/** Sets the Log level for a filter channel -* @param filterChannelName the channel name of the filter channel to change +/** Sets the log level priority for all logging channels * @param logLevel the integer value of the log level to set, 1=Critical, 7=Debug * @param quiet If true then no message regarding the level change is emitted -* @throws std::invalid_argument if the channel name is incorrect or it is not a -* filterChannel */ -void ConfigServiceImpl::setFilterChannelLogLevel( - const std::string &filterChannelName, int logLevel, bool quiet) { - Poco::Channel *channel = nullptr; - try { - channel = Poco::LoggingRegistry::defaultRegistry().channelForName( - filterChannelName); - } catch (Poco::NotFoundException &) { - throw std::invalid_argument(filterChannelName + - " not found in the Logging Registry"); - } - - auto *filterChannel = dynamic_cast<Poco::FilterChannel *>(channel); - if (filterChannel) { - filterChannel->setPriority(logLevel); - int lowestLogLevel = FindLowestFilterLevel(); - // set root level if required - int rootLevel = Poco::Logger::root().getLevel(); - if (rootLevel != lowestLogLevel) { - Mantid::Kernel::Logger::setLevelForAll(lowestLogLevel); - } - if (!quiet) { - g_log.log(filterChannelName + " log channel set to " + - Logger::PriorityNames[logLevel] + " priority", - static_cast<Logger::Priority>(logLevel)); - } - } else { - throw std::invalid_argument(filterChannelName + - " was not a filter channel"); - } -} - -/** Finds the lowest Log level for all registered filter channels -*/ -int ConfigServiceImpl::FindLowestFilterLevel() const { - int lowestPriority = Logger::Priority::PRIO_FATAL; - // Find the lowest level of all of the filter channels - for (const auto &filterChannelName : m_filterChannels) { - try { - auto *channel = Poco::LoggingRegistry::defaultRegistry().channelForName( - filterChannelName); - auto *filterChannel = dynamic_cast<Poco::FilterChannel *>(channel); - if (filterChannel) { - int filterPriority = filterChannel->getPriority(); - if (filterPriority > lowestPriority) { - lowestPriority = filterPriority; - } - } - } catch (Poco::NotFoundException &) { - g_log.warning(filterChannelName + - " registered log filter channel not found"); - } +void ConfigServiceImpl::setLogLevel(int logLevel, bool quiet) { + Mantid::Kernel::Logger::setLevelForAll(logLevel); + if (!quiet) { + g_log.log("logging set to " + + Logger::PriorityNames[logLevel] + " priority", + static_cast<Logger::Priority>(logLevel)); } - - return lowestPriority; } /// \cond TEMPLATE diff --git a/Framework/Kernel/src/FilterChannel.cpp b/Framework/Kernel/src/FilterChannel.cpp deleted file mode 100644 index 420b5fb0abfd838b6bd19e652f9b04bc7c0f4c63..0000000000000000000000000000000000000000 --- a/Framework/Kernel/src/FilterChannel.cpp +++ /dev/null @@ -1,92 +0,0 @@ - -#include "MantidKernel/FilterChannel.h" -#include <MantidKernel/StringTokenizer.h> - -#include <Poco/LoggingRegistry.h> -#include <Poco/Message.h> - -#include <algorithm> - -namespace Poco { - -FilterChannel::FilterChannel() : _channel(nullptr), _priority(8) {} - -FilterChannel::~FilterChannel() { close(); } - -void FilterChannel::addChannel(Channel *pChannel) { - poco_check_ptr(pChannel); - std::lock_guard<std::mutex> lock(_mutex); - - pChannel->duplicate(); - _channel = pChannel; -} - -void FilterChannel::setProperty(const std::string &name, - const std::string &value) { - if (name.compare(0, 7, "channel") == 0) { - Mantid::Kernel::StringTokenizer tokenizer( - value, ",;", Mantid::Kernel::StringTokenizer::TOK_IGNORE_EMPTY | - Mantid::Kernel::StringTokenizer::TOK_TRIM); - for (const auto &piece : tokenizer) { - addChannel(LoggingRegistry::defaultRegistry().channelForName(piece)); - } - } else if (name.compare(0, 5, "level") == 0) { - setPriority(value); - } else - Channel::setProperty(name, value); -} - -void FilterChannel::log(const Message &msg) { - std::lock_guard<std::mutex> lock(_mutex); - - if ((_channel) && (msg.getPriority() <= _priority)) { - _channel->log(msg); - } -} - -void FilterChannel::close() { - std::lock_guard<std::mutex> lock(_mutex); - if (_channel != nullptr) { - _channel->release(); - } -} - -const FilterChannel &FilterChannel::setPriority(const int &priority) { - _priority = priority; - - return *this; -} - -const FilterChannel &FilterChannel::setPriority(const std::string &priority) { - // take a local copy of the input - std::string workPriority = priority; - // convert to upper case - std::transform(workPriority.begin(), workPriority.end(), workPriority.begin(), - toupper); - - // if there is a prefix strip it off - if (workPriority.compare(0, 5, "PRIO_") == 0) { - workPriority = workPriority.substr(5, workPriority.length() - 5); - } - - if (workPriority.compare(0, 2, "FA") == 0) // PRIO_FATAL - _priority = 1; - else if (workPriority.compare(0, 2, "CR") == 0) // PRIO_CRITICAL - _priority = 2; - else if (workPriority.compare(0, 2, "ER") == 0) // PRIO_ERROR - _priority = 3; - else if (workPriority.compare(0, 2, "WA") == 0) // PRIO_WARNING - _priority = 4; - else if (workPriority.compare(0, 2, "NO") == 0) // PRIO_NOTICE - _priority = 5; - else if (workPriority.compare(0, 2, "IN") == 0) // PRIO_INFORMATION - _priority = 6; - else if (workPriority.compare(0, 2, "DE") == 0) // PRIO_DEBUG - _priority = 7; - else if (workPriority.compare(0, 2, "TR") == 0) // PRIO_TRACE - _priority = 8; - - return *this; -} - -} // namespace Poco diff --git a/Framework/Kernel/test/ConfigServiceTest.h b/Framework/Kernel/test/ConfigServiceTest.h index 1ed9a84044dd9a3ab6206ff5985e455fb1284fc9..c0cc52596ffe67068015ba003fae9c0ac4e66716 100644 --- a/Framework/Kernel/test/ConfigServiceTest.h +++ b/Framework/Kernel/test/ConfigServiceTest.h @@ -6,7 +6,6 @@ #include "MantidKernel/ConfigService.h" #include "MantidKernel/Logger.h" #include "MantidKernel/TestChannel.h" -#include "MantidKernel/FilterChannel.h" #include "MantidKernel/InstrumentInfo.h" #include "MantidKernel/FacilityInfo.h" @@ -117,73 +116,18 @@ public: log1.debug("a debug string with offset 999 should be trace")); } - void testLogLevelFiltering() { - TS_ASSERT_THROWS_NOTHING(ConfigService::Instance().setConsoleLogLevel(4)); - TSM_ASSERT_THROWS( - "A false channel name for setFilterChannelLogLevel did not throw", - ConfigService::Instance().setFilterChannelLogLevel( - "AnIncorrectChannelName", 4), - std::invalid_argument); - TSM_ASSERT_THROWS( - "A correct channel name, but not a filterChannel for " - "setFilterChannelLogLevel did not throw", - ConfigService::Instance().setFilterChannelLogLevel("consoleChannel", 4), - std::invalid_argument); - } - - void testLogLevelChangesWithFilteringLevels() { + void testLogLevelChanges() { Logger log1("testLogLevelChangesWithFilteringLevels"); - TS_ASSERT_THROWS_NOTHING(ConfigService::Instance().setConsoleLogLevel(4)); + TS_ASSERT_THROWS_NOTHING(ConfigService::Instance().setLogLevel(4)); TSM_ASSERT("The log level should be 4 after the filters are set to 4", log1.is(4)); - TS_ASSERT_THROWS_NOTHING(ConfigService::Instance().setConsoleLogLevel(3)); + TS_ASSERT_THROWS_NOTHING(ConfigService::Instance().setLogLevel(3)); TSM_ASSERT("The log level should be 3 after the filters are set to 3", log1.is(3)); // return back to previous values - TS_ASSERT_THROWS_NOTHING(ConfigService::Instance().setConsoleLogLevel(4)); - } - - void testRegisteringaNewFilter() { - Logger log1("testRegisteringaNewFilter"); - Poco::FilterChannel *testFilterChannel = new Poco::FilterChannel(); - std::string m_FilterChannelName = "testRegisteringaNewFilter"; - - // Setup logging - auto &rootLogger = Poco::Logger::root(); - auto *rootChannel = Poco::Logger::root().getChannel(); - // The root channel might be a SplitterChannel - if (auto *splitChannel = - dynamic_cast<Poco::SplitterChannel *>(rootChannel)) { - splitChannel->addChannel(testFilterChannel); - } else { - Poco::Logger::setChannel(rootLogger.name(), testFilterChannel); - } - - auto &configService = ConfigService::Instance(); - configService.registerLoggingFilterChannel(m_FilterChannelName, - testFilterChannel); - - int prevLogLevel = log1.getLevel(); - TSM_ASSERT("The log level start above PRIO_TRACE", - log1.getLevel() < Logger::Priority::PRIO_TRACE); - - configService.setFilterChannelLogLevel(m_FilterChannelName, - Logger::Priority::PRIO_TRACE); - TSM_ASSERT("The log level should be PRIO_TRACE", - log1.getLevel() == Logger::Priority::PRIO_TRACE); - TSM_ASSERT("The log filter priority should be PRIO_TRACE", - testFilterChannel->getPriority() == - Logger::Priority::PRIO_TRACE); - - configService.setFilterChannelLogLevel(m_FilterChannelName, prevLogLevel); - TSM_ASSERT("The log level should be " + std::to_string(prevLogLevel), - log1.getLevel() == prevLogLevel); - TSM_ASSERT("The log filter priority should be " + - std::to_string(prevLogLevel), - testFilterChannel->getPriority() == - static_cast<unsigned int>(prevLogLevel)); + TS_ASSERT_THROWS_NOTHING(ConfigService::Instance().setLogLevel(4)); } void testDefaultFacility() { diff --git a/Framework/Kernel/test/FilterChannelTest.h b/Framework/Kernel/test/FilterChannelTest.h deleted file mode 100644 index e21210140e4e6c84d488d64a719e02a7cf73e9ce..0000000000000000000000000000000000000000 --- a/Framework/Kernel/test/FilterChannelTest.h +++ /dev/null @@ -1,229 +0,0 @@ -#ifndef MANTID_FILTERCHANNELTEST_H_ -#define MANTID_FILTERCHANNELTEST_H_ - -#include <cxxtest/TestSuite.h> - -#include "MantidKernel/FilterChannel.h" -#include "MantidKernel/ConfigService.h" -#include "MantidKernel/TestChannel.h" -#include <Poco/Channel.h> -#include <Poco/Message.h> -#include <Poco/LoggingFactory.h> -#include <Poco/LoggingRegistry.h> -#include <boost/make_shared.hpp> -#include <boost/shared_ptr.hpp> -#include <map> -#include <string> - -using namespace Mantid::Kernel; -using Mantid::TestChannel; - -class FilterChannelTest : public CxxTest::TestSuite { -public: - void testContructor() { TS_ASSERT_THROWS_NOTHING(Poco::FilterChannel a;) } - - void testContructorDefaults() { - Poco::FilterChannel a; - TestChannel *empty = nullptr; - TS_ASSERT_EQUALS(a.getPriority(), 8); - TS_ASSERT_EQUALS(a.getChannel(), empty); - } - - void testSetPriority() { - Poco::FilterChannel a; - TS_ASSERT_EQUALS(a.getPriority(), 8); - - TS_ASSERT_EQUALS(a.setPriority("prio_fatal").getPriority(), 1); - TS_ASSERT_EQUALS(a.setPriority("prio_trace").getPriority(), 8); - TS_ASSERT_EQUALS(a.setPriority("fatal").getPriority(), 1); - TS_ASSERT_EQUALS(a.setPriority("trace").getPriority(), 8); - TS_ASSERT_EQUALS(a.setPriority("FATAL").getPriority(), 1); - TS_ASSERT_EQUALS(a.setPriority("tRaCe").getPriority(), 8); - - TS_ASSERT_EQUALS(a.setPriority("FATAL").getPriority(), 1); - TS_ASSERT_EQUALS(a.setPriority("CRITICAL").getPriority(), 2); - TS_ASSERT_EQUALS(a.setPriority("ERROR").getPriority(), 3); - TS_ASSERT_EQUALS(a.setPriority("WARNING").getPriority(), 4); - TS_ASSERT_EQUALS(a.setPriority("NOTICE").getPriority(), 5); - TS_ASSERT_EQUALS(a.setPriority("INFORMATION").getPriority(), 6); - TS_ASSERT_EQUALS(a.setPriority("DEBUG").getPriority(), 7); - TS_ASSERT_EQUALS(a.setPriority("TRACE").getPriority(), 8); - - // abbreviations - TS_ASSERT_EQUALS(a.setPriority("WARN").getPriority(), 4); - TS_ASSERT_EQUALS(a.setPriority("INFO").getPriority(), 6); - } - - void testSetPriorityThroughProperty() { - Poco::FilterChannel a; - TS_ASSERT_EQUALS(a.getPriority(), 8); - - a.setProperty("level", "prio_fatal"); - TS_ASSERT_EQUALS(a.getPriority(), 1); - a.setProperty("level", "prio_trace"); - TS_ASSERT_EQUALS(a.getPriority(), 8); - a.setProperty("level", "fatal"); - TS_ASSERT_EQUALS(a.getPriority(), 1); - a.setProperty("level", "trace"); - TS_ASSERT_EQUALS(a.getPriority(), 8); - a.setProperty("level", "FATAL"); - TS_ASSERT_EQUALS(a.getPriority(), 1); - a.setProperty("level", "tRaCe"); - TS_ASSERT_EQUALS(a.getPriority(), 8); - - a.setProperty("level", "FATAL"); - TS_ASSERT_EQUALS(a.getPriority(), 1); - a.setProperty("level", "CRITICAL"); - TS_ASSERT_EQUALS(a.getPriority(), 2); - a.setProperty("level", "ERROR"); - TS_ASSERT_EQUALS(a.getPriority(), 3); - a.setProperty("level", "WARNING"); - TS_ASSERT_EQUALS(a.getPriority(), 4); - a.setProperty("level", "NOTICE"); - TS_ASSERT_EQUALS(a.getPriority(), 5); - a.setProperty("level", "INFORMATION"); - TS_ASSERT_EQUALS(a.getPriority(), 6); - a.setProperty("level", "DEBUG"); - TS_ASSERT_EQUALS(a.getPriority(), 7); - a.setProperty("level", "TRACE"); - TS_ASSERT_EQUALS(a.getPriority(), 8); - - // abbreviations - a.setProperty("level", "WARN"); - TS_ASSERT_EQUALS(a.getPriority(), 4); - a.setProperty("level", "INFO"); - TS_ASSERT_EQUALS(a.getPriority(), 6); - } - - void testAddChannel() { - boost::shared_ptr<TestChannel> tChannel = boost::make_shared<TestChannel>(); - Poco::FilterChannel a; - TestChannel *empty = nullptr; - - TS_ASSERT_EQUALS(a.getChannel(), empty); - a.addChannel(tChannel.get()); - TS_ASSERT_EQUALS(a.getChannel(), tChannel.get()); - } - - void testLogMessage() { - boost::shared_ptr<TestChannel> tChannel = boost::make_shared<TestChannel>(); - Poco::FilterChannel a; - a.addChannel(tChannel.get()); - Poco::Message msg; - a.log(msg); - TS_ASSERT_EQUALS(tChannel->list().size(), 1); - } - void testSimpleLogMessagesByPriority() { - // initialise the channel - boost::shared_ptr<TestChannel> tChannel = boost::make_shared<TestChannel>(); - Poco::FilterChannel a; - a.addChannel(tChannel.get()); - Poco::Message msg; - a.setPriority(Poco::Message::Priority::PRIO_INFORMATION); - msg.setPriority(Poco::Message::Priority::PRIO_NOTICE); - a.log(msg); - TSM_ASSERT_EQUALS("Message of greater priority failed to get through", - tChannel->list().size(), 1); - msg.setPriority(Poco::Message::Priority::PRIO_INFORMATION); - a.log(msg); - TSM_ASSERT_EQUALS("Message of equal priority failed to get through", - tChannel->list().size(), 2); - msg.setPriority(Poco::Message::Priority::PRIO_DEBUG); - a.log(msg); - TSM_ASSERT_EQUALS("Message of lesser priority managed to get through", - tChannel->list().size(), 2); - } - void testLogMessagesByPriority() { - // initialise the channel - boost::shared_ptr<TestChannel> tChannel = boost::make_shared<TestChannel>(); - Poco::FilterChannel a; - a.addChannel(tChannel.get()); - - // create a priority map - using priorityMap = std::map<unsigned int, std::string>; - priorityMap pMap; - pMap.insert(priorityMap::value_type(1, "FATAL")); - pMap.insert(priorityMap::value_type(2, "CRITICAL")); - pMap.insert(priorityMap::value_type(3, "ERROR")); - pMap.insert(priorityMap::value_type(4, "WARNING")); - pMap.insert(priorityMap::value_type(5, "NOTICE")); - pMap.insert(priorityMap::value_type(6, "INFORMATION")); - pMap.insert(priorityMap::value_type(7, "DEBUG")); - pMap.insert(priorityMap::value_type(8, "TRACE")); - - Poco::Message msg; - int totalCount = 0; - - priorityMap::iterator iter; - for (iter = pMap.begin(); iter != pMap.end(); ++iter) { - size_t channelPriority = (*iter).first; - std::string priorityString = (*iter).second; - a.setPriority(priorityString); - - for (size_t msgPriority = 0; msgPriority < 8; ++msgPriority) { - msg.setPriority(static_cast<Poco::Message::Priority>(msgPriority)); - - size_t previousMessageCount = tChannel->list().size(); - a.log(msg); - size_t addedMessageCount = - tChannel->list().size() - previousMessageCount; - - if ((channelPriority >= msgPriority) && (addedMessageCount == 1)) { - // count should have increased - ++totalCount; - } else if ((channelPriority < msgPriority) && - (addedMessageCount == 0)) { - // count should not have increased and that is good - } else { - // something else happened and that is bad - if (addedMessageCount == 1) - TS_FAIL("Message incorrectly passed the filter criteria"); - else - TS_FAIL("Message incorrectly stopped by the filter criteria"); - std::cerr << "Message Priority=" << msgPriority << '\n'; - std::cerr << "Channel Priority=" << channelPriority << '\n'; - std::cerr << "addedMessageCount=" << addedMessageCount << '\n'; - } - } - } - - TS_ASSERT_EQUALS(tChannel->list().size(), totalCount); - } - - void testAddChannelThroughProperty() { - Poco::FilterChannel a; - TestChannel *empty = nullptr; - // initialise the test channel and put it into the registry - TestChannel *tChannel = new TestChannel; - Poco::LoggingRegistry::defaultRegistry().registerChannel("tChannel", - tChannel); - - TS_ASSERT_EQUALS(a.getChannel(), empty); - a.setProperty("channel", "tChannel"); - - Poco::Channel *createdChannel = a.getChannel(); - TestChannel *castedTestChannel = - dynamic_cast<TestChannel *>(createdChannel); - TS_ASSERT_EQUALS(castedTestChannel, tChannel); - - Poco::LoggingRegistry::defaultRegistry().unregisterChannel("tChannel"); - tChannel->release(); - } - - void testCreateThroughFactory() { - // Ensure that the ConfigService has started as this registers the - // FilterChannel into the factory - ConfigService::Instance(); - - Poco::FilterChannel *empty = nullptr; - - Poco::Channel *createdChannel = - Poco::LoggingFactory::defaultFactory().createChannel("FilterChannel"); - Poco::FilterChannel *castedFilterChannel = - dynamic_cast<Poco::FilterChannel *>(createdChannel); - TS_ASSERT_DIFFERS(castedFilterChannel, empty); - createdChannel->release(); - } -}; - -#endif /*MANTID_FILTERCHANNELTEST_H_*/ diff --git a/Framework/Properties/Mantid.properties.template b/Framework/Properties/Mantid.properties.template index 1b518930adc96009ff1998ffc4ec7f1ffd4f1f75..49ef3a0456d8a8b886dfd21ba217bb7312559da6 100644 --- a/Framework/Properties/Mantid.properties.template +++ b/Framework/Properties/Mantid.properties.template @@ -169,16 +169,11 @@ graph1d.autodistribution = On # logging configuration # root level message filter (This sets a minimal level possible for any channel) -logging.loggers.root.level = information +logging.loggers.root.level = notice # splitting the messages to many logging channels logging.loggers.root.channel.class = SplitterChannel -logging.loggers.root.channel.channel1 = consoleFilterChannel - -# specific filter for the console channel raising the level to notice (drop to debug for debugging) -logging.channels.consoleFilterChannel.class= FilterChannel -logging.channels.consoleFilterChannel.channel= consoleChannel -logging.channels.consoleFilterChannel.level= notice +logging.loggers.root.channel.channel1 = consoleChannel # output to the console - primarily for console based apps logging.channels.consoleChannel.class = @CONSOLECHANNELCLASS@ diff --git a/Framework/PythonInterface/mantid/kernel/src/Exports/ConfigService.cpp b/Framework/PythonInterface/mantid/kernel/src/Exports/ConfigService.cpp index cbc672f2c4118419fd39a5f05b8947bf9ee8582b..256cb0b123f1ae5a59373537d1a29ddc2c0fb9b1 100644 --- a/Framework/PythonInterface/mantid/kernel/src/Exports/ConfigService.cpp +++ b/Framework/PythonInterface/mantid/kernel/src/Exports/ConfigService.cpp @@ -162,9 +162,9 @@ void export_ConfigService() { "Saves the keys that have changed from their default to the given " "filename") - .def("setConsoleLogLevel", &ConfigServiceImpl::setConsoleLogLevel, + .def("setLogLevel", &ConfigServiceImpl::setLogLevel, (arg("self"), arg("logLevel")), - "Sets the log level priority for the Console log channel, logLevel " + "Sets the log level priority for all the log channels, logLevel " "1 = Fatal, 6 = information, 7 = Debug") .def("keys", &ConfigServiceImpl::keys, arg("self")) diff --git a/Framework/PythonInterface/test/python/mantid/kernel/ConfigServiceTest.py b/Framework/PythonInterface/test/python/mantid/kernel/ConfigServiceTest.py index 752519547a0a17e3f1697ad71e785c92f52c490f..18c830ac7b87182a20349e2f459ecea6ac6637f0 100644 --- a/Framework/PythonInterface/test/python/mantid/kernel/ConfigServiceTest.py +++ b/Framework/PythonInterface/test/python/mantid/kernel/ConfigServiceTest.py @@ -94,8 +94,7 @@ class ConfigServiceTest(unittest.TestCase): self._clean_up_test_areas() def test_setting_log_channel_levels(self): - testhelpers.assertRaisesNothing(self, config.setFileLogLevel, 4) - testhelpers.assertRaisesNothing(self, config.setConsoleLogLevel, 4) + testhelpers.assertRaisesNothing(self, config.setLogLevel, 4) def _setup_test_areas(self): """Create a new data search path string diff --git a/qt/widgets/common/inc/MantidQtWidgets/Common/MessageDisplay.h b/qt/widgets/common/inc/MantidQtWidgets/Common/MessageDisplay.h index 0f5db76bfe24bf242e4e4c14d5622f69a7e4ffe9..b88dce6800c5ad5ba7eded8296962fce4da1cacd 100644 --- a/qt/widgets/common/inc/MantidQtWidgets/Common/MessageDisplay.h +++ b/qt/widgets/common/inc/MantidQtWidgets/Common/MessageDisplay.h @@ -5,7 +5,6 @@ // Includes //---------------------------------- #include "DllOption.h" -#include "MantidKernel/FilterChannel.h" #include "MantidQtWidgets/Common/Configurable.h" #include "MantidQtWidgets/Common/Message.h" #include "MantidQtWidgets/Common/QtSignalChannel.h" @@ -112,8 +111,6 @@ private: /// A reference to the log channel QtSignalChannel *m_logChannel; - /// A reference to the log channel - Poco::FilterChannel *m_filterChannel; /// The actual widget holding the text QPlainTextEdit *m_textDisplay; /// Map priority to text formatting @@ -124,8 +121,6 @@ private: QSignalMapper *m_logLevelMapping; /// Log level actions QAction *m_error, *m_warning, *m_notice, *m_information, *m_debug; - /// Name of the filter channel registered with Poco - std::string m_filterChannelName; }; } } diff --git a/qt/widgets/common/src/MessageDisplay.cpp b/qt/widgets/common/src/MessageDisplay.cpp index 2f76a231f68c126d55fb5f98e94fa3749c2ac4d0..77fc080b1af246226241f01d9b66d60a471360b2 100644 --- a/qt/widgets/common/src/MessageDisplay.cpp +++ b/qt/widgets/common/src/MessageDisplay.cpp @@ -43,8 +43,7 @@ namespace MantidWidgets { void MessageDisplay::readSettings(const QSettings &storage) { const int logLevel = storage.value("MessageDisplayPriority", 0).toInt(); if (logLevel > 0) { - ConfigService::Instance().setFilterChannelLogLevel(m_filterChannelName, - logLevel, true); + ConfigService::Instance().setLogLevel(logLevel, true); } } @@ -57,7 +56,7 @@ void MessageDisplay::readSettings(const QSettings &storage) { void MessageDisplay::writeSettings(QSettings *storage) { Q_ASSERT(storage); storage->setValue("MessageDisplayPriority", - static_cast<int>(m_filterChannel->getPriority())); + Poco::Logger::root().getLevel()); } /** @@ -65,7 +64,6 @@ void MessageDisplay::writeSettings(QSettings *storage) { */ MessageDisplay::MessageDisplay(QWidget *parent) : QWidget(parent), m_logChannel(new QtSignalChannel), - m_filterChannel(new Poco::FilterChannel), m_textDisplay(new QPlainTextEdit(this)), m_formats(), m_loglevels(new QActionGroup(this)), m_logLevelMapping(new QSignalMapper(this)), @@ -73,7 +71,7 @@ MessageDisplay::MessageDisplay(QWidget *parent) 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)), m_filterChannelName() { + m_debug(new QAction(tr("&Debug"), this)) { initActions(); initFormats(); setupTextArea(); @@ -84,7 +82,6 @@ MessageDisplay::MessageDisplay(QWidget *parent) MessageDisplay::~MessageDisplay() { // The Channel class is ref counted and will // delete itself when required - m_filterChannel->release(); m_logChannel->release(); delete m_textDisplay; } @@ -102,17 +99,14 @@ void MessageDisplay::attachLoggingChannel(int logLevel) { auto *rootChannel = Poco::Logger::root().getChannel(); // The root channel might be a SplitterChannel if (auto *splitChannel = dynamic_cast<Poco::SplitterChannel *>(rootChannel)) { - splitChannel->addChannel(m_filterChannel); + splitChannel->addChannel(m_logChannel); } else { - Poco::Logger::setChannel(rootLogger.name(), m_filterChannel); + Poco::Logger::setChannel(rootLogger.name(), m_logChannel); } - m_filterChannel->addChannel(m_logChannel); - m_filterChannelName = "MessageDisplayChannel" + std::to_string(ATTACH_COUNT); - configSvc.registerLoggingFilterChannel(m_filterChannelName, m_filterChannel); connect(m_logChannel, SIGNAL(messageReceived(const Message &)), this, SLOT(append(const Message &))); if (logLevel > 0) { - configSvc.setFilterChannelLogLevel(m_filterChannelName, logLevel, true); + configSvc.setLogLevel(logLevel, true); } ++ATTACH_COUNT; } @@ -266,12 +260,7 @@ void MessageDisplay::showContextMenu(const QPoint &mousePos) { logLevelMenu->addAction(m_debug); // check the right level - int level = m_filterChannel->getPriority(); - // get the root logger logging level - int rootLevel = Poco::Logger::root().getLevel(); - if (rootLevel < level) { - level = rootLevel; - } + int level = Poco::Logger::root().getLevel(); if (level == Poco::Message::PRIO_ERROR) m_error->setChecked(true); if (level == Poco::Message::PRIO_WARNING) @@ -292,8 +281,7 @@ void MessageDisplay::showContextMenu(const QPoint &mousePos) { * enumeration */ void MessageDisplay::setLogLevel(int priority) { - ConfigService::Instance().setFilterChannelLogLevel(m_filterChannelName, - priority); + ConfigService::Instance().setLogLevel(priority); } //-----------------------------------------------------------------------------