LCOV - code coverage report
Current view: top level - bgp - bgp_log.cc (source / functions) Hit Total Coverage
Test: OpenSDN C/C++ coverage (all TARGET_SET jobs) Lines: 26 30 86.7 %
Date: 2026-06-04 02:06:09 Functions: 5 6 83.3 %
Legend: Lines: hit not hit

          Line data    Source code
       1             : /*
       2             :  * Copyright (c) 2013 Juniper Networks, Inc. All rights reserved.
       3             :  */
       4             : 
       5             : #include "bgp/bgp_log.h"
       6             : 
       7             : #include <string>
       8             : 
       9             : #include "bgp/routing-instance/routing_instance.h"
      10             : 
      11             : SandeshTraceBufferPtr BgpTraceBuf(SandeshTraceBufferCreate(BGP_TRACE_BUF,
      12             :         1000));
      13             : SandeshTraceBufferPtr BgpPeerObjectTraceBuf(SandeshTraceBufferCreate(
      14             :         BGP_PEER_OBJECT_TRACE_BUF, 1000));
      15             : 
      16             : namespace bgp_log_test {
      17             : 
      18             : bool unit_test_;
      19             : 
      20         266 : static void init_common() {
      21         266 :     unit_test_ = true;
      22         266 :     bool log_disable = getenv("LOG_DISABLE") != NULL;
      23             : 
      24             :     // By default, we log all messages from all categories.
      25         266 :     Sandesh::SetLoggingParams(!log_disable, "", Sandesh::LoggingUtLevel());
      26             : 
      27             :     // Have ability to filter messages via environment variables.
      28         266 :     const char *category = getenv("BGP_UT_LOG_CATEGORY");
      29         266 :     if (category) Sandesh::SetLoggingCategory(category);
      30             : 
      31         266 :     const char *level = getenv("BGP_UT_LOG_LEVEL");
      32         266 :     if (level) Sandesh::SetLoggingLevel(level);
      33             : 
      34         266 :     SetLoggingDisabled(log_disable);
      35         266 : }
      36             : 
      37         266 : void init() {
      38         266 :     LoggingInit();
      39         266 :     init_common();
      40         266 : }
      41             : 
      42           0 : 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           0 :     LoggingInit(log_file, log_file_size, log_file_index,
      47             :                 enable_syslog, syslog_facility, ident,
      48             :                 SandeshLevelTolog4Level(
      49             :                     Sandesh::StringToLevel(log_level)));
      50           0 :     init_common();
      51           0 : }
      52             : 
      53     2373864 : bool unit_test() {
      54     2373864 :     return unit_test_;
      55             : }
      56             : 
      57     7053491 : void LogServerName(const BgpServer *server) {
      58     7053491 :     if (!unit_test_ || !server) return;
      59             : 
      60     6072211 :     if (Sandesh::LoggingLevel() >= SandeshLevel::SYS_DEBUG) {
      61     6072013 :         LOG(DEBUG, "BgpServer: " << server->ToString());
      62             :     }
      63             : }
      64             : 
      65     2407602 : void LogServerName(const IPeer *ipeer, const BgpTable *table) {
      66     2407602 :     if (!unit_test_) return;
      67             : 
      68     2407602 :     BgpServer *server = ipeer ? const_cast<IPeer *>(ipeer)->server() : NULL;
      69     2407581 :     if (!server && table && table->routing_instance()) {
      70             :         server = const_cast<RoutingInstance *>(
      71      266144 :                      table->routing_instance())->server();
      72             :     }
      73             : 
      74     2407580 :     LogServerName(server);
      75             : }
      76             : 
      77             : }  // namespace bgp_log_test

Generated by: LCOV version 1.14