/
bgp_log.cc
83 lines (63 loc) · 2.13 KB
/
bgp_log.cc
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
79
80
81
82
83
/*
* Copyright (c) 2013 Juniper Networks, Inc. All rights reserved.
*/
#include "bgp/bgp_log.h"
#include <string>
#include "bgp/bgp_server.h"
#include "bgp/routing-instance/routing_instance.h"
SandeshTraceBufferPtr BgpTraceBuf(SandeshTraceBufferCreate(BGP_TRACE_BUF,
1000));
SandeshTraceBufferPtr BgpPeerObjectTraceBuf(SandeshTraceBufferCreate(
BGP_PEER_OBJECT_TRACE_BUF, 1000));
namespace bgp_log_test {
bool unit_test_;
static void init_common() {
unit_test_ = true;
//
// By default, we log all messages from all categories.
//
Sandesh::SetLoggingParams(true, "", Sandesh::LoggingUtLevel());
//
// Have ability to filter messages via environment variables.
//
const char *category = getenv("BGP_UT_LOG_CATEGORY");
if (category) Sandesh::SetLoggingCategory(category);
const char *level = getenv("BGP_UT_LOG_LEVEL");
if (level) Sandesh::SetLoggingLevel(level);
if (getenv("LOG_DISABLE") != NULL) {
SetLoggingDisabled(true);
}
}
void init() {
LoggingInit();
init_common();
}
void init(std::string log_file, unsigned long log_file_size,
unsigned long log_file_index, bool enable_syslog,
std::string syslog_facility, std::string ident,
std::string log_level) {
LoggingInit(log_file, log_file_size, log_file_index,
enable_syslog, syslog_facility, ident,
SandeshLevelTolog4Level(
Sandesh::StringToLevel(log_level)));
init_common();
}
bool unit_test() {
return unit_test_;
}
void LogServerName(const BgpServer *server) {
if (!unit_test_ || !server) return;
if (Sandesh::LoggingLevel() >= SandeshLevel::SYS_DEBUG) {
LOG(DEBUG, "BgpServer: " << server->ToString());
}
}
void LogServerName(const IPeer *ipeer, const BgpTable *table) {
if (!unit_test_) return;
BgpServer *server = ipeer ? const_cast<IPeer *>(ipeer)->server() : NULL;
if (!server && table && table->routing_instance()) {
server = const_cast<RoutingInstance *>(
table->routing_instance())->server();
}
LogServerName(server);
}
} // namespace bgp_log_test