stub_debug.cc
Go to the documentation of this file.
1 /*
2  * Copyright (C) 1996-2018 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 {
108  buf.setf(std::ios::fixed);
109  buf.precision(2);
110 }
111 
112 std::ostringstream &
113 Debug::Start(const int section, const int level)
114 {
115  Current = new Context(section, level);
116  return Current->buf;
117 }
118 
119 void
121 {
122  if (Current) {
123  _db_print("%s\n", Current->buf.str().c_str());
124  delete Current;
125  Current = nullptr;
126  }
127 }
128 
129 std::ostream&
130 ForceAlert(std::ostream& s)
131 {
132  return s;
133 }
134 
135 std::ostream &
136 Raw::print(std::ostream &os) const
137 {
138  if (label_)
139  os << ' ' << label_ << '[' << size_ << ']';
140 
141  if (!size_)
142  return os;
143 
144  // finalize debugging level if no level was set explicitly via minLevel()
145  const int finalLevel = (level >= 0) ? level :
146  (size_ > 40 ? DBG_DATA : Debug::SectionLevel());
147  if (finalLevel <= Debug::SectionLevel()) {
148  os << (label_ ? '=' : ' ');
149  if (data_)
150  os.write(data_, size_);
151  else
152  os << "[null]";
153  }
154 
155  return os;
156 }
157 
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
std::ostream & print(std::ostream &os) const
Definition: debug.cc:886
void _db_set_syslog(const char *facility)
Definition: stub_debug.cc:55
static void ForceAlert()
configures the active debugging context to write syslog ALERT
Definition: debug.cc:858
void ctx_exit(Ctx ctx)
Definition: debug.cc:731
static int Level()
minimum level required by the current debugs() call
Definition: Debug.h:91
void _db_rotate_log(void)
Definition: debug.cc:502
std::ostringstream buf
debugs() output sink
Definition: Debug.h:70
static int override_X
Definition: Debug.h:84
meta-information for debugs() or a similar debugging call
Definition: Debug.h:57
std::ostream & ForceAlert(std::ostream &s)
Definition: debug.cc:866
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
size_t size_
data length
Definition: Debug.h:214
#define STUB
macro to stub a void function.
Definition: STUB.h:33
void _db_init(const char *logfile, const char *options)
Definition: debug.cc:484
Ctx ctx_enter(const char *descr)
Definition: debug.cc:715
#define BUFSIZ
Definition: defines.h:20
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
int level
Definition: Debug.h:207
static int Levels[MAX_DEBUG_SECTIONS]
Definition: Debug.h:83
#define DBG_DATA
Definition: Debug.h:48
static int SectionLevel()
maximum level currently allowed
Definition: Debug.h:93
FILE * DebugStream()
Definition: debug.cc:77
#define NULL
Definition: types.h:166
const char * label_
optional data name or ID; triggers size printing
Definition: Debug.h:212
int Ctx
Definition: Debug.h:37
#define MAX_DEBUG_SECTIONS
Definition: Debug.h:42
const char * data_
raw data to be printed
Definition: Debug.h:213

 

Introduction

Documentation

Support

Miscellaneous

Web Site Translations

Mirrors