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-11-09 02:10:49 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             :  * Copyright Contributors to the OpenSDN project
       4             :  */
       5             : 
       6             : #include "bgp/bgp_log.h"
       7             : 
       8             : #include <string>
       9             : 
      10             : #include "bgp/routing-instance/routing_instance.h"
      11             : 
      12             : SandeshTraceBufferPtr BgpTraceBuf(SandeshTraceBufferCreate(BGP_TRACE_BUF,
      13             :         1000));
      14             : SandeshTraceBufferPtr BgpPeerObjectTraceBuf(SandeshTraceBufferCreate(
      15             :         BGP_PEER_OBJECT_TRACE_BUF, 1000));
      16             : 
      17             : namespace bgp_log_test {
      18             : 
      19             : bool unit_test_;
      20             : 
      21         266 : static void init_common() {
      22         266 :     unit_test_ = true;
      23         266 :     bool log_disable = getenv("LOG_DISABLE") != NULL;
      24             : 
      25             :     // By default, we log all messages from all categories.
      26         266 :     Sandesh::SetLoggingParams(!log_disable, "", Sandesh::LoggingUtLevel());
      27             : 
      28             :     // Have ability to filter messages via environment variables.
      29         266 :     const char *category = getenv("BGP_UT_LOG_CATEGORY");
      30         266 :     if (category) Sandesh::SetLoggingCategory(category);
      31             : 
      32         266 :     const char *level = getenv("BGP_UT_LOG_LEVEL");
      33         266 :     if (level) Sandesh::SetLoggingLevel(level);
      34             : 
      35         266 :     SetLoggingDisabled(log_disable);
      36         266 : }
      37             : 
      38         266 : void init() {
      39         266 :     LoggingInit();
      40         266 :     init_common();
      41         266 : }
      42             : 
      43           0 : void init(std::string log_file, unsigned long log_file_size,
      44             :           unsigned long log_file_index, bool enable_syslog,
      45             :           std::string syslog_facility, std::string ident,
      46             :           std::string log_level) {
      47           0 :     LoggingInit(log_file, log_file_size, log_file_index,
      48             :                 enable_syslog, syslog_facility, ident,
      49             :                 SandeshLevelTolog4Level(
      50             :                     Sandesh::StringToLevel(log_level)));
      51           0 :     init_common();
      52           0 : }
      53             : 
      54     2378993 : bool unit_test() {
      55     2378993 :     return unit_test_;
      56             : }
      57             : 
      58     7066571 : void LogServerName(const BgpServer *server) {
      59     7066571 :     if (!unit_test_ || !server) return;
      60             : 
      61     6086134 :     if (Sandesh::LoggingLevel() >= SandeshLevel::SYS_DEBUG) {
      62     6085992 :         LOG(DEBUG, "BgpServer: " << server->ToString());
      63             :     }
      64             : }
      65             : 
      66     2413791 : void LogServerName(const IPeer *ipeer, const BgpTable *table) {
      67     2413791 :     if (!unit_test_) return;
      68             : 
      69     2413791 :     BgpServer *server = ipeer ? const_cast<IPeer *>(ipeer)->server() : NULL;
      70     2413775 :     if (!server && table && table->routing_instance()) {
      71             :         server = const_cast<RoutingInstance *>(
      72      266209 :                      table->routing_instance())->server();
      73             :     }
      74             : 
      75     2413765 :     LogServerName(server);
      76             : }
      77             : 
      78             : }  // namespace bgp_log_test

Generated by: LCOV version 1.14