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
|
/*
Copyright (c) 2015, Facebook, Inc.
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; version 2 of the License.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */
#pragma once
#include <log.h>
#include <sstream>
#include <string>
namespace myrocks {
class Rdb_logger : public rocksdb::Logger
{
public:
void Logv(const rocksdb::InfoLogLevel log_level,
const char* format,
va_list ap) override
{
DBUG_ASSERT(format != nullptr);
enum loglevel mysql_log_level;
if (m_logger) {
m_logger->Logv(log_level, format, ap);
}
if (log_level < GetInfoLogLevel()) {
return;
}
if (log_level >= rocksdb::InfoLogLevel::ERROR_LEVEL) {
mysql_log_level= ERROR_LEVEL;
} else if (log_level >= rocksdb::InfoLogLevel::WARN_LEVEL) {
mysql_log_level= WARNING_LEVEL;
} else {
mysql_log_level= INFORMATION_LEVEL;
}
// log to MySQL
std::string f("LibRocksDB:");
f.append(format);
error_log_print(mysql_log_level, f.c_str(), ap);
}
void Logv(const char* format, va_list ap) override
{
DBUG_ASSERT(format != nullptr);
// If no level is specified, it is by default at information level
Logv(rocksdb::InfoLogLevel::INFO_LEVEL, format, ap);
}
void SetRocksDBLogger(std::shared_ptr<rocksdb::Logger> logger)
{
m_logger = logger;
}
private:
std::shared_ptr<rocksdb::Logger> m_logger;
};
} // namespace myrocks
|