2018-12-31 20:04:05 +01:00
|
|
|
//
|
2018-01-02 14:42:31 +01:00
|
|
|
// Copyright Aliaksei Levin (levlam@telegram.org), Arseny Smirnov (arseny30@gmail.com) 2014-2018
|
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
|
|
|
|
|
|
|
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:
|
2018-10-24 17:42:40 +02:00
|
|
|
Status init(string path, int64 rotate_threshold = DEFAULT_ROTATE_THRESHOLD);
|
|
|
|
|
|
|
|
Slice get_path() const;
|
2018-12-31 20:04:05 +01:00
|
|
|
|
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;
|
|
|
|
|
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
|
|
|
|
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;
|
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
|