2
This file is part of TON Blockchain Library.
4
TON Blockchain Library is free software: you can redistribute it and/or modify
5
it under the terms of the GNU Lesser General Public License as published by
6
the Free Software Foundation, either version 2 of the License, or
7
(at your option) any later version.
9
TON Blockchain Library is distributed in the hope that it will be useful,
10
but WITHOUT ANY WARRANTY; without even the implied warranty of
11
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12
GNU Lesser General Public License for more details.
14
You should have received a copy of the GNU Lesser General Public License
15
along with TON Blockchain Library. If not, see <http://www.gnu.org/licenses/>.
17
Copyright 2017-2020 Telegram Systems LLP
22
#include "td/utils/port/FileFd.h"
23
#include "td/utils/filesystem.h"
24
#include "td/utils/port/path.h"
25
#include "td/utils/Time.h"
34
std::mutex init_mutex_;
35
std::string files_path_;
37
void ErrorLog::create(std::string db_root) {
43
auto path = db_root + "/error";
44
td::mkdir(path).ensure();
45
files_path_ = path + "/files";
46
td::mkdir(files_path_).ensure();
47
auto R = td::FileFd::open(path + "/log.txt",
48
td::FileFd::Flags::Write | td::FileFd::Flags::Append | td::FileFd::Flags::Create);
54
void ErrorLog::log(std::string error) {
55
error = PSTRING() << "[" << td::Clocks::system() << "] " << error << "\n";
57
auto s = td::Slice{error};
58
while (s.size() > 0) {
61
s.remove_prefix(R.move_as_ok());
65
void ErrorLog::log_file(td::BufferSlice data) {
66
auto filename = sha256_bits256(data.as_slice());
67
auto path = files_path_ + "/" + filename.to_hex();
69
td::write_file(path, data.as_slice()).ensure();
72
} // namespace errorlog