2018-12-31 20:04:05 +01:00
|
|
|
//
|
2020-01-01 02:23:48 +01:00
|
|
|
// Copyright Aliaksei Levin (levlam@telegram.org), Arseny Smirnov (arseny30@gmail.com) 2014-2020
|
2018-12-31 20:04:05 +01:00
|
|
|
//
|
|
|
|
// Distributed under the Boost Software License, Version 1.0. (See accompanying
|
|
|
|
// file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
|
|
|
|
//
|
|
|
|
#pragma once
|
|
|
|
|
|
|
|
#include "td/utils/common.h"
|
|
|
|
#include "td/utils/logging.h"
|
|
|
|
#include "td/utils/port/FileFd.h"
|
|
|
|
#include "td/utils/Slice.h"
|
2018-10-24 17:42:40 +02:00
|
|
|
#include "td/utils/Status.h"
|
2018-12-31 20:04:05 +01:00
|
|
|
|
2020-06-26 01:24:13 +02:00
|
|
|
#include <atomic>
|
|
|
|
|
2018-12-31 20:04:05 +01:00
|
|
|
namespace td {
|
|
|
|
|
|
|
|
class FileLog : public LogInterface {
|
2018-01-28 15:33:14 +01:00
|
|
|
static constexpr int64 DEFAULT_ROTATE_THRESHOLD = 10 * (1 << 20);
|
2018-12-31 20:04:05 +01:00
|
|
|
|
|
|
|
public:
|
2020-06-26 01:24:13 +02:00
|
|
|
static Result<unique_ptr<LogInterface>> create(string path, int64 rotate_threshold = DEFAULT_ROTATE_THRESHOLD,
|
|
|
|
bool redirect_stderr = true);
|
2019-08-12 13:45:57 +02:00
|
|
|
Status init(string path, int64 rotate_threshold = DEFAULT_ROTATE_THRESHOLD, bool redirect_stderr = true);
|
2018-10-24 17:42:40 +02:00
|
|
|
|
|
|
|
Slice get_path() const;
|
2018-12-31 20:04:05 +01:00
|
|
|
|
2019-01-17 23:17:20 +01:00
|
|
|
vector<string> get_file_paths() override;
|
|
|
|
|
2018-01-28 15:33:14 +01:00
|
|
|
void set_rotate_threshold(int64 rotate_threshold);
|
2018-12-31 20:04:05 +01:00
|
|
|
|
2018-10-24 17:42:40 +02:00
|
|
|
int64 get_rotate_threshold() const;
|
|
|
|
|
2020-09-27 13:37:35 +02:00
|
|
|
bool get_redirect_stderr() const;
|
|
|
|
|
2018-01-28 15:33:14 +01:00
|
|
|
void append(CSlice cslice, int log_level) override;
|
2018-12-31 20:04:05 +01:00
|
|
|
|
2018-01-28 15:33:14 +01:00
|
|
|
void rotate() override;
|
2018-01-09 10:40:56 +01:00
|
|
|
|
2020-06-24 13:47:36 +02:00
|
|
|
void lazy_rotate();
|
|
|
|
|
2018-12-31 20:04:05 +01:00
|
|
|
private:
|
|
|
|
FileFd fd_;
|
|
|
|
string path_;
|
2018-10-26 16:11:20 +02:00
|
|
|
int64 size_ = 0;
|
|
|
|
int64 rotate_threshold_ = 0;
|
2019-08-13 22:52:54 +02:00
|
|
|
bool redirect_stderr_ = false;
|
2020-06-26 01:24:13 +02:00
|
|
|
std::atomic<bool> want_rotate_{false};
|
2018-12-31 20:04:05 +01:00
|
|
|
|
2018-01-28 15:33:14 +01:00
|
|
|
void do_rotate();
|
2018-12-31 20:04:05 +01:00
|
|
|
};
|
2018-01-28 15:33:14 +01:00
|
|
|
|
2018-12-31 20:04:05 +01:00
|
|
|
} // namespace td
|