-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.cpp
71 lines (66 loc) · 1.86 KB
/
main.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
68
69
70
71
#include "Http/HttpData.h"
#include "Log/AsynLog.h"
#include "Log/LogConfig.h"
#include "Log/Logger.h"
#include "Reactor/EventLoop.h"
#include "Server/Server.h"
#include <cstdlib>
#include <memory>
#include <string>
#include <getopt.h>
int main(int argc, char *argv[]) {
int threadNum = 8;
int port = 1316;
std::string logName = "EasyServerLog";
// parse args
int opt;
const char *str = "t:l:p:";
while ((opt = getopt(argc, argv, str)) != -1) {
switch (opt) {
case 't': {
threadNum = atoi(optarg);
break;
}
case 'l': {
logName = optarg;
if (logName.size() < 2 || optarg[0] != '/') {
printf("logPath should start with \"/\"\n");
abort();
}
if (logName.empty()) {
printf("Empty LogName");
abort();
}
break;
}
case 'p': {
port = atoi(optarg);
if (port > 65535 || port < 1024) {
LOG_ERROR("Port:%d error!", port);
abort();
}
break;
}
default:
break;
}
}
std::unique_ptr<AsynLog> asynLog;
LogConfig config;
config.logLevel = LogConfig::TRACE;
config.logFileOptions.baseName = logName;
config.logFileOptions.fileWriterType = FileWriterType::FileWriter_NORMAL;
config.logFileOptions.rollSize = static_cast<size_t>(500 * 1024 * 1024);
Logger::setConfig(config);
auto asynOutput = [&](const char *msg, size_t len, size_t keyLen = 0) {
asynLog->append(msg, len);
};
Logger::setOutputFunc(asynOutput);
asynLog = std::make_unique<AsynLog>();
asynLog->start();
EventLoop mainLoop;
Server EasyServer(&mainLoop, threadNum, port);
EasyServer.start();
mainLoop.loop();
return 0;
}