debug.cc File Reference
#include "squid.h"
#include "base/TextException.h"
#include "debug/Stream.h"
#include "fatal.h"
#include "fd.h"
#include "ipc/Kids.h"
#include "time/gadgets.h"
#include "util.h"
#include <algorithm>
#include <deque>
#include <functional>
#include <memory>
#include <optional>
Include dependency graph for debug.cc:

Go to the source code of this file.

Classes

class  DebugFile
 a named FILE with very-early/late usage safety mechanisms More...
 
class  DebugMessageHeader
 meta-information of a Finish()ed debugs() message More...
 
class  CompiledDebugMessage
 a fully processed debugs(), ready to be logged More...
 
class  DebugChannel
 a receiver of debugs() messages (e.g., stderr or cache.log) More...
 
class  DebugChannel::Logger
 output iterator for writing CompiledDebugMessages to a given channel More...
 
class  CacheLogChannel
 DebugChannel managing messages destined for the configured cache_log file. More...
 
class  StderrChannel
 DebugChannel managing messages destined for "standard error stream" (stderr) More...
 
class  SyslogChannel
 syslog DebugChannel More...
 
class  DebugModule
 
class  LoggingSectionGuard
 

Typedefs

using DebugRecordCount = uint64_t
 a counter related to the number of debugs() calls More...
 
using CompiledDebugMessageBody = std::string
 The processed "content" (i.e. the last parameter) part of a debugs() call. More...
 
using CompiledDebugMessages = std::deque< CompiledDebugMessage >
 debugs() messages captured in LogMessage() call order More...
 

Functions

static const char * debugLogTime (const timeval &)
 
static void ResetSections (const int level)
 used for the side effect: fills Debug::Levels with the given level More...
 
FILE * DebugStream ()
 
static void LabelThisProcess (const char *const name, const std::optional< int > id=std::optional< int >())
 optimization: formats ProcessLabel once for frequent debugs() reuse More...
 
static DebugModuleModule ()
 safe access to the debugging module More...
 
void ResyncDebugLog (FILE *newFile)
 a hack for low-level file descriptor manipulations in ipcCreate() More...
 
static void debugArg (const char *arg)
 
static void debugOpenLog (const char *logfile)
 
void _db_rotate_log (void)
 
void xassert (const char *msg, const char *file, int line)
 
std::ostream & ForceAlert (std::ostream &s)
 

Variables

static DebugModuleModule_ = nullptr
 Debugging module singleton. More...
 
static std::optional< intExplicitStderrLevel
 
static int DefaultStderrLevel = -1
 
static constexpr int EarlyMessagesLevel = DBG_IMPORTANT
 early debugs() with higher level are not buffered and, hence, may be lost More...
 
static std::string ProcessLabel
 pre-formatted name of the current process for debugs() messages (or empty) More...
 
static bool DidResetSections = false
 
static Debug::ContextWaitingForIdle = nullptr
 
static DebugFile TheLog
 
static auto Asserting_ = false
 

Typedef Documentation

◆ CompiledDebugMessageBody

using CompiledDebugMessageBody = std::string

Definition at line 125 of file debug.cc.

◆ CompiledDebugMessages

Definition at line 144 of file debug.cc.

◆ DebugRecordCount

using DebugRecordCount = uint64_t

Definition at line 34 of file debug.cc.

Function Documentation

◆ _db_rotate_log()

void _db_rotate_log ( void  )

◆ debugArg()

static void debugArg ( const char *  arg)
static

Definition at line 823 of file debug.cc.

References assert, Debug::Levels, MAX_DEBUG_SECTIONS, ResetSections(), and Debug::rotateNumber.

Referenced by Debug::parseOptions().

◆ debugLogTime()

static const char * debugLogTime ( const timeval &  t)
static

Definition at line 1224 of file debug.cc.

References assert, and Debug::Level().

Referenced by DebugChannel::writeToStream().

◆ debugOpenLog()

static void debugOpenLog ( const char *  logfile)
static

◆ DebugStream()

FILE * DebugStream ( )

cache.log FILE or, as the last resort, stderr stream; may be nil during static initialization and destruction!

Definition at line 354 of file debug.cc.

References DebugFile::file(), and TheLog.

◆ ForceAlert()

std::ostream & ForceAlert ( std::ostream &  s)

Does not change the stream being manipulated. Exists for its side effect: In a debugs() context, forces the message to become a syslog ALERT. Outside of debugs() context, has no effect and should not be used.

Definition at line 1408 of file debug.cc.

References Debug::ForceAlert().

Referenced by death(), and fatal_common().

◆ LabelThisProcess()

static void LabelThisProcess ( const char *const  name,
const std::optional< int id = std::optional<int>() 
)
static

Definition at line 369 of file debug.cc.

References assert, and ProcessLabel.

Referenced by Debug::NameThisHelper(), and Debug::NameThisKid().

◆ Module()

◆ ResetSections()

static void ResetSections ( const int  level = DBG_IMPORTANT)
static

Definition at line 360 of file debug.cc.

References DidResetSections, and Debug::Levels.

Referenced by DebugModule::DebugModule(), debugArg(), and Debug::parseOptions().

◆ ResyncDebugLog()

void ResyncDebugLog ( FILE *  newFile)

Definition at line 514 of file debug.cc.

Referenced by ipcCreate().

◆ xassert()

void xassert ( const char *  msg,
const char *  file,
int  line 
)

Definition at line 1257 of file debug.cc.

References Asserting_, DBG_CRITICAL, debugs, and Debug::PrepareToDie().

Variable Documentation

◆ Asserting_

auto Asserting_ = false
static

Whether there are any xassert() calls in the call stack. Treat as private to xassert(): It is moved out only to simplify the asserting code path.

Definition at line 1254 of file debug.cc.

Referenced by xassert().

◆ DefaultStderrLevel

int DefaultStderrLevel = -1
static

ExplicitStderrLevel preference or default: Just like with ExplicitStderrLevel, debugs() messages with this (or lower) level will be written to stderr (and possibly other channels), but this setting is ignored when ExplicitStderrLevel is set. This setting is also ignored after major problems that prevent logging of important debugs() messages (e.g., failing to open cache_log or assertions).

Definition at line 52 of file debug.cc.

Referenced by StderrChannel::enabled(), and Debug::EnsureDefaultStderrLevel().

◆ DidResetSections

bool DidResetSections = false
static

Whether ResetSections() has been called already. We need to keep track of this state because external code may trigger ResetSections() before the DebugModule constructor has a chance to ResetSections() to their defaults. TODO: Find a way to static-initialize Debug::Levels instead.

Definition at line 79 of file debug.cc.

Referenced by DebugModule::DebugModule(), and ResetSections().

◆ EarlyMessagesLevel

constexpr int EarlyMessagesLevel = DBG_IMPORTANT
staticconstexpr

Definition at line 55 of file debug.cc.

Referenced by DebugChannel::saveMessage().

◆ ExplicitStderrLevel

std::optional<int> ExplicitStderrLevel
static

Explicitly configured maximum level for debugs() messages written to stderr. debugs() messages with this (or lower) level will be written to stderr (and possibly other channels).

Definition at line 44 of file debug.cc.

Referenced by StderrChannel::enabled(), Debug::ResetStderrLevel(), and Debug::SettleStderr().

◆ Module_

DebugModule* Module_ = nullptr
static

Definition at line 39 of file debug.cc.

Referenced by Module().

◆ ProcessLabel

std::string ProcessLabel
static

Definition at line 58 of file debug.cc.

Referenced by LabelThisProcess(), Debug::NameThisKid(), and DebugChannel::writeToStream().

◆ TheLog

DebugFile TheLog
static

cache_log file safe during static initialization, even if it has not been constructed yet safe during program termination, even if it has been destructed already

Definition at line 351 of file debug.cc.

Referenced by _db_rotate_log(), DebugModule::banCacheLogUse(), debugOpenLog(), DebugStream(), Debug::LogMessage(), DebugModule::prepareToDie(), CacheLogChannel::shouldWrite(), Debug::StopCacheLogUse(), DebugModule::useCacheLog(), and CacheLogChannel::write().

◆ WaitingForIdle

Debug::Context* WaitingForIdle = nullptr
static

debugs() messages postponed due to LoggingSectionGuard::Busy(). This is the head of the invasive Context::upper FIFO list of such messages.

Definition at line 346 of file debug.cc.

Referenced by Debug::Finish(), and Debug::LogWaitingForIdle().

 

Introduction

Documentation

Support

Miscellaneous

Web Site Translations

Mirrors