forked from cpp-netlib/cpp-netlib
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathlogging.cpp
More file actions
50 lines (39 loc) · 1.27 KB
/
logging.cpp
File metadata and controls
50 lines (39 loc) · 1.27 KB
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
// Copyright 2011 A. Joel Lamotte <mjklaim@gmail.com>.
// Distributed under the Boost Software License, Version 1.0.
// (See accompanying file LICENSE_1_0.txt or copy at
// http://www.boost.org/LICENSE_1_0.txt)
#ifdef NETWORK_NO_LIB
#undef NETWORK_NO_LIB
#endif
#include <iostream>
#include <memory>
#include <network/logging/logging.hpp>
namespace network {
namespace logging {
const char* log_record::UNKNOWN_FILE_NAME = "unknown";
namespace handler {
namespace {
void std_log_handler(const log_record& log) {
std::cerr << "[network " << log.filename() << ":" << log.line() << "] "
<< log.message() << std::endl;
}
}
log_record_handler get_std_log_handler() { return &std_log_handler; }
log_record_handler get_default_log_handler() { return &std_log_handler; }
}
namespace {
// the log handler have to manage itself the thread safety on call
static auto current_log_record_handler = std::make_shared<log_record_handler>(
&handler::std_log_handler);
}
void set_log_record_handler(log_record_handler handler) {
current_log_record_handler = std::make_shared<log_record_handler>(handler);
}
void log(const log_record& log) {
auto log_handler = current_log_record_handler;
if (log_handler) {
(*log_handler)(log);
}
}
}
}