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

 

Introduction

Documentation

Support

Miscellaneous

Web Site Translations

Mirrors