#ifndef SQUID_SRC_BASE_IO_MANIP_H
#define SQUID_SRC_BASE_IO_MANIP_H
+#include "debug/Stream.h"
+
#include <iostream>
#include <iomanip>
-/// debugs objects pointed by possibly nil pointers: label=object
+/// Safely prints an object pointed to by the given pointer: [label]<object>
+/// Prints nothing at all if the pointer is nil.
template <class Pointer>
class RawPointerT {
public:
RawPointerT(const char *aLabel, const Pointer &aPtr):
label(aLabel), ptr(aPtr) {}
+
+ /// Report the pointed-to-object on a dedicated Debug::Extra line.
+ RawPointerT<Pointer> &asExtra() { onExtraLine = true; return *this; }
+
const char *label; /// the name or description of the being-debugged object
const Pointer &ptr; /// a possibly nil pointer to the being-debugged object
+ bool onExtraLine = false;
};
/// convenience wrapper for creating RawPointerT<> objects
inline std::ostream &
operator <<(std::ostream &os, const RawPointerT<Pointer> &pd)
{
- os << pd.label << '=';
- if (pd.ptr)
- os << *pd.ptr;
- else
- os << "[nil]";
+ if (!pd.ptr)
+ return os;
+
+ if (pd.onExtraLine)
+ os << Debug::Extra;
+
+ if (pd.label)
+ os << pd.label;
+
+ os << *pd.ptr;
+
return os;
}
}
// TODO: Honor result.important when working in a reverse proxy role?
- debugs(83, 2, "ERROR: " << result.errorDescription <<
- " while establishing TLS connection on FD: " << serverConnection()->fd << result.errorDetail);
+ debugs(83, 2, "ERROR: Cannot establish a TLS connection to " << serverConnection() << ':' <<
+ Debug::Extra << "problem: " << result.errorDescription <<
+ RawPointer("detail: ", result.errorDetail).asExtra());
recordNegotiationDetails();
noteNegotiationError(result.errorDetail);
}
if (Debug::Enabled(83, 5)) {
Security::SessionPointer ssl(fd_table[serverConnection()->fd].ssl);
SBuf *server = static_cast<SBuf *>(SSL_get_ex_data(ssl.get(), ssl_ex_index_server));
- debugs(83,5, RawPointer("host", server) << " cert validation result: " << validationResponse->resultCode);
+ debugs(83, 5, "cert validation result: " << validationResponse->resultCode << RawPointer(" host: ", server));
}
if (validationResponse->resultCode == ::Helper::Error) {