stub_debug.cc
Go to the documentation of this file.
1 /*
2  * Copyright (C) 1996-2019 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.h"
18 
19 #define STUB_API "debug.cc"
20 #include "tests/STUB.h"
21 
23 char *Debug::cache_log= NULL;
24 int Debug::rotateNumber = 0;
26 int Debug::override_X = 0;
27 int Debug::log_stderr = 1;
28 bool Debug::log_syslog = false;
30 
32 void ResyncDebugLog(FILE *) STUB
33 
34 FILE *
36 {
37  return stderr;
38 }
39 
40 Ctx
41 ctx_enter(const char *)
42 {
43  return -1;
44 }
45 
46 void
48 {}
49 
50 void
51 _db_init(const char *, const char *)
52 {}
53 
54 void
55 _db_set_syslog(const char *)
56 {}
57 
58 void
60 {}
61 
62 static void
63 _db_print_stderr(const char *format, va_list args);
64 
65 void
66 _db_print(const char *format,...)
67 {
68  static char f[BUFSIZ];
69  va_list args1;
70  va_list args2;
71  va_list args3;
72 
73  va_start(args1, format);
74  va_start(args2, format);
75  va_start(args3, format);
76 
77  snprintf(f, BUFSIZ, "%s| %s",
78  "stub time", //debugLogTime(squid_curtime),
79  format);
80 
81  _db_print_stderr(f, args2);
82 
83  va_end(args1);
84  va_end(args2);
85  va_end(args3);
86 }
87 
88 static void
89 _db_print_stderr(const char *format, va_list args)
90 {
91  if (1 < Debug::Level())
92  return;
93 
94  vfprintf(stderr, format, args);
95 }
96 
97 void
98 Debug::parseOptions(char const *)
99 {}
100 
101 Debug::Context *Debug::Current = nullptr;
102 
103 Debug::Context::Context(const int aSection, const int aLevel):
104  level(aLevel),
105  sectionLevel(Levels[aSection]),
106  upper(Current),
107  forceAlert(false)
108 {
109  buf.setf(std::ios::fixed);
110  buf.precision(2);
111 }
112 
113 std::ostringstream &
114 Debug::Start(const int section, const int level)
115 {
116  Current = new Context(section, level);
117  return Current->buf;
118 }
119 
120 void
122 {
123  if (Current) {
124  _db_print("%s\n", Current->buf.str().c_str());
125  delete Current;
126  Current = nullptr;
127  }
128 }
129 
130 std::ostream&
131 ForceAlert(std::ostream& s)
132 {
133  return s;
134 }
135 
136 std::ostream &
137 Raw::print(std::ostream &os) const
138 {
139  if (label_)
140  os << ' ' << label_ << '[' << size_ << ']';
141 
142  if (!size_)
143  return os;
144 
145  // finalize debugging level if no level was set explicitly via minLevel()
146  const int finalLevel = (level >= 0) ? level :
147  (size_ > 40 ? DBG_DATA : Debug::SectionLevel());
148  if (finalLevel <= Debug::SectionLevel()) {
149  os << (label_ ? '=' : ' ');
150  if (data_)
151  os.write(data_, size_);
152  else
153  os << "[null]";
154  }
155 
156  return os;
157 }
158 
static void parseOptions(char const *)
Definition: debug.cc:459
static void Finish()
logs output buffer created in Start() and closes debugging context
Definition: debug.cc:844
static int rotateNumber
Definition: Debug.h:82
Context(const int aSectionLevel, const int aLevel)
Definition: debug.cc:786
static bool log_syslog
Definition: Debug.h:86
static void _db_print_stderr(const char *format, va_list args)
Definition: stub_debug.cc:89
static void ForceAlert()
configures the active debugging context to write syslog ALERT
Definition: debug.cc:858
static int Level()
minimum level required by the current debugs() call
Definition: Debug.h:91
std::ostringstream buf
debugs() output sink
Definition: Debug.h:70
Ctx ctx_enter(const char *)
Definition: stub_debug.cc:41
static int override_X
Definition: Debug.h:84
meta-information for debugs() or a similar debugging call
Definition: Debug.h:57
static int log_stderr
Definition: Debug.h:85
static char * debugOptions
Definition: Debug.h:80
static Context * Current
deepest active context; nil outside debugs()
Definition: Debug.h:103
static char * cache_log
Definition: Debug.h:81
#define STUB
macro to stub a void function.
Definition: STUB.h:33
void _db_rotate_log(void)
Definition: stub_debug.cc:59
#define BUFSIZ
Definition: defines.h:20
void _db_set_syslog(const char *)
Definition: stub_debug.cc:55
void const char * buf
Definition: stub_helper.cc:16
void StopUsingDebugLog()
start logging to stderr (instead of cache.log, if any)
Definition: debug.cc:82
void _db_print(const char *format,...)
Definition: stub_debug.cc:66
static std::ostringstream & Start(const int section, const int level)
opens debugging context and returns output buffer
Definition: debug.cc:823
void ResyncDebugLog(FILE *newFile)
a hack for low-level file descriptor manipulations in ipcCreate()
Definition: debug.cc:88
void ctx_exit(Ctx)
Definition: stub_debug.cc:47
static int Levels[MAX_DEBUG_SECTIONS]
Definition: Debug.h:83
std::ostream & print(std::ostream &os) const
Definition: debug.cc:886
#define DBG_DATA
Definition: Debug.h:48
static int SectionLevel()
maximum level currently allowed
Definition: Debug.h:93
FILE * DebugStream()
Definition: debug.cc:77
void _db_init(const char *, const char *)
Definition: stub_debug.cc:51
#define NULL
Definition: types.h:166
int Ctx
Definition: Debug.h:37
#define MAX_DEBUG_SECTIONS
Definition: Debug.h:42

 

Introduction

Documentation

Support

Miscellaneous

Web Site Translations

Mirrors