OpenSDN source code
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
bgp_log.cc
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2013 Juniper Networks, Inc. All rights reserved.
3  */
4 
5 #include "bgp/bgp_log.h"
6 
7 #include <string>
8 
10 
12  1000));
15 
16 namespace bgp_log_test {
17 
19 
20 static void init_common() {
21  unit_test_ = true;
22  bool log_disable = getenv("LOG_DISABLE") != NULL;
23 
24  // By default, we log all messages from all categories.
26 
27  // Have ability to filter messages via environment variables.
28  const char *category = getenv("BGP_UT_LOG_CATEGORY");
29  if (category) Sandesh::SetLoggingCategory(category);
30 
31  const char *level = getenv("BGP_UT_LOG_LEVEL");
32  if (level) Sandesh::SetLoggingLevel(level);
33 
34  SetLoggingDisabled(log_disable);
35 }
36 
37 void init() {
38  LoggingInit();
39  init_common();
40 }
41 
42 void init(std::string log_file, unsigned long log_file_size,
43  unsigned long log_file_index, bool enable_syslog,
44  std::string syslog_facility, std::string ident,
45  std::string log_level) {
46  LoggingInit(log_file, log_file_size, log_file_index,
47  enable_syslog, syslog_facility, ident,
49  Sandesh::StringToLevel(log_level)));
50  init_common();
51 }
52 
53 bool unit_test() {
54  return unit_test_;
55 }
56 
57 void LogServerName(const BgpServer *server) {
58  if (!unit_test_ || !server) return;
59 
60  if (Sandesh::LoggingLevel() >= SandeshLevel::SYS_DEBUG) {
61  LOG(DEBUG, "BgpServer: " << server->ToString());
62  }
63 }
64 
65 void LogServerName(const IPeer *ipeer, const BgpTable *table) {
66  if (!unit_test_) return;
67 
68  BgpServer *server = ipeer ? const_cast<IPeer *>(ipeer)->server() : NULL;
69  if (!server && table && table->routing_instance()) {
70  server = const_cast<RoutingInstance *>(
71  table->routing_instance())->server();
72  }
73 
74  LogServerName(server);
75 }
76 
77 } // namespace bgp_log_test
log4cplus::LogLevel SandeshLevelTolog4Level(SandeshLevel::type slevel)
Definition: sandesh.cc:395
void init()
Definition: bgp_log.cc:37
bool unit_test_
Definition: bgp_log.cc:18
SandeshTraceBufferPtr BgpTraceBuf
static SandeshLevel::type StringToLevel(std::string level)
Definition: sandesh.cc:861
#define BGP_PEER_OBJECT_TRACE_BUF
Definition: bgp_log.h:37
static void SetLoggingParams(bool enable_local_log, std::string category, std::string level, bool enable_trace_print=false, bool enable_flow_log=false, bool enable_session_syslog=false)
Definition: sandesh.cc:369
RoutingInstance * routing_instance()
Definition: bgp_table.h:148
static SandeshLevel::type LoggingLevel()
Definition: p/sandesh.h:221
void LogServerName(const BgpServer *server)
Definition: bgp_log.cc:57
boost::shared_ptr< TraceBuffer< SandeshTrace > > SandeshTraceBufferPtr
Definition: sandesh_trace.h:18
Definition: ipeer.h:186
static void SetLoggingCategory(std::string category)
Definition: sandesh.cc:438
static void SetLoggingLevel(std::string level)
Definition: sandesh.cc:390
bool unit_test()
Definition: bgp_log.cc:53
void LoggingInit()
Definition: logging.cc:51
SandeshTraceBufferPtr BgpPeerObjectTraceBuf
static void init_common()
Definition: bgp_log.cc:20
#define BGP_TRACE_BUF
Definition: bgp_log.h:36
#define LOG(_Level, _Msg)
Definition: logging.h:33
void SetLoggingDisabled(bool flag)
Definition: logging.cc:28
virtual std::string ToString() const
Definition: bgp_server.cc:556
static SandeshLevel::type LoggingUtLevel()
Definition: p/sandesh.h:222
SandeshTraceBufferPtr SandeshTraceBufferCreate(const std::string &buf_name, size_t buf_size, bool trace_enable=true)
Definition: sandesh_trace.h:46