forked from datastax/cpp-driver
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathlogger.cpp
78 lines (60 loc) · 2.15 KB
/
logger.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
/*
Copyright (c) 2014-2016 DataStax
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/
#include "logger.hpp"
extern "C" {
void cass_log_cleanup() {
// Deprecated
}
void cass_log_set_level(CassLogLevel log_level) {
cass::Logger::set_log_level(log_level);
}
void cass_log_set_callback(CassLogCallback callback,
void* data) {
cass::Logger::set_callback(callback, data);
}
void cass_log_set_queue_size(size_t queue_size) {
// Deprecated
}
} // extern "C"
namespace cass {
void stderr_log_callback(const CassLogMessage* message, void* data) {
fprintf(stderr, "%u.%03u [%s] (%s:%d:%s): %s\n",
static_cast<unsigned int>(message->time_ms / 1000),
static_cast<unsigned int>(message->time_ms % 1000),
cass_log_level_string(message->severity),
message->file, message->line, message->function,
message->message);
}
void noop_log_callback(const CassLogMessage* message, void* data) { }
CassLogLevel Logger::log_level_ = CASS_LOG_WARN;
CassLogCallback Logger::cb_ = stderr_log_callback;
void* Logger::data_ = NULL;
void Logger::log(CassLogLevel severity,
const char* file, int line, const char* function,
const char* format, va_list args) {
CassLogMessage message = {
get_time_since_epoch_ms(), severity,
file, line, function,
""
};
vsnprintf(message.message, sizeof(message.message), format, args);
Logger::cb_(&message, Logger::data_);
}
void Logger::set_log_level(CassLogLevel log_level) {
log_level_ = log_level;
}
void Logger::set_callback(CassLogCallback cb, void* data) {
cb_ = cb == NULL ? noop_log_callback : cb;
data_ = data;
}
} // namespace cass