Skip to content

Commit da3f190

Browse files
committed
feat: track server exit times and write to file
1 parent 61a426a commit da3f190

1 file changed

Lines changed: 17 additions & 12 deletions

File tree

demo/web-server/main.cpp

Lines changed: 17 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
#include <ctime>
1313
#include <iostream>
1414
#include <memory>
15+
#include <string>
1516
#include <unistd.h>
1617
#include <vector>
1718
using namespace std;
@@ -26,17 +27,21 @@ void RunWithConfig(Config &config) {
2627
}
2728

2829
if (config.is_guard) {
29-
ProcessCtrl::Guard([](int exit_code, bool is_normal_exit) -> bool {
30-
if (!is_normal_exit) {
31-
cout << "child exit code:" << exit_code
32-
<< " not normal exit:" << is_normal_exit << endl;
33-
return true;
34-
} else {
35-
cout << "child exit code:" << exit_code
36-
<< " normal exit:" << is_normal_exit << endl;
37-
return false;
38-
}
39-
});
30+
int exit_time = 0;
31+
ProcessCtrl::Guard(
32+
[&exit_time](int exit_code, bool is_normal_exit) -> bool {
33+
exit_time++;
34+
File::Write("server.exit", to_string(exit_time));
35+
if (!is_normal_exit) {
36+
cout << "child exit code:" << exit_code
37+
<< " not normal exit:" << is_normal_exit << endl;
38+
return true;
39+
} else {
40+
cout << "child exit code:" << exit_code
41+
<< " normal exit:" << is_normal_exit << endl;
42+
return false;
43+
}
44+
});
4045
}
4146

4247
// get now time str
@@ -112,7 +117,7 @@ void RunWithConfig(Config &config) {
112117
auto file_logger = make_shared<FileLogger>();
113118

114119
std_logger->set_level(Logger::Level(config.log_level));
115-
logger->set_level(Logger::Level(config.log_level));
120+
file_logger->set_level(Logger::Level(config.log_level));
116121

117122
file_logger->Init(config.log_path);
118123
logger->Init({std_logger, file_logger});

0 commit comments

Comments
 (0)