Messages.h
Go to the documentation of this file.
1/*
2 * Copyright (C) 1996-2022 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/Stream.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
23typedef size_t DebugMessageId;
24
27{
28public:
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
59private:
61 mutable uint64_t count_ = 0;
62};
63
66
69{
70public:
72 typedef std::array<DebugMessage, DebugMessageIdUpperBound> Storage;
74};
75
76// Using a template allows us to check message ID range at compile time.
78template <DebugMessageId id>
79inline int
80DebugMessageLevel(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
class SquidConfig Config
Definition: SquidConfig.cc:12
manages configurable aspects of a debugs() message
Definition: Messages.h:27
bool configured() const
whether the logging of this message has been customized
Definition: Messages.h:30
int currentLevel(const int defaultLevel) const
Definition: Messages.h:39
uint64_t limit
logging attempts beyond this limit are logged at the DBG_DATA level
Definition: Messages.h:57
bool limited() const
whether the number of logging attempts have been limited
Definition: Messages.h:36
uint64_t count_
the total number of attempts to log this message if it was configured()
Definition: Messages.h:61
bool levelled() const
whether the default logging level of this message has been altered
Definition: Messages.h:33
int level
debugging level (i.e., the second debugs() parameter) or -1
Definition: Messages.h:54
a collection of DebugMessage objects (with fast access by message IDs)
Definition: Messages.h:69
Storage messages
Definition: Messages.h:73
std::array< DebugMessage, DebugMessageIdUpperBound > Storage
configurable messages indexed by their IDs
Definition: Messages.h:72
DebugMessages * debugMessages
cache_log_message
Definition: SquidConfig.h:556
A const & max(A const &lhs, A const &rhs)
constexpr DebugMessageId DebugMessageIdUpperBound
The maximum used DebugMessage::id plus 1. Increase as you add new IDs.
Definition: Messages.h:65
int DebugMessageLevel(const int defaultLevel)
Definition: Messages.h:80
size_t DebugMessageId
an identifier for messages supporting configuration via cache_log_message
Definition: Messages.h:23
#define DBG_IMPORTANT
Definition: Stream.h:41

 

Introduction

Documentation

Support

Miscellaneous

Web Site Translations

Mirrors