DebugMessages.h
Go to the documentation of this file.
1 /*
2  * Copyright (C) 1996-2021 The Squid Software Foundation and contributors
3  *
4  * Squid software is distributed under GPLv2+ license and includes
5  * contributions from numerous individuals and organizations.
6  * Please see the COPYING and CONTRIBUTORS files for details.
7  */
8 
9 /* DEBUG: section 00 Debug Routines */
10 
11 #ifndef SQUID_DEBUG_MESSAGES_H
12 #define SQUID_DEBUG_MESSAGES_H
13 
14 #include "Debug.h"
15 #include "SquidConfig.h"
16 
17 #include <array>
18 #include <limits>
19 
20 // XXX: Replace Debug class with namespace and use that namespace here.
21 
23 typedef size_t DebugMessageId;
24 
27 {
28 public:
30  bool configured() const { return id > 0; }
31 
33  bool levelled() const { return level >= 0; }
34 
36  bool limited() const { return limit < std::numeric_limits<decltype(limit)>::max(); }
37 
39  int currentLevel(const int defaultLevel) const {
40  if (configured()) {
41  if (count_++ < limit)
42  return level;
43  return (level <= DBG_IMPORTANT) ? 3 : 8;
44  }
45  return defaultLevel;
46  }
47 
50 
51  /* all these configurable members are ignored unless configured() */
52 
54  int level = -1;
55 
58 
59 private:
61  mutable uint64_t count_ = 0;
62 };
63 
66 
69 {
70 public:
72  typedef std::array<DebugMessage, DebugMessageIdUpperBound> Storage;
74 };
75 
76 // Using a template allows us to check message ID range at compile time.
78 template <DebugMessageId id>
79 inline int
80 DebugMessageLevel(const int defaultLevel)
81 {
82  static_assert(id > 0, "debugs() message ID must be positive");
83  static_assert(id < DebugMessageIdUpperBound, "debugs() message ID must be smaller than DebugMessageIdUpperBound");
84  if (const auto configured = Config.debugMessages)
85  return (configured->messages)[id].currentLevel(defaultLevel);
86  return defaultLevel;
87 }
88 
89 /* convenience macros for calling DebugMessageLevel */
90 #define Critical(id) DebugMessageLevel<id>(DBG_CRITICAL)
91 #define Important(id) DebugMessageLevel<id>(DBG_IMPORTANT)
92 #define Dbg(id, defaultLevel) DebugMessageLevel<id>(defaultLevel)
93 
94 #endif /* SQUID_DEBUG_MESSAGES_H */
95 
int currentLevel(const int defaultLevel) const
Definition: DebugMessages.h:39
size_t DebugMessageId
an identifier for messages supporting configuration via cache_log_message
Definition: DebugMessages.h:23
#define DBG_IMPORTANT
Definition: Debug.h:41
A const & max(A const &lhs, A const &rhs)
int level
debugging level (i.e., the second debugs() parameter) or -1
Definition: DebugMessages.h:54
int DebugMessageLevel(const int defaultLevel)
Definition: DebugMessages.h:80
Storage messages
Definition: DebugMessages.h:73
manages configurable aspects of a debugs() message
Definition: DebugMessages.h:27
uint64_t count_
the total number of attempts to log this message if it was configured()
Definition: DebugMessages.h:61
uint64_t limit
logging attempts beyond this limit are logged at the DBG_DATA level
Definition: DebugMessages.h:57
a collection of DebugMessage objects (with fast access by message IDs)
Definition: DebugMessages.h:69
constexpr DebugMessageId DebugMessageIdUpperBound
The maximum used DebugMessage::id plus 1. Increase as you add new IDs.
Definition: DebugMessages.h:65
DebugMessages * debugMessages
cache_log_message
Definition: SquidConfig.h:565
std::array< DebugMessage, DebugMessageIdUpperBound > Storage
configurable messages indexed by their IDs
Definition: DebugMessages.h:72
bool levelled() const
whether the default logging level of this message has been altered
Definition: DebugMessages.h:33
class SquidConfig Config
Definition: SquidConfig.cc:12
bool configured() const
whether the logging of this message has been customized
Definition: DebugMessages.h:30
bool limited() const
whether the number of logging attempts have been limited
Definition: DebugMessages.h:36

 

Introduction

Documentation

Support

Miscellaneous

Web Site Translations

Mirrors