-
Notifications
You must be signed in to change notification settings - Fork 21
/
log.cpp
67 lines (57 loc) · 1.42 KB
/
log.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
#include <spdlog/spdlog.h>
#include <vector>
#include <libtorrent/libtorrent.hpp>
#include "log.hpp"
namespace ezio
{
log::log(ezio &daemon) :
m_daemon(daemon)
{
m_speed = std::thread(&log::report_speed, this);
m_alert = std::thread(&log::report_alert, this);
}
log::~log()
{
join();
}
void log::join()
{
m_speed.join();
m_alert.join();
}
void log::report_speed()
{
SPDLOG_INFO("start speed report thread");
while (!m_daemon.get_shutdown()) {
std::this_thread::sleep_for(std::chrono::seconds(5));
std::vector<std::string> hashes;
auto result = m_daemon.get_torrent_status(hashes);
for (const auto &iter : result) {
const auto &hash = iter.first;
const auto &t_stat = iter.second;
SPDLOG_INFO("[{}][{}%][D: {:.2f}MB/s][U: {:.2f}MB/s][{}{}][A: {}][F: {}][S: {}]",
t_stat.save_path,
int(t_stat.progress * 100),
(double)t_stat.download_rate / 1024 / 1024,
(double)t_stat.upload_rate / 1024 / 1024,
t_stat.is_paused ? "P" : " ",
t_stat.is_finished ? "F" : " ",
t_stat.active_time,
t_stat.finished_time,
t_stat.seeding_time);
}
}
}
void log::report_alert()
{
SPDLOG_INFO("start alert report thread");
while (!m_daemon.get_shutdown()) {
std::this_thread::sleep_for(std::chrono::seconds(5));
std::vector<libtorrent::alert *> alerts;
m_daemon.pop_alerts(&alerts);
for (auto a : alerts) {
SPDLOG_INFO("lt alert: {} {}", a->what(), a->message());
}
}
}
} // namespace ezio