stub_debug.cc
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 /*
10  * A stub implementation of the Debug.h API.
11  * For use by test binaries which do not need the full context debugging
12  *
13  * Note: it doesn't use the STUB API as the functions defined here must
14  * not abort the unit test.
15  */
16 #include "squid.h"
17 #include "debug/Stream.h"
18 
19 #define STUB_API "debug/libdebug.la"
20 #include "tests/STUB.h"
21 
23 char *Debug::cache_log= nullptr;
24 int Debug::rotateNumber = 0;
26 int Debug::override_X = 0;
27 bool Debug::log_syslog = false;
29 
30 void ResyncDebugLog(FILE *) STUB
31 
32 FILE *
34 {
35  return stderr;
36 }
37 
38 void
40 {}
41 
42 void
43 Debug::FormatStream(std::ostream &buf)
44 {
45  const static std::ostringstream cleanStream;
46  buf.flags(cleanStream.flags() | std::ios::fixed);
47  buf.width(cleanStream.width());
48  buf.precision(2);
49  buf.fill(' ');
50 }
51 
52 void
53 Debug::LogMessage(const Context &context)
54 {
55  if (context.level > DBG_IMPORTANT)
56  return;
57 
58  if (!stderr)
59  return;
60 
61  fprintf(stderr, "%s| %s\n",
62  "stub time", // debugLogTime(current_time),
63  context.buf.str().c_str());
64 }
65 
66 std::ostream &
67 Debug::Extra(std::ostream &os)
68 {
69  FormatStream(os);
70  os << "\n ";
71  return os;
72 }
73 
75 void Debug::PrepareToDie() STUB
76 
77 void
78 Debug::parseOptions(char const *)
79 {}
80 
82 
83 Debug::Context::Context(const int aSection, const int aLevel):
84  section(aSection),
85  level(aLevel),
86  sectionLevel(Levels[aSection]),
87  upper(Current),
88  forceAlert(false)
89 {
90  FormatStream(buf);
91 }
92 
93 std::ostringstream &
94 Debug::Start(const int section, const int level)
95 {
96  Current = new Context(section, level);
97  return Current->buf;
98 }
99 
100 void
102 {
103  if (Current) {
105  delete Current;
106  Current = nullptr;
107  }
108 }
109 
110 std::ostream&
111 ForceAlert(std::ostream& s)
112 {
113  return s;
114 }
115 
static char * debugOptions
Definition: Stream.h:80
static char * cache_log
Definition: Stream.h:81
Definition: Stream.h:46
std::ostringstream buf
debugs() output sink
Definition: Stream.h:66
static void FormatStream(std::ostream &)
configures default formatting for the debugging stream
Definition: debug.cc:1305
#define STUB_RETVAL(x)
Definition: STUB.h:42
void _db_rotate_log(void)
Definition: stub_debug.cc:39
Context(const int aSectionLevel, const int aLevel)
Definition: debug.cc:1277
static std::ostringstream & Start(const int section, const int level)
opens debugging context and returns output buffer
Definition: debug.cc:1342
static int Levels[MAX_DEBUG_SECTIONS]
Definition: Stream.h:83
meta-information for debugs() or a similar debugging call
Definition: Stream.h:51
static void Finish()
logs output buffer created in Start() and closes debugging context
Definition: debug.cc:1366
static bool StderrEnabled()
Definition: debug.cc:727
static int rotateNumber
Definition: Stream.h:82
FILE * DebugStream()
Definition: debug.cc:355
#define STUB
macro to stub a void function.
Definition: STUB.h:34
static std::ostream & Extra(std::ostream &)
Definition: debug.cc:1316
static bool log_syslog
Definition: Stream.h:85
#define MAX_DEBUG_SECTIONS
Definition: Stream.h:34
std::ostream & ForceAlert(std::ostream &s)
Definition: stub_debug.cc:111
static void LogMessage(const Context &)
broadcasts debugs() message to the logging channels
Definition: debug.cc:781
static void ForceAlert()
configures the active debugging context to write syslog ALERT
Definition: debug.cc:1403
#define DBG_IMPORTANT
Definition: Stream.h:38
static int override_X
Definition: Stream.h:84
void ResyncDebugLog(FILE *newFile)
a hack for low-level file descriptor manipulations in ipcCreate()
Definition: debug.cc:515
static Context * Current
deepest active context; nil outside debugs()
Definition: Stream.h:176

 

Introduction

Documentation

Support

Miscellaneous