forked from hyphanet/lib-CppFCPLib
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathLog.cpp
46 lines (36 loc) · 774 Bytes
/
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
#include "Log.h"
#include "Exceptions.h"
#include "zthread/Guard.h"
using namespace FCPLib;
Logger::Logger(std::ostream &out_, verbosityLevel logLevel_)
: out(out_),
logLevel(logLevel_)
{
}
void
Logger::log(verbosityLevel logLevel_, const char *message)
{
ZThread::Guard<ZThread::Mutex> g(lock);
if (logLevel_ <= logLevel) {
out << message;
if (message[strlen(message)] != '\n')
out << '\n';
}
out.flush();
}
void
Logger::log(verbosityLevel logLevel_, std::string message)
{
log(logLevel_, message.c_str());
}
Logger&
FCPLib::log(std::ostream &out_, verbosityLevel logLevel_)
{
static bool firstTime = true;
static Logger* l;
if (firstTime) {
firstTime = false;
l = new Logger(out_, logLevel_);
}
return *l;
}