mirror of
https://github.com/ClickHouse/ClickHouse.git
synced 2024-11-21 23:21:59 +00:00
libpocoext
- Добавлен класс фильтрации логов libcommon - В Daemon(и наследниках) можно использовать лог-файл для вывода только ошибок
This commit is contained in:
parent
bb8cf39a6f
commit
c02649ce87
@ -17,7 +17,7 @@
|
|||||||
#include <Poco/AutoPtr.h>
|
#include <Poco/AutoPtr.h>
|
||||||
#include <Poco/PatternFormatter.h>
|
#include <Poco/PatternFormatter.h>
|
||||||
#include <Poco/SplitterChannel.h>
|
#include <Poco/SplitterChannel.h>
|
||||||
//#include <Poco/LevelFilterChannel.h>
|
#include <Poco/Ext/LevelFilterChannel.h>
|
||||||
#include <Poco/FormattingChannel.h>
|
#include <Poco/FormattingChannel.h>
|
||||||
#include <Poco/ConsoleChannel.h>
|
#include <Poco/ConsoleChannel.h>
|
||||||
#include <Poco/FileChannel.h>
|
#include <Poco/FileChannel.h>
|
||||||
@ -129,8 +129,8 @@ void Daemon::buildLoggers()
|
|||||||
if( config().hasProperty("logger.errorlog") )
|
if( config().hasProperty("logger.errorlog") )
|
||||||
{
|
{
|
||||||
std::cerr << "Should error logs to " << config().getString("logger.errorlog") << std::endl;
|
std::cerr << "Should error logs to " << config().getString("logger.errorlog") << std::endl;
|
||||||
//Poco::LevelFilterChannel *level = new Poco::LevelFilterChannel();
|
Poco::LevelFilterChannel *level = new Poco::LevelFilterChannel();
|
||||||
//level->setLevel(Message::PRIO_NOTICE);
|
level->setLevel(Message::PRIO_NOTICE);
|
||||||
PatternFormatter *pf = new PatternFormatter(format);
|
PatternFormatter *pf = new PatternFormatter(format);
|
||||||
pf->setProperty("times", "local");
|
pf->setProperty("times", "local");
|
||||||
FormattingChannel *errorlog = new FormattingChannel(pf);
|
FormattingChannel *errorlog = new FormattingChannel(pf);
|
||||||
@ -140,8 +140,8 @@ void Daemon::buildLoggers()
|
|||||||
errorfile->setProperty("archive", "number");
|
errorfile->setProperty("archive", "number");
|
||||||
errorfile->setProperty("purgeCount", config().getRawString("logger.count", "1"));
|
errorfile->setProperty("purgeCount", config().getRawString("logger.count", "1"));
|
||||||
errorlog->setChannel(errorfile);
|
errorlog->setChannel(errorfile);
|
||||||
//level->setChannel(errorlog);
|
level->setChannel(errorlog);
|
||||||
//split->addChannel(level);
|
split->addChannel(level);
|
||||||
errorlog->open();
|
errorlog->open();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
101
libs/libpocoext/include/Poco/Ext/LevelFilterChannel.h
Normal file
101
libs/libpocoext/include/Poco/Ext/LevelFilterChannel.h
Normal file
@ -0,0 +1,101 @@
|
|||||||
|
//
|
||||||
|
// LevelFilterChannel.h
|
||||||
|
//
|
||||||
|
// $Id$
|
||||||
|
//
|
||||||
|
// Library: Ext
|
||||||
|
// Package: Logging
|
||||||
|
// Module: LevelFilterChannel
|
||||||
|
//
|
||||||
|
// Definition of the ISO_8859_5Encoding class.
|
||||||
|
//
|
||||||
|
// Copyright (c) 2004-2007, Applied Informatics Software Engineering GmbH.
|
||||||
|
// and Contributors.
|
||||||
|
//
|
||||||
|
// Permission is hereby granted, free of charge, to any person or organization
|
||||||
|
// obtaining a copy of the software and accompanying documentation covered by
|
||||||
|
// this license (the "Software") to use, reproduce, display, distribute,
|
||||||
|
// execute, and transmit the Software, and to prepare derivative works of the
|
||||||
|
// Software, and to permit third-parties to whom the Software is furnished to
|
||||||
|
// do so, all subject to the following:
|
||||||
|
//
|
||||||
|
// The copyright notices in the Software and this entire statement, including
|
||||||
|
// the above license grant, this restriction and the following disclaimer,
|
||||||
|
// must be included in all copies of the Software, in whole or in part, and
|
||||||
|
// all derivative works of the Software, unless such copies or derivative
|
||||||
|
// works are solely in the form of machine-executable object code generated by
|
||||||
|
// a source language processor.
|
||||||
|
//
|
||||||
|
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||||
|
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||||
|
// FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT
|
||||||
|
// SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE
|
||||||
|
// FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE,
|
||||||
|
// ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
|
||||||
|
// DEALINGS IN THE SOFTWARE.
|
||||||
|
//
|
||||||
|
|
||||||
|
|
||||||
|
#ifndef Foundation_LevelFilterChannel_INCLUDED
|
||||||
|
#define Foundation_LevelFilterChannel_INCLUDED
|
||||||
|
|
||||||
|
|
||||||
|
#include "Poco/Foundation.h"
|
||||||
|
#include "Poco/Channel.h"
|
||||||
|
#include "Poco/Mutex.h"
|
||||||
|
#include "Poco/Message.h"
|
||||||
|
#include <vector>
|
||||||
|
|
||||||
|
|
||||||
|
namespace Poco {
|
||||||
|
|
||||||
|
|
||||||
|
class Foundation_API LevelFilterChannel: public Channel
|
||||||
|
/// This channel sends messages only higher then specified level
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
LevelFilterChannel();
|
||||||
|
|
||||||
|
void log(const Message& msg);
|
||||||
|
/// Sends the given Message to all
|
||||||
|
/// attaches channels.
|
||||||
|
|
||||||
|
void setProperty(const std::string& name, const std::string& value);
|
||||||
|
/// Sets or changes a configuration property.
|
||||||
|
///
|
||||||
|
/// Only the "level" property is supported, which allows setting desired level
|
||||||
|
|
||||||
|
void setChannel(Channel* pChannel);
|
||||||
|
/// Sets the destination channel to which the formatted
|
||||||
|
/// messages are passed on.
|
||||||
|
|
||||||
|
Channel* getChannel() const;
|
||||||
|
/// Returns the channel to which the formatted
|
||||||
|
/// messages are passed on.
|
||||||
|
|
||||||
|
void open();
|
||||||
|
/// Opens the attached channel.
|
||||||
|
|
||||||
|
void close();
|
||||||
|
/// Closes the attached channel.
|
||||||
|
|
||||||
|
void setLevel(Message::Priority);
|
||||||
|
/// Sets the Logger's log level.
|
||||||
|
void setLevel(const std::string& value);
|
||||||
|
/// Sets the Logger's log level using a symbolic value.
|
||||||
|
Message::Priority getLevel() const;
|
||||||
|
/// Returns the Logger's log level.
|
||||||
|
|
||||||
|
protected:
|
||||||
|
~LevelFilterChannel();
|
||||||
|
|
||||||
|
private:
|
||||||
|
Channel* _channel;
|
||||||
|
Message::Priority _priority;
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
|
} // namespace Poco
|
||||||
|
|
||||||
|
|
||||||
|
#endif // Foundation_LevelFilterChannel_INCLUDED
|
139
libs/libpocoext/src/LevelFilterChannel.cpp
Normal file
139
libs/libpocoext/src/LevelFilterChannel.cpp
Normal file
@ -0,0 +1,139 @@
|
|||||||
|
//
|
||||||
|
// LevelFilterChannel.cpp
|
||||||
|
//
|
||||||
|
// $Id$
|
||||||
|
//
|
||||||
|
// Library: Ext
|
||||||
|
// Package: Logging
|
||||||
|
// Module: LevelFilterChannel
|
||||||
|
//
|
||||||
|
// Copyright (c) 2004-2007, Applied Informatics Software Engineering GmbH.
|
||||||
|
// and Contributors.
|
||||||
|
//
|
||||||
|
// Permission is hereby granted, free of charge, to any person or organization
|
||||||
|
// obtaining a copy of the software and accompanying documentation covered by
|
||||||
|
// this license (the "Software") to use, reproduce, display, distribute,
|
||||||
|
// execute, and transmit the Software, and to prepare derivative works of the
|
||||||
|
// Software, and to permit third-parties to whom the Software is furnished to
|
||||||
|
// do so, all subject to the following:
|
||||||
|
//
|
||||||
|
// The copyright notices in the Software and this entire statement, including
|
||||||
|
// the above license grant, this restriction and the following disclaimer,
|
||||||
|
// must be included in all copies of the Software, in whole or in part, and
|
||||||
|
// all derivative works of the Software, unless such copies or derivative
|
||||||
|
// works are solely in the form of machine-executable object code generated by
|
||||||
|
// a source language processor.
|
||||||
|
//
|
||||||
|
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||||
|
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||||
|
// FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT
|
||||||
|
// SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE
|
||||||
|
// FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE,
|
||||||
|
// ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
|
||||||
|
// DEALINGS IN THE SOFTWARE.
|
||||||
|
//
|
||||||
|
|
||||||
|
|
||||||
|
#include "Poco/Ext/LevelFilterChannel.h"
|
||||||
|
#include "Poco/LoggingRegistry.h"
|
||||||
|
#include "Poco/String.h"
|
||||||
|
|
||||||
|
|
||||||
|
namespace Poco {
|
||||||
|
|
||||||
|
|
||||||
|
LevelFilterChannel::LevelFilterChannel()
|
||||||
|
: Channel(), _channel(NULL), _priority(Message::PRIO_ERROR)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
LevelFilterChannel::~LevelFilterChannel()
|
||||||
|
{
|
||||||
|
if (_channel)
|
||||||
|
_channel->release();
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void LevelFilterChannel::setChannel(Channel* channel)
|
||||||
|
{
|
||||||
|
if (_channel)
|
||||||
|
_channel->release();
|
||||||
|
_channel = channel;
|
||||||
|
if (_channel)
|
||||||
|
_channel->duplicate();
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
Channel* LevelFilterChannel::getChannel() const
|
||||||
|
{
|
||||||
|
return _channel;
|
||||||
|
}
|
||||||
|
|
||||||
|
void LevelFilterChannel::open()
|
||||||
|
{
|
||||||
|
if (_channel)
|
||||||
|
_channel->open();
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void LevelFilterChannel::close()
|
||||||
|
{
|
||||||
|
if (_channel)
|
||||||
|
_channel->close();
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void LevelFilterChannel::setLevel(Message::Priority priority)
|
||||||
|
{
|
||||||
|
_priority = priority;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void LevelFilterChannel::setLevel(const std::string& value)
|
||||||
|
{
|
||||||
|
if (icompare(value, "fatal") == 0)
|
||||||
|
setLevel(Message::PRIO_FATAL);
|
||||||
|
else if (icompare(value, "critical") == 0)
|
||||||
|
setLevel(Message::PRIO_CRITICAL);
|
||||||
|
else if (icompare(value, "error") == 0)
|
||||||
|
setLevel(Message::PRIO_ERROR);
|
||||||
|
else if (icompare(value, "warning") == 0)
|
||||||
|
setLevel(Message::PRIO_WARNING);
|
||||||
|
else if (icompare(value, "notice") == 0)
|
||||||
|
setLevel(Message::PRIO_NOTICE);
|
||||||
|
else if (icompare(value, "information") == 0)
|
||||||
|
setLevel(Message::PRIO_INFORMATION);
|
||||||
|
else if (icompare(value, "debug") == 0)
|
||||||
|
setLevel(Message::PRIO_DEBUG);
|
||||||
|
else if (icompare(value, "trace") == 0)
|
||||||
|
setLevel(Message::PRIO_TRACE);
|
||||||
|
else
|
||||||
|
throw InvalidArgumentException("Not a valid log value", value);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
Message::Priority LevelFilterChannel::getLevel() const
|
||||||
|
{
|
||||||
|
return _priority;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void LevelFilterChannel::setProperty(const std::string& name, const std::string& value)
|
||||||
|
{
|
||||||
|
if (icompare(name, "level") == 0)
|
||||||
|
setLevel(value);
|
||||||
|
else if (icompare(name, "channel") == 0)
|
||||||
|
setChannel(LoggingRegistry::defaultRegistry().channelForName(value));
|
||||||
|
else
|
||||||
|
Channel::setProperty(name, value);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void LevelFilterChannel::log(const Message& msg)
|
||||||
|
{
|
||||||
|
if ((_priority >= msg.getPriority()) && _channel)
|
||||||
|
_channel->log(msg);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
} // namespace Poco
|
Loading…
Reference in New Issue
Block a user