-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathtestlog.cpp
118 lines (92 loc) · 2.29 KB
/
testlog.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
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
#include "es_main.h"
#include "Efc.hh"
#include "ELog.hh"
static sp<ELogger> rootLogger = ELoggerManager::getRootLogger();
static sp<ELogger> logger = ELoggerManager::getLogger("XXX.YYY.ZZZ");
static void test_logger() {
ELoggerManager::init("log4e.properties");
// ELoggerManager::getRootLogger()->setLevel(ELogger::LEVEL_OFF);
try {
logger->info("xxxxxxxxxxxxxx");
logger->warn_("xxxxxxxxxxxxxx%s", "z");
throw EException(__FILE__, __LINE__, "exception:");
} catch (EException& e) {
// ELOG_E(logger, "xxxxxxxxxxxxxx[%s]", e.getMessage());
// ELOG__E(logger, "xxxxxxxxxxxxxx", e);
ELOG__E(logger, "message", e);
logger->error(e);
logger->error("message", e);
}
ELOG_E(logger, "format s=%d", 9999);
ELOG_E(rootLogger, "root log s=%d", 9999);
for (int i=0; i<5; i++) {
ENDC::push(new EString(i));
sp<ELogger> logger2 = ELoggerManager::getLogger("XXX");
ELOG_E(logger2, "!@#$%%^&*(&^%@#%%&*\" i s=%d", i);
logger2->close();
delete ENDC::pop();
}
ENDC::clear();
ELOG_E(logger, "ndc xxx");
}
class ThreadX : public EThread {
public:
virtual void run() {
long i = 0;
while (true) {
ENDC ndc("abc");
EMDC mdc("x1", "v1");
mdc.put("x2", "v2");
// ELoggerManager::getRootLogger()->setLevel(ELogger::LEVEL_OFF);
ELOG_I(logger, "i=%d", i++);
ELOG_W(logger, "i=%d", i++);
ELOG_E(logger, "i=%d", i++);
EThread::sleep(100);
}
}
};
static void test_logger_multi_threads() {
ELoggerManager::init("log4e.properties");
EArray<ThreadX*> arr;
for (int i = 0; i < 10; i++) {
ThreadX* thread = new ThreadX();
arr.add(thread);
thread->start();
}
while (true) {
ELoggerManager::flushConfig(); //!
EThread::sleep(50);
}
for (int i = 0; i < arr.size(); i++) {
ThreadX* thread = arr.getAt(i);
thread->join(100);
}
}
static void test_test(int argc, const char** argv) {
test_logger();
// test_logger_multi_threads();
//
// EThread::sleep(3000);
}
MAIN_IMPL(testlog) {
printf("main()\n");
ESystem::init(argc, argv);
printf("inited.\n");
int i = 0;
try {
boolean loop = EBoolean::parseBoolean(ESystem::getProgramArgument("loop"));
do {
test_test(argc, argv);
// } while (++i < 5);
} while (1);
}
catch (EException& e) {
e.printStackTrace();
}
catch (...) {
printf("catch all...\n");
}
printf("exit...\n");
ESystem::exit(0);
return 0;
}