Added the ability to hook into logging system.
This commit is contained in:
parent
8231c58335
commit
3b0e2f5e85
@ -32,8 +32,22 @@ namespace td {
|
||||
|
||||
LogOptions log_options;
|
||||
|
||||
static std::atomic<int> max_callback_verbosity_level = 0;
|
||||
static std::atomic<OnLogMessageCallback> on_log_message_callback = nullptr;
|
||||
|
||||
void set_log_message_callback(int max_verbosity_level, OnLogMessageCallback callback) {
|
||||
max_callback_verbosity_level = max_verbosity_level;
|
||||
on_log_message_callback = callback;
|
||||
}
|
||||
|
||||
void LogInterface::append(int log_level, CSlice slice) {
|
||||
do_append(log_level, slice);
|
||||
if (log_level <= max_callback_verbosity_level.load(std::memory_order_relaxed)) {
|
||||
auto callback = on_log_message_callback.load(std::memory_order_relaxed);
|
||||
if (callback != nullptr) {
|
||||
callback(log_level, slice);
|
||||
}
|
||||
}
|
||||
if (log_level == VERBOSITY_NAME(FATAL)) {
|
||||
process_fatal_error(slice);
|
||||
}
|
||||
|
@ -185,10 +185,14 @@ class NullLog : public LogInterface {
|
||||
extern LogInterface *const default_log_interface;
|
||||
extern LogInterface *log_interface;
|
||||
|
||||
[[noreturn]] void process_fatal_error(CSlice message);
|
||||
|
||||
// deprecated in favor of set_log_message_callback
|
||||
using OnFatalErrorCallback = void (*)(CSlice message);
|
||||
void set_log_fatal_error_callback(OnFatalErrorCallback callback);
|
||||
|
||||
[[noreturn]] void process_fatal_error(CSlice message);
|
||||
using OnLogMessageCallback = void (*)(int verbosity_level, CSlice message);
|
||||
void set_log_message_callback(int max_verbosity_level, OnLogMessageCallback callback);
|
||||
|
||||
#define TC_RED "\x1b[1;31m"
|
||||
#define TC_BLUE "\x1b[1;34m"
|
||||
|
@ -55,12 +55,14 @@ int KQueue::update(int nevents, const timespec *timeout, bool may_fail) {
|
||||
if (err != -1) {
|
||||
return false;
|
||||
}
|
||||
if (may_fail) {
|
||||
return kevent_errno != ENOENT;
|
||||
if (may_fail && kevent_errno == ENOENT) {
|
||||
return false;
|
||||
}
|
||||
return kevent_errno != EINTR;
|
||||
}();
|
||||
LOG_IF(FATAL, is_fatal_error) << Status::PosixError(kevent_errno, "kevent failed");
|
||||
if (is_fatal_error) {
|
||||
LOG(FATAL) << Status::PosixError(kevent_errno, "kevent failed");
|
||||
}
|
||||
|
||||
changes_n_ = 0;
|
||||
if (err < 0) {
|
||||
|
Loading…
Reference in New Issue
Block a user