-
Notifications
You must be signed in to change notification settings - Fork 410
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
1.logging files name ends with the timestamp;
2.make logger.count/logger.size dynamic updatable
Showing
9 changed files
with
276 additions
and
11 deletions.
There are no files selected for viewing
Submodule poco
updated
3 files
+2 −2 | Foundation/include/Poco/ArchiveStrategy.h | |
+1 −3 | Foundation/include/Poco/FileChannel.h | |
+0 −2 | Foundation/include/Poco/SplitterChannel.h |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
#include "MutableSplitterChannel.h" | ||
|
||
#include <Poco/Ext/LevelFilterChannel.h> | ||
#include <Poco/FormattingChannel.h> | ||
#include <fmt/format.h> | ||
|
||
#include <iostream> | ||
|
||
#include "TiflashLogFileChannel.h" | ||
namespace DB | ||
{ | ||
void MutableSplitterChannel::setPropertiesRecursively(Poco::Logger & logger, Poco::Channel & channel, Poco::Util::AbstractConfiguration & config) | ||
{ | ||
if (typeid(channel) == typeid(TiflashLogFileChannel)) | ||
{ | ||
TiflashLogFileChannel * fileChannel = dynamic_cast<TiflashLogFileChannel *>(&channel); | ||
std::string rotation_size = config.getRawString("logger.size", "100M"); | ||
std::string purge_count = config.getRawString("logger.count", "1"); | ||
logger.information(fmt::format("set channel rotation:{}, purgecount:{}", rotation_size, purge_count)); | ||
fileChannel->setProperty(Poco::FileChannel::PROP_ROTATION, rotation_size); | ||
fileChannel->setProperty(Poco::FileChannel::PROP_PURGECOUNT, purge_count); | ||
return; | ||
} | ||
if (typeid(channel) == typeid(Poco::LevelFilterChannel)) | ||
{ | ||
Poco::LevelFilterChannel * levelFilterChannel = dynamic_cast<Poco::LevelFilterChannel *>(&channel); | ||
setPropertiesRecursively(logger, *levelFilterChannel->getChannel(), config); | ||
return; | ||
} | ||
if (typeid(channel) == typeid(Poco::FormattingChannel)) | ||
{ | ||
Poco::FormattingChannel * formattingChannel = dynamic_cast<Poco::FormattingChannel *>(&channel); | ||
setPropertiesRecursively(logger, *formattingChannel->getChannel(), config); | ||
return; | ||
} | ||
logger.information(fmt::format("invalid channel type:{}", typeid(channel).name())); | ||
} | ||
// only support FormattingChannel --> LevelFilterChannel --> TiflashLogFileChannel or LevelFilterChannel --> TiflashLogFileChannel or TiflashLogFileChannel | ||
void MutableSplitterChannel::changeProperties(Poco::Logger & logger, Poco::Util::AbstractConfiguration & config) | ||
{ | ||
for (auto it : _channels) | ||
{ | ||
setPropertiesRecursively(logger, *it, config); | ||
} | ||
} | ||
} // namespace DB |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
#pragma once | ||
|
||
|
||
#include <Poco/Logger.h> | ||
#include <Poco/SplitterChannel.h> | ||
#include <Poco/Util/AbstractConfiguration.h> | ||
|
||
#include <functional> | ||
namespace DB | ||
{ | ||
class MutableSplitterChannel : public Poco::SplitterChannel | ||
{ | ||
public: | ||
using SplitterChannelValidator = std::function<void(Poco::Channel &, Poco::Util::AbstractConfiguration &)>; | ||
void changeProperties(Poco::Logger & logger, Poco::Util::AbstractConfiguration & config); | ||
// just for test now | ||
void setPropertiesValidator(SplitterChannelValidator validator) { properties_validator = validator; } | ||
void validateProperties(Poco::Util::AbstractConfiguration & expect_config) | ||
{ | ||
for (auto it : _channels) | ||
{ | ||
properties_validator(*it, expect_config); | ||
} | ||
} | ||
|
||
protected: | ||
void setPropertiesRecursively(Poco::Logger & logger, Poco::Channel & channel, Poco::Util::AbstractConfiguration & config); | ||
SplitterChannelValidator properties_validator = nullptr; // just for test now | ||
}; | ||
} // namespace DB |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
#pragma once | ||
#include <Poco/ArchiveStrategy.h> | ||
namespace DB | ||
{ | ||
template <class DT> | ||
class TiflashArchiveByTimestampsStrategy : public Poco::ArchiveByTimestampStrategy<DT> | ||
{ | ||
public: | ||
Poco::LogFile * archive(Poco::LogFile * pFile) override | ||
{ | ||
std::string path = pFile->path(); | ||
delete pFile; | ||
std::string archPath = path; | ||
archPath.append("."); | ||
Poco::DateTimeFormatter::append(archPath, DT().timestamp(), "%Y-%m-%d-%H:%M:%S.%i"); | ||
|
||
if (Poco::ArchiveByTimestampStrategy<DT>::exists(archPath)) | ||
Poco::ArchiveByTimestampStrategy<DT>::archiveByNumber(archPath); | ||
else | ||
Poco::ArchiveByTimestampStrategy<DT>::moveFile(path, archPath); | ||
|
||
return new Poco::LogFile(path); | ||
} | ||
}; | ||
} // namespace DB |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
#include "TiflashLogFileChannel.h" | ||
|
||
#include <Poco/LocalDateTime.h> | ||
|
||
#include "Poco/ArchiveStrategy.h" | ||
#include "Poco/String.h" | ||
#include "TiflashArchiveByTimestampsStrategy.h" | ||
namespace DB | ||
{ | ||
void TiflashLogFileChannel::setArchive(const std::string & archive) | ||
{ | ||
Poco::ArchiveStrategy * pStrategy = 0; | ||
if (archive == "number") | ||
{ | ||
pStrategy = new Poco::ArchiveByNumberStrategy; | ||
} | ||
else if (archive == "timestamp") | ||
{ | ||
if (_times == "utc") | ||
pStrategy = new TiflashArchiveByTimestampsStrategy<Poco::DateTime>; | ||
else if (_times == "local") | ||
pStrategy = new TiflashArchiveByTimestampsStrategy<Poco::LocalDateTime>; | ||
else | ||
throw Poco::PropertyNotSupportedException("times", _times); | ||
} | ||
else | ||
throw Poco::InvalidArgumentException("archive", archive); | ||
delete _pArchiveStrategy; | ||
pStrategy->compress(_compress); | ||
_pArchiveStrategy = pStrategy; | ||
_archive = archive; | ||
} | ||
} // namespace DB |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
#pragma once | ||
#include <Poco/FileChannel.h> | ||
namespace DB | ||
{ | ||
class TiflashLogFileChannel : public Poco::FileChannel | ||
{ | ||
protected: | ||
void setArchive(const std::string & archive) override; | ||
}; | ||
} // namespace DB |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters