mirror of
https://github.com/ClickHouse/ClickHouse.git
synced 2024-11-10 09:32:06 +00:00
Introduce logging in shared library dictionaries
This commit is contained in:
parent
ead9493741
commit
4e3dc0d8a2
@ -124,12 +124,18 @@ LibraryDictionarySource::LibraryDictionarySource(const DictionaryStructure & dic
|
||||
description.init(sample_block);
|
||||
library = std::make_shared<SharedLibrary>(path);
|
||||
settings = std::make_shared<CStringsHolder>(getLibSettings(config, config_prefix + lib_config_settings));
|
||||
if (auto libNew = library->tryGet<decltype(lib_data) (*)(decltype(&settings->strings))>("ClickHouseDictionary_v2_libNew"))
|
||||
if (auto libNew = library->tryGet<decltype(lib_data) (*)(decltype(&settings->strings), ClickHouseLibrary::CLogger*)>("ClickHouseDictionary_v2_libNew")) {
|
||||
clogger = std::make_shared<ClickHouseLibrary::CLogger>();
|
||||
ClickHouseLibrary::initDictLogger(clogger.get());
|
||||
lib_data = libNew(&settings->strings, clogger.get());
|
||||
} else if (auto libNew = library->tryGet<decltype(lib_data) (*)(decltype(&settings->strings))>("ClickHouseDictionary_v2_libNew")) {
|
||||
lib_data = libNew(&settings->strings);
|
||||
}
|
||||
}
|
||||
|
||||
LibraryDictionarySource::LibraryDictionarySource(const LibraryDictionarySource & other)
|
||||
: log(&Logger::get("LibraryDictionarySource"))
|
||||
, clogger{other.clogger}
|
||||
, dict_struct{other.dict_struct}
|
||||
, config_prefix{other.config_prefix}
|
||||
, path{other.path}
|
||||
@ -139,8 +145,11 @@ LibraryDictionarySource::LibraryDictionarySource(const LibraryDictionarySource &
|
||||
, description{other.description}
|
||||
, settings{other.settings}
|
||||
{
|
||||
|
||||
if (auto libClone = library->tryGet<decltype(lib_data) (*)(decltype(other.lib_data))>("ClickHouseDictionary_v2_libClone"))
|
||||
lib_data = libClone(other.lib_data);
|
||||
else if (auto libNew = library->tryGet<decltype(lib_data) (*)(decltype(&settings->strings), ClickHouseLibrary::CLogger*)>("ClickHouseDictionary_v2_libNew"))
|
||||
lib_data = libNew(&settings->strings, clogger.get());
|
||||
else if (auto libNew = library->tryGet<decltype(lib_data) (*)(decltype(&settings->strings))>("ClickHouseDictionary_v2_libNew"))
|
||||
lib_data = libNew(&settings->strings);
|
||||
}
|
||||
|
@ -3,6 +3,7 @@
|
||||
#include <Dictionaries/DictionaryStructure.h>
|
||||
#include <Dictionaries/ExternalResultDescription.h>
|
||||
#include <Dictionaries/IDictionarySource.h>
|
||||
#include <Dictionaries/LibraryDictionarySourceExternal.h>
|
||||
#include <Common/SharedLibrary.h>
|
||||
#include <common/LocalDateTime.h>
|
||||
|
||||
@ -65,6 +66,7 @@ public:
|
||||
|
||||
private:
|
||||
Poco::Logger * log;
|
||||
std::shared_ptr<ClickHouseLibrary::CLogger> clogger;
|
||||
|
||||
LocalDateTime getLastModification() const;
|
||||
|
||||
|
82
dbms/src/Dictionaries/LibraryDictionarySourceExternal.cpp
Normal file
82
dbms/src/Dictionaries/LibraryDictionarySourceExternal.cpp
Normal file
@ -0,0 +1,82 @@
|
||||
#include <Dictionaries/LibraryDictionarySourceExternal.h>
|
||||
#include <common/logger_useful.h>
|
||||
|
||||
namespace
|
||||
{
|
||||
const char DICT_LOGGER_NAME[] = "LibraryDictionarySourceExternal";
|
||||
void trace(ClickHouseLibrary::CString msg)
|
||||
{
|
||||
auto & logger = Logger::get(DICT_LOGGER_NAME);
|
||||
if (logger.trace()) {
|
||||
logger.trace(msg);
|
||||
}
|
||||
}
|
||||
|
||||
void debug(ClickHouseLibrary::CString msg)
|
||||
{
|
||||
auto & logger = Logger::get(DICT_LOGGER_NAME);
|
||||
if (logger.debug()) {
|
||||
logger.debug(msg);
|
||||
}
|
||||
}
|
||||
|
||||
void information(ClickHouseLibrary::CString msg)
|
||||
{
|
||||
auto & logger = Logger::get(DICT_LOGGER_NAME);
|
||||
if (logger.information()) {
|
||||
logger.information(msg);
|
||||
}
|
||||
}
|
||||
|
||||
void notice(ClickHouseLibrary::CString msg)
|
||||
{
|
||||
auto & logger = Logger::get(DICT_LOGGER_NAME);
|
||||
if (logger.notice()) {
|
||||
logger.notice(msg);
|
||||
}
|
||||
}
|
||||
|
||||
void warning(ClickHouseLibrary::CString msg)
|
||||
{
|
||||
auto & logger = Logger::get(DICT_LOGGER_NAME);
|
||||
if (logger.warning()) {
|
||||
logger.warning(msg);
|
||||
}
|
||||
}
|
||||
|
||||
void error(ClickHouseLibrary::CString msg)
|
||||
{
|
||||
auto & logger = Logger::get(DICT_LOGGER_NAME);
|
||||
if (logger.error()) {
|
||||
logger.error(msg);
|
||||
}
|
||||
}
|
||||
|
||||
void critical(ClickHouseLibrary::CString msg)
|
||||
{
|
||||
auto & logger = Logger::get(DICT_LOGGER_NAME);
|
||||
if (logger.critical()) {
|
||||
logger.critical(msg);
|
||||
}
|
||||
}
|
||||
|
||||
void fatal(ClickHouseLibrary::CString msg)
|
||||
{
|
||||
auto & logger = Logger::get(DICT_LOGGER_NAME);
|
||||
if (logger.fatal()) {
|
||||
logger.fatal(msg);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void ClickHouseLibrary::initDictLogger(CLogger * logger) {
|
||||
logger->trace = trace;
|
||||
logger->debug = debug;
|
||||
logger->information = information;
|
||||
logger->notice = notice;
|
||||
logger->warning = warning;
|
||||
logger->error = error;
|
||||
logger->critical = critical;
|
||||
logger->fatal = fatal;
|
||||
}
|
@ -47,4 +47,19 @@ struct Table
|
||||
uint64_t error_code = 0; // 0 = ok; !0 = error, with message in error_string
|
||||
const char * error_string = nullptr;
|
||||
};
|
||||
|
||||
struct CLogger
|
||||
{
|
||||
void (*trace)(CString msg);
|
||||
void (*debug)(CString msg);
|
||||
void (*information)(CString msg);
|
||||
void (*notice)(CString msg);
|
||||
void (*warning)(CString msg);
|
||||
void (*error)(CString msg);
|
||||
void (*critical)(CString msg);
|
||||
void (*fatal)(CString msg);
|
||||
};
|
||||
|
||||
void initDictLogger(CLogger * logger);
|
||||
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user