forest-net
an overlay networks for large-scale virtual worlds
Main Page
Namespaces
Classes
Files
File List
File Members
All
Classes
Namespaces
Files
Functions
Variables
Typedefs
Enumerations
Enumerator
Logger.cpp
Go to the documentation of this file.
1
9
#include "
Logger.h
"
10
11
namespace
forest {
12
13
14
Logger::Logger() {
15
level
= 1;
16
if
(pthread_mutex_init(&
myLock
,NULL) != 0)
17
fatal(
"Logger::Logger: could not initialize lock\n"
);
18
tag
[0] =
"informational"
;
19
tag
[1] =
"warning"
;
20
tag
[2] =
"exceptional event"
;
21
tag
[3] =
"program error"
;
22
}
23
24
void
Logger::setLevel(
int
lev) {
25
pthread_mutex_lock(&
myLock
);
26
level
= min(3,max(0,lev));
27
pthread_mutex_unlock(&
myLock
);
28
}
29
36
void
Logger::logit
(
const
string
& s,
int
severity) {
37
pthread_mutex_lock(&
myLock
);
38
cerr <<
"Logger: "
<< s <<
" ("
<<
tag
[severity] <<
")\n"
;
39
if
(severity > 3) fatal(
"terminating"
);
40
pthread_mutex_unlock(&
myLock
);
41
}
42
43
void
Logger::logit
(
const
string
& s,
int
severity,
Packet
& p) {
44
pthread_mutex_lock(&
myLock
);
45
cerr <<
"Logger: "
<< s <<
" ("
<<
tag
[severity] <<
")\n"
;
46
string
s1;
47
cerr << p.
toString
(s1) << endl;
48
if
(severity > 3) fatal(
"terminating"
);
49
pthread_mutex_unlock(&
myLock
);
50
}
51
52
void
Logger::logit
(
const
string
& s,
int
severity, CtlPkt& cp) {
53
pthread_mutex_lock(&
myLock
);
54
cerr <<
"Logger: "
<< s <<
" ("
<< tag[severity] <<
")\n"
;
55
string
s1;
56
cerr << cp.toString(s1) << endl;
57
if
(severity > 3) fatal(
"terminating"
);
58
pthread_mutex_lock(&
myLock
);
59
}
60
61
}
// ends namespace
62
forest-net
cpp
common
Logger.cpp
Generated on Mon Aug 4 2014 11:13:34 for forest-net by
1.8.4