Messages.h
Go to the documentation of this file.
1/*
2 * Copyright (C) 1996-2023 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
16#include <array>
17#include <limits>
18
19// XXX: Replace Debug class with namespace and use that namespace here.
20
22typedef size_t DebugMessageId;
23
26{
27public:
29 bool configured() const { return id > 0; }
30
32 bool levelled() const { return level >= 0; }
33
35 bool limited() const { return limit < std::numeric_limits<decltype(limit)>::max(); }
36
38 int currentLevel(const int defaultLevel) const {
39 if (configured()) {
40 if (count_++ < limit)
41 return level;
42 return (level <= DBG_IMPORTANT) ? 3 : 8;
43 }
44 return defaultLevel;
45 }
46
49
50 /* all these configurable members are ignored unless configured() */
51
53 int level = -1;
54
57
58private:
60 mutable uint64_t count_ = 0;
61};
62
65
68{
69public:
71 typedef std::array<DebugMessage, DebugMessageIdUpperBound> Storage;
73};
74
77
78// Using a template allows us to check message ID range at compile time.
80template <DebugMessageId id>
81inline int
82DebugMessageLevel(const int defaultLevel)
83{
84 static_assert(id > 0, "debugs() message ID must be positive");
85 static_assert(id < DebugMessageIdUpperBound, "debugs() message ID must be smaller than DebugMessageIdUpperBound");
86 if (const auto configured = DebugMessagesConfig)
87 return (configured->messages)[id].currentLevel(defaultLevel);
88 return defaultLevel;
89}
90
91/* convenience macros for calling DebugMessageLevel */
92#define Critical(id) DebugMessageLevel<id>(DBG_CRITICAL)
93#define Important(id) DebugMessageLevel<id>(DBG_IMPORTANT)
94#define Dbg(id, defaultLevel) DebugMessageLevel<id>(defaultLevel)
95
96#endif /* SQUID_DEBUG_MESSAGES_H */
97
manages configurable aspects of a debugs() message
Definition: Messages.h:26
bool configured() const
whether the logging of this message has been customized
Definition: Messages.h:29
int currentLevel(const int defaultLevel) const
Definition: Messages.h:38
uint64_t limit
logging attempts beyond this limit are logged at the DBG_DATA level
Definition: Messages.h:56
bool limited() const
whether the number of logging attempts have been limited
Definition: Messages.h:35
uint64_t count_
the total number of attempts to log this message if it was configured()
Definition: Messages.h:60
bool levelled() const
whether the default logging level of this message has been altered
Definition: Messages.h:32
int level
debugging level (i.e., the second debugs() parameter) or -1
Definition: Messages.h:53
a collection of DebugMessage objects (with fast access by message IDs)
Definition: Messages.h:68
Storage messages
Definition: Messages.h:72
std::array< DebugMessage, DebugMessageIdUpperBound > Storage
configurable messages indexed by their IDs
Definition: Messages.h:71
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:64
int DebugMessageLevel(const int defaultLevel)
Definition: Messages.h:82
DebugMessages * DebugMessagesConfig
Global configuration for DebugMessageLevel() (where/when supported).
Definition: Messages.h:76
size_t DebugMessageId
an identifier for messages supporting configuration via cache_log_message
Definition: Messages.h:22
#define DBG_IMPORTANT
Definition: Stream.h:38

 

Introduction

Documentation

Support

Miscellaneous

Web Site Translations

Mirrors