1
0
Fork 0
mirror of https://github.com/ton-blockchain/ton synced 2025-03-09 15:40:10 +00:00

bugfixes + tonlib update

This commit is contained in:
ton 2020-04-30 15:04:47 +04:00
parent 2f81361a02
commit eecf05ca59
35 changed files with 734 additions and 193 deletions

View file

@ -95,7 +95,7 @@ void FileLog::append(CSlice cslice, int log_level) {
process_fatal_error(cslice);
}
if (size_ > rotate_threshold_) {
if (size_ > rotate_threshold_ || want_rotate_.load(std::memory_order_relaxed)) {
auto status = rename(path_, PSLICE() << path_ << ".old");
if (status.is_error()) {
process_fatal_error(PSLICE() << status.error() << " in " << __FILE__ << " at " << __LINE__);
@ -111,9 +111,13 @@ void FileLog::rotate() {
do_rotate();
}
void FileLog::lazy_rotate() {
want_rotate_ = true;
}
void FileLog::do_rotate() {
auto current_verbosity_level = GET_VERBOSITY_LEVEL();
SET_VERBOSITY_LEVEL(std::numeric_limits<int>::min()); // to ensure that nothing will be printed to the closed log
want_rotate_ = false;
td::ScopedDisableLog disable_log; // to ensure that nothing will be printed to the closed log
CHECK(!path_.empty());
fd_.close();
auto r_fd = FileFd::open(path_, FileFd::Create | FileFd::Truncate | FileFd::Write);
@ -125,7 +129,6 @@ void FileLog::do_rotate() {
fd_.get_native_fd().duplicate(Stderr().get_native_fd()).ignore();
}
size_ = 0;
SET_VERBOSITY_LEVEL(current_verbosity_level);
}
Result<td::unique_ptr<LogInterface>> FileLog::create(string path, int64 rotate_threshold, bool redirect_stderr) {

View file

@ -46,12 +46,15 @@ class FileLog : public LogInterface {
void rotate() override;
void lazy_rotate();
private:
FileFd fd_;
string path_;
int64 size_ = 0;
int64 rotate_threshold_ = 0;
bool redirect_stderr_;
std::atomic<bool> want_rotate_{};
void do_rotate();
};

View file

@ -166,10 +166,10 @@ double Random::fast(double min, double max) {
Random::Xorshift128plus::Xorshift128plus(uint64 seed) {
auto next = [&]() {
// splitmix64
seed += static_cast<uint64>(0x9E3779B97F4A7C15);
seed += static_cast<uint64>(0x9E3779B97F4A7C15ull);
uint64 z = seed;
z = (z ^ (z >> 30)) * static_cast<uint64>(0xBF58476D1CE4E5B9);
z = (z ^ (z >> 27)) * static_cast<uint64>(0x94D049BB133111EB);
z = (z ^ (z >> 30)) * static_cast<uint64>(0xBF58476D1CE4E5B9ull);
z = (z ^ (z >> 27)) * static_cast<uint64>(0x94D049BB133111EBull);
return z ^ (z >> 31);
};
seed_[0] = next();

View file

@ -89,7 +89,7 @@ class TsFileLog : public LogInterface {
void rotate() override {
for (auto &info : logs_) {
if (info.is_inited.load(std::memory_order_consume)) {
info.log.rotate();
info.log.lazy_rotate();
}
}
}

View file

@ -26,6 +26,7 @@
#include <atomic>
#include <cstdlib>
#include <mutex>
#if TD_ANDROID
#include <android/log.h>
@ -272,4 +273,26 @@ void process_fatal_error(CSlice message) {
std::abort();
}
namespace {
std::mutex sdl_mutex;
int sdl_cnt = 0;
int sdl_verbosity = 0;
} // namespace
ScopedDisableLog::ScopedDisableLog() {
std::unique_lock<std::mutex> guard(sdl_mutex);
if (sdl_cnt == 0) {
sdl_verbosity = set_verbosity_level(std::numeric_limits<int>::min());
}
sdl_cnt++;
}
ScopedDisableLog::~ScopedDisableLog() {
std::unique_lock<std::mutex> guard(sdl_mutex);
sdl_cnt--;
if (sdl_cnt == 0) {
set_verbosity_level(sdl_verbosity);
}
}
} // namespace td

View file

@ -52,8 +52,8 @@
#define VERBOSITY_NAME(x) verbosity_##x
#define GET_VERBOSITY_LEVEL() (::td::log_options.level)
#define SET_VERBOSITY_LEVEL(new_level) (::td::log_options.level = (new_level))
#define GET_VERBOSITY_LEVEL() (::td::get_verbosity_level())
#define SET_VERBOSITY_LEVEL(new_level) (::td::set_verbosity_level(new_level))
#ifndef STRIP_LOG
#define STRIP_LOG VERBOSITY_NAME(DEBUG)
@ -64,7 +64,7 @@
#define LOGGER(interface, options, level, comment) ::td::Logger(interface, options, level, __FILE__, __LINE__, comment)
#define LOG_IMPL_FULL(interface, options, strip_level, runtime_level, condition, comment) \
LOG_IS_STRIPPED(strip_level) || runtime_level > options.level || !(condition) \
LOG_IS_STRIPPED(strip_level) || runtime_level > options.get_level() || !(condition) \
? (void)0 \
: ::td::detail::Voidify() & LOGGER(interface, options, runtime_level, comment)
@ -133,11 +133,18 @@ extern int VERBOSITY_NAME(files);
extern int VERBOSITY_NAME(sqlite);
struct LogOptions {
int level{VERBOSITY_NAME(DEBUG) + 1};
std::atomic<int> level{VERBOSITY_NAME(DEBUG) + 1};
bool fix_newlines{true};
bool add_info{true};
static constexpr LogOptions plain() {
int get_level() const {
return level.load(std::memory_order_relaxed);
}
int set_level(int new_level) {
return level.exchange(new_level);
}
static LogOptions plain() {
return LogOptions{0, false, false};
}
@ -145,9 +152,31 @@ struct LogOptions {
constexpr LogOptions(int level, bool fix_newlines, bool add_info)
: level(level), fix_newlines(fix_newlines), add_info(add_info) {
}
LogOptions(const LogOptions &other) : LogOptions(other.level.load(), other.fix_newlines, other.add_info) {
}
LogOptions &operator=(const LogOptions &other) {
level = other.level.load();
fix_newlines = other.fix_newlines;
add_info = other.add_info;
return *this;
}
};
extern LogOptions log_options;
inline int set_verbosity_level(int level) {
return log_options.set_level(level);
}
inline int get_verbosity_level() {
return log_options.get_level();
}
class ScopedDisableLog {
public:
ScopedDisableLog();
~ScopedDisableLog();
};
class LogInterface {
public: