mirror of
https://github.com/RetroShare/RetroShare.git
synced 2025-01-14 00:49:41 -05:00
Merge pull request #1992 from G10h4ck/debug_strip
Multiple improvements in debugging helpers
This commit is contained in:
commit
6603accf8f
@ -467,18 +467,18 @@ void JsonApiServer::registerHandler(
|
|||||||
const std::function<void (const std::shared_ptr<rb::Session>)>& callback )
|
const std::function<void (const std::shared_ptr<rb::Session>)>& callback )
|
||||||
{
|
{
|
||||||
/* Declare outside the lambda to avoid returning a dangling
|
/* Declare outside the lambda to avoid returning a dangling
|
||||||
* reference on Android */
|
* reference */
|
||||||
RsWarn tWarn;
|
RsWarn tWarn;
|
||||||
const auto authFail =
|
const auto authFail =
|
||||||
[&](int status) -> RsWarn::stream_type&
|
[&](int status) -> std::ostream&
|
||||||
{
|
{
|
||||||
/* Capture session by reference as it is cheaper then copying
|
/* Capture session by reference as it is cheaper then copying
|
||||||
* shared_ptr by value which is not needed in this case */
|
* shared_ptr by value which is not needed in this case */
|
||||||
|
|
||||||
session->close(status, corsOptionsHeaders);
|
session->close(status, corsOptionsHeaders);
|
||||||
return tWarn << "JsonApiServer authentication handler "
|
return tWarn << "JsonApiServer authentication handler "
|
||||||
"blocked an attempt to call JSON API "
|
"blocked an attempt to call JSON API "
|
||||||
"authenticated method: " << path;
|
"authenticated method: " << path;
|
||||||
};
|
};
|
||||||
|
|
||||||
if(session->get_request()->get_method() == "OPTIONS")
|
if(session->get_request()->get_method() == "OPTIONS")
|
||||||
|
@ -468,7 +468,12 @@ HEADERS += turtle/p3turtle.h \
|
|||||||
turtle/turtleclientservice.h
|
turtle/turtleclientservice.h
|
||||||
|
|
||||||
HEADERS += util/folderiterator.h \
|
HEADERS += util/folderiterator.h \
|
||||||
util/rsdebug.h \
|
util/rsdebug.h \
|
||||||
|
util/rsdebuglevel0.h \
|
||||||
|
util/rsdebuglevel1.h \
|
||||||
|
util/rsdebuglevel2.h \
|
||||||
|
util/rsdebuglevel3.h \
|
||||||
|
util/rsdebuglevel4.h \
|
||||||
util/rskbdinput.h \
|
util/rskbdinput.h \
|
||||||
util/rsmemory.h \
|
util/rsmemory.h \
|
||||||
util/smallobject.h \
|
util/smallobject.h \
|
||||||
|
@ -507,25 +507,27 @@ private:
|
|||||||
|
|
||||||
std::map<uint32_t,TokenRequestType> mActiveTokens;
|
std::map<uint32_t,TokenRequestType> mActiveTokens;
|
||||||
|
|
||||||
|
#ifdef DEBUG_GXSIFACEHELPER
|
||||||
void locked_dumpTokens()
|
void locked_dumpTokens()
|
||||||
{
|
{
|
||||||
const uint16_t service_id = mGxs.serviceType();
|
const uint16_t service_id = mGxs.serviceType();
|
||||||
const auto countSize = static_cast<size_t>(TokenRequestType::__MAX);
|
const auto countSize = static_cast<size_t>(TokenRequestType::__MAX);
|
||||||
uint32_t count[countSize] = {0};
|
uint32_t count[countSize] = {0};
|
||||||
|
|
||||||
RsDbg() << __PRETTY_FUNCTION__ << "Service 0x" << std::hex << service_id
|
RsDbg rsdbg;
|
||||||
<< " (" << rsServiceControl->getServiceName(
|
rsdbg << __PRETTY_FUNCTION__ << " Service 0x" << std::hex << service_id
|
||||||
RsServiceInfo::RsServiceInfoUIn16ToFullServiceId(service_id) )
|
<< " (" << rsServiceControl->getServiceName(
|
||||||
<< ") this=0x" << static_cast<void*>(this)
|
RsServiceInfo::RsServiceInfoUIn16ToFullServiceId(service_id) )
|
||||||
<< ") Active tokens (per type): ";
|
<< ") this=0x" << static_cast<void*>(this)
|
||||||
|
<< ") Active tokens (per type): ";
|
||||||
|
|
||||||
// let's count how many token of each type we've got.
|
// let's count how many token of each type we've got.
|
||||||
for(auto& it: mActiveTokens) ++count[static_cast<size_t>(it.second)];
|
for(auto& it: mActiveTokens) ++count[static_cast<size_t>(it.second)];
|
||||||
|
|
||||||
for(uint32_t i=0; i < countSize; ++i)
|
for(uint32_t i=0; i < countSize; ++i)
|
||||||
RsDbg().uStream() /* << i << ":" */ << count[i] << " ";
|
rsdbg /* << i << ":" */ << count[i] << " ";
|
||||||
RsDbg().uStream() << std::endl;
|
|
||||||
}
|
}
|
||||||
|
#endif // def DEBUG_GXSIFACEHELPER
|
||||||
|
|
||||||
RS_SET_CONTEXT_DEBUG_LEVEL(1)
|
RS_SET_CONTEXT_DEBUG_LEVEL(1)
|
||||||
};
|
};
|
||||||
|
@ -235,8 +235,7 @@ template<> bool RsTypeSerializer::from_JSON( \
|
|||||||
\
|
\
|
||||||
if(!ret) \
|
if(!ret) \
|
||||||
{ \
|
{ \
|
||||||
Dbg3() << __PRETTY_FUNCTION__ << " " << memberName << " not found" \
|
RS_DBG3(memberName, " not found"); \
|
||||||
<< std::endl; \
|
|
||||||
return false; \
|
return false; \
|
||||||
} \
|
} \
|
||||||
\
|
\
|
||||||
|
@ -39,7 +39,7 @@
|
|||||||
#include "serialiser/rsserializer.h"
|
#include "serialiser/rsserializer.h"
|
||||||
#include "serialiser/rsserializable.h"
|
#include "serialiser/rsserializable.h"
|
||||||
#include "util/rsjson.h"
|
#include "util/rsjson.h"
|
||||||
#include "util/rsdebug.h"
|
#include "util/rsdebuglevel1.h"
|
||||||
#include "util/cxx14retrocompat.h"
|
#include "util/cxx14retrocompat.h"
|
||||||
|
|
||||||
|
|
||||||
@ -715,12 +715,9 @@ struct RsTypeSerializer
|
|||||||
E& member,
|
E& member,
|
||||||
const std::string& memberName )
|
const std::string& memberName )
|
||||||
{
|
{
|
||||||
#ifdef RSSERIAL_DEBUG
|
RS_DBG4( "processing enum: ", typeid(E).name(), " as ",
|
||||||
std::cerr << __PRETTY_FUNCTION__ << " processing enum: "
|
typeid(typename std::underlying_type<E>::type).name() );
|
||||||
<< typeid(E).name() << " as "
|
|
||||||
<< typeid(typename std::underlying_type<E>::type).name()
|
|
||||||
<< std::endl;
|
|
||||||
#endif
|
|
||||||
serial_process(
|
serial_process(
|
||||||
j, ctx,
|
j, ctx,
|
||||||
reinterpret_cast<typename std::underlying_type<E>::type&>(member),
|
reinterpret_cast<typename std::underlying_type<E>::type&>(member),
|
||||||
@ -1004,14 +1001,16 @@ protected:
|
|||||||
uint8_t data[], uint32_t size, uint32_t &offset, T member )
|
uint8_t data[], uint32_t size, uint32_t &offset, T member )
|
||||||
{
|
{
|
||||||
std::decay_t<T> backupMember = member;
|
std::decay_t<T> backupMember = member;
|
||||||
|
#if RS_DEBUG_LEVEL >= 3
|
||||||
uint32_t offsetBackup = offset;
|
uint32_t offsetBackup = offset;
|
||||||
|
#endif
|
||||||
|
|
||||||
bool ok = true;
|
bool ok = true;
|
||||||
#pragma GCC diagnostic push
|
#pragma GCC diagnostic push
|
||||||
#pragma GCC diagnostic ignored "-Wbool-compare"
|
#pragma GCC diagnostic ignored "-Wbool-compare"
|
||||||
/* Check with < and not with <= here as we write last byte after
|
/* Check with < and not with <= here as we write last byte after
|
||||||
* the loop. Order of && operands very important here! */
|
* the loop. Order of && operands very important here! */
|
||||||
while(member > 127 && (ok = offset < size))
|
while(member > 127 && (ok = (offset < size)))
|
||||||
{
|
{
|
||||||
// | 128: Set the next byte flag
|
// | 128: Set the next byte flag
|
||||||
data[offset++] = (static_cast<uint8_t>(member & 127)) | 128;
|
data[offset++] = (static_cast<uint8_t>(member & 127)) | 128;
|
||||||
@ -1036,13 +1035,13 @@ protected:
|
|||||||
|
|
||||||
data[offset++] = static_cast<uint8_t>(member & 127);
|
data[offset++] = static_cast<uint8_t>(member & 127);
|
||||||
|
|
||||||
Dbg3() << __PRETTY_FUNCTION__ << " backupMember: " << backupMember
|
#if RS_DEBUG_LEVEL >= 3
|
||||||
<< " offsetBackup: " << offsetBackup << " offeset: " << offset
|
RsDbg tdbg( __PRETTY_FUNCTION__, " backupMember: ", backupMember,
|
||||||
<< " serialized as: ";
|
" offsetBackup: ", offsetBackup, " offeset: ", offset,
|
||||||
|
" serialized as: " );
|
||||||
for(; offsetBackup < offset; ++offsetBackup)
|
for(; offsetBackup < offset; ++offsetBackup)
|
||||||
Dbg3().uStream() << " " << std::bitset<8>(data[offsetBackup]);
|
tdbg << " " << std::bitset<8>(data[offsetBackup]);
|
||||||
Dbg3().uStream() << std::endl;
|
#endif
|
||||||
|
|
||||||
return ok;
|
return ok;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1082,13 +1081,13 @@ protected:
|
|||||||
/* If return is not triggered inside the for loop, either the buffer
|
/* If return is not triggered inside the for loop, either the buffer
|
||||||
* ended before we encountered the end of the number, or the number
|
* ended before we encountered the end of the number, or the number
|
||||||
* is VLQ encoded improperly */
|
* is VLQ encoded improperly */
|
||||||
RsErr() << __PRETTY_FUNCTION__ << std::errc::illegal_byte_sequence
|
RsErr rserr;
|
||||||
<< " size: " << size
|
rserr << __PRETTY_FUNCTION__ << std::errc::illegal_byte_sequence
|
||||||
<< " offsetBackup: " << offsetBackup
|
<< " size: " << size
|
||||||
<< " offset: " << offset << " bytes: ";
|
<< " offsetBackup: " << offsetBackup
|
||||||
|
<< " offset: " << offset << " bytes: ";
|
||||||
for(; offsetBackup < offset; ++offsetBackup)
|
for(; offsetBackup < offset; ++offsetBackup)
|
||||||
RsErr().uStream() << " " << std::bitset<8>(data[offsetBackup]);
|
rserr << " " << std::bitset<8>(data[offsetBackup]);
|
||||||
RsErr().uStream() << std::endl;
|
|
||||||
print_stacktrace();
|
print_stacktrace();
|
||||||
|
|
||||||
return false;
|
return false;
|
||||||
@ -1151,7 +1150,7 @@ protected:
|
|||||||
|
|
||||||
struct ErrConditionWrapper : RsSerializable
|
struct ErrConditionWrapper : RsSerializable
|
||||||
{
|
{
|
||||||
ErrConditionWrapper(const std::error_condition& ec): mec(ec) {}
|
explicit ErrConditionWrapper(const std::error_condition& ec): mec(ec) {}
|
||||||
|
|
||||||
/** supports only TO_JSON if a different SerializeJob is passed it will
|
/** supports only TO_JSON if a different SerializeJob is passed it will
|
||||||
* explode at runtime */
|
* explode at runtime */
|
||||||
|
@ -21,19 +21,23 @@
|
|||||||
*******************************************************************************/
|
*******************************************************************************/
|
||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
#include <ostream>
|
#include <string>
|
||||||
|
#include <sstream>
|
||||||
#include <system_error>
|
#include <system_error>
|
||||||
|
|
||||||
/** Stream helper for std::error_condition */
|
|
||||||
std::ostream &operator<<(std::ostream& out, const std::error_condition& err);
|
|
||||||
|
|
||||||
#ifdef __ANDROID__
|
#ifdef __ANDROID__
|
||||||
# include <android/log.h>
|
# include <android/log.h>
|
||||||
# include <sstream>
|
#else // def __ANDROID__
|
||||||
# include <string>
|
# include <iostream>
|
||||||
|
# include <chrono>
|
||||||
|
# include <iomanip>
|
||||||
|
#endif // def __ANDROID__
|
||||||
|
|
||||||
# include "util/rsjson.h"
|
|
||||||
|
|
||||||
|
#include "util/rsjson.h"
|
||||||
|
|
||||||
|
|
||||||
|
#ifdef __ANDROID__
|
||||||
enum class RsLoggerCategories
|
enum class RsLoggerCategories
|
||||||
{
|
{
|
||||||
DEBUG = ANDROID_LOG_DEBUG,
|
DEBUG = ANDROID_LOG_DEBUG,
|
||||||
@ -42,72 +46,7 @@ enum class RsLoggerCategories
|
|||||||
ERROR = ANDROID_LOG_ERROR,
|
ERROR = ANDROID_LOG_ERROR,
|
||||||
FATAL = ANDROID_LOG_FATAL
|
FATAL = ANDROID_LOG_FATAL
|
||||||
};
|
};
|
||||||
|
|
||||||
template <RsLoggerCategories CATEGORY>
|
|
||||||
struct t_RsLogger
|
|
||||||
{
|
|
||||||
inline t_RsLogger() = default;
|
|
||||||
|
|
||||||
/** Offer variadic style too, as a benefit this has better atomicity then
|
|
||||||
* << style, but doesn't supports manipulators and things like std::endl
|
|
||||||
* @see https://stackoverflow.com/a/27375675 */
|
|
||||||
template <typename Arg, typename... Args>
|
|
||||||
inline t_RsLogger(Arg&& arg, Args&&... args)
|
|
||||||
{
|
|
||||||
ostr << std::forward<Arg>(arg);
|
|
||||||
using expander = int[];
|
|
||||||
(void)expander{0, (void(ostr << std::forward<Args>(args)), 0)...};
|
|
||||||
mFlush();
|
|
||||||
}
|
|
||||||
|
|
||||||
/** On other platforms expose the type of underlying stream.
|
|
||||||
* On Android it cannot work like that so return the class type itself
|
|
||||||
* just for code compatibility with other platforms */
|
|
||||||
using stream_type = t_RsLogger;
|
|
||||||
|
|
||||||
template<typename T>
|
|
||||||
inline stream_type& operator<<(const T& val)
|
|
||||||
{ ostr << val; return *this; }
|
|
||||||
|
|
||||||
template<typename T>
|
|
||||||
inline stream_type& operator<<(const RsJson& val)
|
|
||||||
{ ostr << val; return *this; }
|
|
||||||
|
|
||||||
/// needed for manipulators and things like std::endl
|
|
||||||
stream_type& operator<<(std::ostream& (*pf)(std::ostream&))
|
|
||||||
{
|
|
||||||
if(pf == static_cast<std::ostream& (*)(std::ostream&)>(
|
|
||||||
&std::endl< char, std::char_traits<char> > ))
|
|
||||||
mFlush();
|
|
||||||
else ostr << pf;
|
|
||||||
|
|
||||||
return *this;
|
|
||||||
}
|
|
||||||
|
|
||||||
/** On other platforms return underlying stream to write avoiding additional
|
|
||||||
* prefixes. On Android it cannot work like that so return the object itself
|
|
||||||
* just for code compatibility with other platforms */
|
|
||||||
inline stream_type& uStream() { return *this; }
|
|
||||||
|
|
||||||
private:
|
|
||||||
std::ostringstream ostr;
|
|
||||||
|
|
||||||
void mFlush()
|
|
||||||
{
|
|
||||||
__android_log_write(
|
|
||||||
static_cast<int>(CATEGORY),
|
|
||||||
"RetroShare", ostr.str().c_str() );
|
|
||||||
ostr.str() = "";
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
#else // def __ANDROID__
|
#else // def __ANDROID__
|
||||||
|
|
||||||
#include <iostream>
|
|
||||||
#include <chrono>
|
|
||||||
#include <iomanip>
|
|
||||||
#include <sstream>
|
|
||||||
|
|
||||||
enum class RsLoggerCategories
|
enum class RsLoggerCategories
|
||||||
{
|
{
|
||||||
DEBUG = 'D',
|
DEBUG = 'D',
|
||||||
@ -116,90 +55,101 @@ enum class RsLoggerCategories
|
|||||||
ERROR = 'E',
|
ERROR = 'E',
|
||||||
FATAL = 'F'
|
FATAL = 'F'
|
||||||
};
|
};
|
||||||
|
#endif // def __ANDROID__
|
||||||
|
|
||||||
|
|
||||||
|
/** Stream helper for std::error_condition */
|
||||||
|
std::ostream &operator<<(std::ostream& out, const std::error_condition& err);
|
||||||
|
|
||||||
|
|
||||||
template <RsLoggerCategories CATEGORY>
|
template <RsLoggerCategories CATEGORY>
|
||||||
struct t_RsLogger
|
struct t_RsLogger : std::ostringstream
|
||||||
{
|
{
|
||||||
/// Expose the type of underlying stream
|
t_RsLogger() { setPrefix(); }
|
||||||
using stream_type = decltype(std::cerr);
|
~t_RsLogger() { flush(); }
|
||||||
|
|
||||||
/// Return underlying stream to write avoiding additional prefixes
|
/** Offer variadic style, this doesn't supports things like std::endl as
|
||||||
static inline stream_type& uStream() { return std::cerr; }
|
* paramether but when used toghether with conditional debugging macros
|
||||||
|
* reduces binary size as paramethers of suppressed calls are not evaluated
|
||||||
inline t_RsLogger() = default;
|
* and literally disappear in preprocessing fase @see RsDbg */
|
||||||
|
template <typename... Args>
|
||||||
/** Offer variadic style too, as a benefit this has better atomicity then
|
explicit inline t_RsLogger(Args&&... args)
|
||||||
* << style, but doesn't supports manipulators and things like std::endl
|
|
||||||
* @see https://stackoverflow.com/a/27375675 */
|
|
||||||
template <typename Arg, typename... Args>
|
|
||||||
inline t_RsLogger(Arg&& arg, Args&&... args)
|
|
||||||
{
|
{
|
||||||
std::ostringstream ostr;
|
setPrefix();
|
||||||
ostr << getPrefix() << std::forward<Arg>(arg);
|
|
||||||
using expander = int[];
|
/* Combine initializer list and comma operator so the compiler unpack
|
||||||
(void)expander{0, (void(ostr << std::forward<Args>(args)), 0)...};
|
* template arguments and feed our own stream without recursion
|
||||||
ostr << std::endl;
|
* see https://stackoverflow.com/a/27375675 */
|
||||||
uStream() << ostr.str();
|
using expander = char[];
|
||||||
|
(void) expander {0, (void((*this) << std::forward<Args>(args)), 0)...};
|
||||||
}
|
}
|
||||||
|
|
||||||
template<typename T>
|
/** Dump buffer stream to log */
|
||||||
inline stream_type& operator<<(const T& val)
|
void flush()
|
||||||
{ return uStream() << getPrefix() << val; }
|
{
|
||||||
|
#ifdef __ANDROID__
|
||||||
/// needed for manipulators and things like std::endl
|
__android_log_write(
|
||||||
stream_type& operator<<(std::ostream& (*pf)(std::ostream&))
|
static_cast<int>(CATEGORY),
|
||||||
{ return uStream() << pf; }
|
"RetroShare", str().c_str() );
|
||||||
|
#else // def __ANDROID__
|
||||||
|
(*this) << std::endl;
|
||||||
|
std::cerr << str();
|
||||||
|
#endif // def __ANDROID__
|
||||||
|
str() = "";
|
||||||
|
}
|
||||||
|
|
||||||
private:
|
private:
|
||||||
std::string getPrefix()
|
#ifdef __ANDROID__
|
||||||
|
inline void setPrefix() {}
|
||||||
|
#else // def __ANDROID__
|
||||||
|
void setPrefix()
|
||||||
{
|
{
|
||||||
using namespace std::chrono;
|
using namespace std::chrono;
|
||||||
const auto now = system_clock::now();
|
const auto now = system_clock::now();
|
||||||
const auto sec = time_point_cast<seconds>(now);
|
const auto sec = time_point_cast<seconds>(now);
|
||||||
const auto msec = duration_cast<milliseconds>(now - sec);
|
const auto msec = duration_cast<milliseconds>(now - sec);
|
||||||
std::ostringstream tstream;
|
(*this) << static_cast<char>(CATEGORY) << " "
|
||||||
tstream << static_cast<char>(CATEGORY) << " "
|
|
||||||
<< sec.time_since_epoch().count() << "."
|
<< sec.time_since_epoch().count() << "."
|
||||||
<< std::setfill('0') << std::setw(3) << msec.count()
|
<< std::setfill('0') << std::setw(3) << msec.count() << " ";
|
||||||
<< " ";
|
|
||||||
return tstream.str();
|
|
||||||
}
|
}
|
||||||
};
|
|
||||||
#endif // def __ANDROID__
|
#endif // def __ANDROID__
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Comfortable debug message logging, supports chaining like std::cerr but can
|
* Comfortable debug message logging, supports both variadic style and chaining
|
||||||
* be easly and selectively disabled at compile time to reduce generated binary
|
* style like std::cerr.
|
||||||
* size and performance impact without too many \#ifdef around.
|
* Can be easly and selectively disabled at compile time.
|
||||||
|
* To reduce generated binary size and performance impact when debugging is
|
||||||
|
* disabled without too many \#ifdef around the code combining the variadic
|
||||||
|
* style with the leveled debugging macros is the way to go.
|
||||||
*
|
*
|
||||||
* To selectively debug your context you can just add something like this in
|
* To selectively debug your file you just need to include the header of desired
|
||||||
* in that context, as an example for a class you can just add a line like this
|
* debugging level (0 to 4)
|
||||||
* inside class declaration:
|
|
||||||
@code{.cpp}
|
@code{.cpp}
|
||||||
RS_SET_CONTEXT_DEBUG_LEVEL(2)
|
#include "util/rsdebuglevel2.h"
|
||||||
@endcode
|
@endcode
|
||||||
* And the you can write debug messages around the code of the class like this:
|
* Then where you want to print debug messages use
|
||||||
@code{.cpp}
|
@code{.cpp}
|
||||||
Dbg1() << "Level 1 debug message example, this will be compiled and "
|
RS_DBG0("Hello 0 ", "my debug ", my_variable) << " message " << variable2;
|
||||||
<< "printed" << std::endl;
|
RS_DBG1("Hello 1 ", "my debug ", my_variable) << " message " << variable2;
|
||||||
Dbg2() << "Level 2 debug message example, this will be compiled and "
|
RS_DBG2("Hello 2 ", "my debug ", my_variable) << " message " << variable2;
|
||||||
<< "printed" << std::endl;
|
RS_DBG3("Hello 3 ", "my debug ", my_variable) << " message " << variable2;
|
||||||
Dbg3() << "Level 3 debug message example, this will not be compiled and "
|
RS_DBG4("Hello 4 ", "my debug ", my_variable) << " message " << variable2;
|
||||||
<< "printed, and without #ifdef around!!" << std::endl;
|
|
||||||
Dbg4() << "Level 4 debug message example, this will not be compiled and "
|
|
||||||
<< "printed, and without #ifdef around!!" << std::endl;
|
|
||||||
@endcode
|
@endcode
|
||||||
* To change the debugging level, for example to completely disable debug
|
* To change the debugging level just include a different level header like
|
||||||
* messages you can change it to 0
|
* `util/rsdebuglevel1.h`, debug messages with lower or equal level then the
|
||||||
@code{.cpp}
|
* included header will be printed, the others will not.
|
||||||
RS_SET_CONTEXT_DEBUG_LEVEL(0)
|
* Remember then on messages with debug level higher then the included the
|
||||||
@endcode
|
* paramethers you pass as macro arguments (variadic style) will disappear in
|
||||||
* While to set it to maximim level you have to pass 4.
|
* the preprocessing phase, so their evaluation will not be included in the
|
||||||
|
* final binary and not executed at runtime, instead the paramether passed with
|
||||||
|
* `<<` (chaining style) will be in the compiled binary and evaluated at runtime
|
||||||
|
* even if are not printed, due to how C++ is made it is not possible to avoid
|
||||||
|
* this, so we suggest to use variadic style for debug messages.
|
||||||
*/
|
*/
|
||||||
using RsDbg = t_RsLogger<RsLoggerCategories::DEBUG>;
|
using RsDbg = t_RsLogger<RsLoggerCategories::DEBUG>;
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Comfortable log information reporting helper, supports chaining like
|
* Comfortable log information reporting helper, supports chaining like
|
||||||
* std::cerr.
|
* std::cerr.
|
||||||
@ -220,6 +170,7 @@ using RsErr = t_RsLogger<RsLoggerCategories::ERROR>;
|
|||||||
* to terminate) messages */
|
* to terminate) messages */
|
||||||
using RsFatal = t_RsLogger<RsLoggerCategories::FATAL>;
|
using RsFatal = t_RsLogger<RsLoggerCategories::FATAL>;
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Keeps compatible syntax with RsDbg but explicitely do nothing in a way that
|
* Keeps compatible syntax with RsDbg but explicitely do nothing in a way that
|
||||||
* any modern compiler should be smart enough to optimize out all the function
|
* any modern compiler should be smart enough to optimize out all the function
|
||||||
@ -228,27 +179,32 @@ using RsFatal = t_RsLogger<RsLoggerCategories::FATAL>;
|
|||||||
struct RsNoDbg
|
struct RsNoDbg
|
||||||
{
|
{
|
||||||
inline RsNoDbg() = default;
|
inline RsNoDbg() = default;
|
||||||
|
template <typename... Args> inline explicit RsNoDbg(Args...) {}
|
||||||
template <typename T, typename... Args> inline RsNoDbg(T, Args...) {}
|
|
||||||
|
|
||||||
/** Defined as the type itself just for code compatibility with other
|
|
||||||
* logging classes */
|
|
||||||
using stream_type = RsNoDbg;
|
|
||||||
|
|
||||||
/** This match most of the types, but might be not enough for templated
|
/** This match most of the types, but might be not enough for templated
|
||||||
* types */
|
* types */
|
||||||
template<typename T>
|
template<typename T>
|
||||||
inline stream_type& operator<<(const T&) { return *this; }
|
inline RsNoDbg& operator<<(const T&) { return *this; }
|
||||||
|
|
||||||
/// needed for manipulators and things like std::endl
|
/// needed for manipulators and things like std::endl
|
||||||
inline stream_type& operator<<(std::ostream& (*/*pf*/)(std::ostream&))
|
inline RsNoDbg& operator<<(std::ostream& (*/*pf*/)(std::ostream&))
|
||||||
{ return *this; }
|
{ return *this; }
|
||||||
|
|
||||||
/** Return the object itself just for code compatibility with other
|
/** Do nothing. Just for code compatibility with other logging classes */
|
||||||
* logging classes */
|
inline void flush() {}
|
||||||
inline stream_type& uStream() { return *this; }
|
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
////////////////////////////////////////////////////////////////////////////////
|
||||||
|
////////////////////////////////////////////////////////////////////////////////
|
||||||
|
////////////////////////////////////////////////////////////////////////////////
|
||||||
|
////////////////////////////////////////////////////////////////////////////////
|
||||||
|
/// All the following lines are DEPRECATED!!
|
||||||
|
|
||||||
|
#include "util/rsdeprecate.h"
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Concatenate preprocessor tokens A and B without expanding macro definitions
|
* Concatenate preprocessor tokens A and B without expanding macro definitions
|
||||||
* (however, if invoked from a macro, macro arguments are expanded).
|
* (however, if invoked from a macro, macro arguments are expanded).
|
||||||
@ -267,41 +223,30 @@ struct RsNoDbg
|
|||||||
|
|
||||||
// A bunch of boilerplate, but just in one place
|
// A bunch of boilerplate, but just in one place
|
||||||
#define RS_SET_CONTEXT_DEBUG_LEVEL0 \
|
#define RS_SET_CONTEXT_DEBUG_LEVEL0 \
|
||||||
using Dbg1 = RsNoDbg; \
|
using Dbg1 RS_DEPRECATED_FOR(RS_DBG1) = RsNoDbg; \
|
||||||
using Dbg2 = RsNoDbg; \
|
using Dbg2 RS_DEPRECATED_FOR(RS_DBG2) = RsNoDbg; \
|
||||||
using Dbg3 = RsNoDbg; \
|
using Dbg3 RS_DEPRECATED_FOR(RS_DBG3) = RsNoDbg; \
|
||||||
using Dbg4 = RsNoDbg;
|
using Dbg4 RS_DEPRECATED_FOR(RS_DBG4) = RsNoDbg;
|
||||||
#define RS_SET_CONTEXT_DEBUG_LEVEL1 \
|
#define RS_SET_CONTEXT_DEBUG_LEVEL1 \
|
||||||
using Dbg1 = RsDbg; \
|
using Dbg1 RS_DEPRECATED_FOR(RS_DBG1) = RsDbg; \
|
||||||
using Dbg2 = RsNoDbg; \
|
using Dbg2 RS_DEPRECATED_FOR(RS_DBG2) = RsNoDbg; \
|
||||||
using Dbg3 = RsNoDbg; \
|
using Dbg3 RS_DEPRECATED_FOR(RS_DBG3) = RsNoDbg; \
|
||||||
using Dbg4 = RsNoDbg;
|
using Dbg4 RS_DEPRECATED_FOR(RS_DBG4) = RsNoDbg;
|
||||||
#define RS_SET_CONTEXT_DEBUG_LEVEL2 \
|
#define RS_SET_CONTEXT_DEBUG_LEVEL2 \
|
||||||
using Dbg1 = RsDbg; \
|
using Dbg1 RS_DEPRECATED_FOR(RS_DBG1) = RsDbg; \
|
||||||
using Dbg2 = RsDbg; \
|
using Dbg2 RS_DEPRECATED_FOR(RS_DBG2) = RsDbg; \
|
||||||
using Dbg3 = RsNoDbg; \
|
using Dbg3 RS_DEPRECATED_FOR(RS_DBG3) = RsNoDbg; \
|
||||||
using Dbg4 = RsNoDbg;
|
using Dbg4 RS_DEPRECATED_FOR(RS_DBG4) = RsNoDbg;
|
||||||
#define RS_SET_CONTEXT_DEBUG_LEVEL3 \
|
#define RS_SET_CONTEXT_DEBUG_LEVEL3 \
|
||||||
using Dbg1 = RsDbg; \
|
using Dbg1 RS_DEPRECATED_FOR(RS_DBG1) = RsDbg; \
|
||||||
using Dbg2 = RsDbg; \
|
using Dbg2 RS_DEPRECATED_FOR(RS_DBG2) = RsDbg; \
|
||||||
using Dbg3 = RsDbg; \
|
using Dbg3 RS_DEPRECATED_FOR(RS_DBG3) = RsDbg; \
|
||||||
using Dbg4 = RsNoDbg;
|
using Dbg4 RS_DEPRECATED_FOR(RS_DBG4) = RsNoDbg;
|
||||||
#define RS_SET_CONTEXT_DEBUG_LEVEL4 \
|
#define RS_SET_CONTEXT_DEBUG_LEVEL4 \
|
||||||
using Dbg1 = RsDbg; \
|
using Dbg1 RS_DEPRECATED_FOR(RS_DBG1) = RsDbg; \
|
||||||
using Dbg2 = RsDbg; \
|
using Dbg2 RS_DEPRECATED_FOR(RS_DBG2) = RsDbg; \
|
||||||
using Dbg3 = RsDbg; \
|
using Dbg3 RS_DEPRECATED_FOR(RS_DBG3) = RsDbg; \
|
||||||
using Dbg4 = RsDbg;
|
using Dbg4 RS_DEPRECATED_FOR(RS_DBG4) = RsDbg;
|
||||||
|
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////////////////////////
|
|
||||||
////////////////////////////////////////////////////////////////////////////////
|
|
||||||
////////////////////////////////////////////////////////////////////////////////
|
|
||||||
////////////////////////////////////////////////////////////////////////////////
|
|
||||||
/// All the following lines are DEPRECATED!!
|
|
||||||
|
|
||||||
#include <string>
|
|
||||||
|
|
||||||
#include "util/rsdeprecate.h"
|
|
||||||
|
|
||||||
namespace RsLog {
|
namespace RsLog {
|
||||||
enum RS_DEPRECATED_FOR("RsErr, RsDbg, RsNoDbg") logLvl {
|
enum RS_DEPRECATED_FOR("RsErr, RsDbg, RsNoDbg") logLvl {
|
||||||
|
42
libretroshare/src/util/rsdebuglevel0.h
Normal file
42
libretroshare/src/util/rsdebuglevel0.h
Normal file
@ -0,0 +1,42 @@
|
|||||||
|
/*******************************************************************************
|
||||||
|
* RetroShare debugging level *
|
||||||
|
* *
|
||||||
|
* Copyright (C) 2020 Gioacchino Mazzurco <gio@eigenlab.org> *
|
||||||
|
* Copyright (C) 2020 Asociación Civil Altermundi <info@altermundi.net> *
|
||||||
|
* *
|
||||||
|
* This program is free software: you can redistribute it and/or modify *
|
||||||
|
* it under the terms of the GNU Lesser General Public License as *
|
||||||
|
* published by the Free Software Foundation, either version 3 of the *
|
||||||
|
* License, or (at your option) any later version. *
|
||||||
|
* *
|
||||||
|
* This program is distributed in the hope that it will be useful, *
|
||||||
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
|
||||||
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
|
||||||
|
* GNU Lesser General Public License for more details. *
|
||||||
|
* *
|
||||||
|
* You should have received a copy of the GNU Lesser General Public License *
|
||||||
|
* along with this program. If not, see <https://www.gnu.org/licenses/>. *
|
||||||
|
* *
|
||||||
|
*******************************************************************************/
|
||||||
|
|
||||||
|
// #pragma once // This is commented out on purpose!
|
||||||
|
|
||||||
|
#include <util/rsdebug.h>
|
||||||
|
|
||||||
|
#undef RS_DEBUG_LEVEL
|
||||||
|
#define RS_DEBUG_LEVEL 0
|
||||||
|
|
||||||
|
#undef RS_DBG0
|
||||||
|
#define RS_DBG0(...) RsDbg(__PRETTY_FUNCTION__, " ", __VA_ARGS__)
|
||||||
|
|
||||||
|
#undef RS_DBG1
|
||||||
|
#define RS_DBG1(...) RsNoDbg("")
|
||||||
|
|
||||||
|
#undef RS_DBG2
|
||||||
|
#define RS_DBG2(...) RsNoDbg("")
|
||||||
|
|
||||||
|
#undef RS_DBG3
|
||||||
|
#define RS_DBG3(...) RsNoDbg("")
|
||||||
|
|
||||||
|
#undef RS_DBG4
|
||||||
|
#define RS_DBG4(...) RsNoDbg("")
|
42
libretroshare/src/util/rsdebuglevel1.h
Normal file
42
libretroshare/src/util/rsdebuglevel1.h
Normal file
@ -0,0 +1,42 @@
|
|||||||
|
/*******************************************************************************
|
||||||
|
* RetroShare debugging level *
|
||||||
|
* *
|
||||||
|
* Copyright (C) 2020 Gioacchino Mazzurco <gio@eigenlab.org> *
|
||||||
|
* Copyright (C) 2020 Asociación Civil Altermundi <info@altermundi.net> *
|
||||||
|
* *
|
||||||
|
* This program is free software: you can redistribute it and/or modify *
|
||||||
|
* it under the terms of the GNU Lesser General Public License as *
|
||||||
|
* published by the Free Software Foundation, either version 3 of the *
|
||||||
|
* License, or (at your option) any later version. *
|
||||||
|
* *
|
||||||
|
* This program is distributed in the hope that it will be useful, *
|
||||||
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
|
||||||
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
|
||||||
|
* GNU Lesser General Public License for more details. *
|
||||||
|
* *
|
||||||
|
* You should have received a copy of the GNU Lesser General Public License *
|
||||||
|
* along with this program. If not, see <https://www.gnu.org/licenses/>. *
|
||||||
|
* *
|
||||||
|
*******************************************************************************/
|
||||||
|
|
||||||
|
// #pragma once // This is commented out on purpose!
|
||||||
|
|
||||||
|
#include <util/rsdebug.h>
|
||||||
|
|
||||||
|
#undef RS_DEBUG_LEVEL
|
||||||
|
#define RS_DEBUG_LEVEL 1
|
||||||
|
|
||||||
|
#undef RS_DBG0
|
||||||
|
#define RS_DBG0(...) RsDbg(__PRETTY_FUNCTION__, " ", __VA_ARGS__)
|
||||||
|
|
||||||
|
#undef RS_DBG1
|
||||||
|
#define RS_DBG1(...) RsDbg(__PRETTY_FUNCTION__, " ", __VA_ARGS__)
|
||||||
|
|
||||||
|
#undef RS_DBG2
|
||||||
|
#define RS_DBG2(...) RsNoDbg()
|
||||||
|
|
||||||
|
#undef RS_DBG3
|
||||||
|
#define RS_DBG3(...) RsNoDbg()
|
||||||
|
|
||||||
|
#undef RS_DBG4
|
||||||
|
#define RS_DBG4(...) RsNoDbg()
|
42
libretroshare/src/util/rsdebuglevel2.h
Normal file
42
libretroshare/src/util/rsdebuglevel2.h
Normal file
@ -0,0 +1,42 @@
|
|||||||
|
/*******************************************************************************
|
||||||
|
* RetroShare debugging level *
|
||||||
|
* *
|
||||||
|
* Copyright (C) 2020 Gioacchino Mazzurco <gio@eigenlab.org> *
|
||||||
|
* Copyright (C) 2020 Asociación Civil Altermundi <info@altermundi.net> *
|
||||||
|
* *
|
||||||
|
* This program is free software: you can redistribute it and/or modify *
|
||||||
|
* it under the terms of the GNU Lesser General Public License as *
|
||||||
|
* published by the Free Software Foundation, either version 3 of the *
|
||||||
|
* License, or (at your option) any later version. *
|
||||||
|
* *
|
||||||
|
* This program is distributed in the hope that it will be useful, *
|
||||||
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
|
||||||
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
|
||||||
|
* GNU Lesser General Public License for more details. *
|
||||||
|
* *
|
||||||
|
* You should have received a copy of the GNU Lesser General Public License *
|
||||||
|
* along with this program. If not, see <https://www.gnu.org/licenses/>. *
|
||||||
|
* *
|
||||||
|
*******************************************************************************/
|
||||||
|
|
||||||
|
// #pragma once // This is commented out on purpose!
|
||||||
|
|
||||||
|
#include <util/rsdebug.h>
|
||||||
|
|
||||||
|
#undef RS_DEBUG_LEVEL
|
||||||
|
#define RS_DEBUG_LEVEL 2
|
||||||
|
|
||||||
|
#undef RS_DBG0
|
||||||
|
#define RS_DBG0(...) RsDbg(__PRETTY_FUNCTION__, " ", __VA_ARGS__)
|
||||||
|
|
||||||
|
#undef RS_DBG1
|
||||||
|
#define RS_DBG1(...) RsDbg(__PRETTY_FUNCTION__, " ", __VA_ARGS__)
|
||||||
|
|
||||||
|
#undef RS_DBG2
|
||||||
|
#define RS_DBG2(...) RsDbg(__PRETTY_FUNCTION__, " ", __VA_ARGS__)
|
||||||
|
|
||||||
|
#undef RS_DBG3
|
||||||
|
#define RS_DBG3(...) RsNoDbg()
|
||||||
|
|
||||||
|
#undef RS_DBG4
|
||||||
|
#define RS_DBG4(...) RsNoDbg()
|
42
libretroshare/src/util/rsdebuglevel3.h
Normal file
42
libretroshare/src/util/rsdebuglevel3.h
Normal file
@ -0,0 +1,42 @@
|
|||||||
|
/*******************************************************************************
|
||||||
|
* RetroShare debugging level *
|
||||||
|
* *
|
||||||
|
* Copyright (C) 2020 Gioacchino Mazzurco <gio@eigenlab.org> *
|
||||||
|
* Copyright (C) 2020 Asociación Civil Altermundi <info@altermundi.net> *
|
||||||
|
* *
|
||||||
|
* This program is free software: you can redistribute it and/or modify *
|
||||||
|
* it under the terms of the GNU Lesser General Public License as *
|
||||||
|
* published by the Free Software Foundation, either version 3 of the *
|
||||||
|
* License, or (at your option) any later version. *
|
||||||
|
* *
|
||||||
|
* This program is distributed in the hope that it will be useful, *
|
||||||
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
|
||||||
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
|
||||||
|
* GNU Lesser General Public License for more details. *
|
||||||
|
* *
|
||||||
|
* You should have received a copy of the GNU Lesser General Public License *
|
||||||
|
* along with this program. If not, see <https://www.gnu.org/licenses/>. *
|
||||||
|
* *
|
||||||
|
*******************************************************************************/
|
||||||
|
|
||||||
|
// #pragma once // This is commented out on purpose!
|
||||||
|
|
||||||
|
#include <util/rsdebug.h>
|
||||||
|
|
||||||
|
#undef RS_DEBUG_LEVEL
|
||||||
|
#define RS_DEBUG_LEVEL 3
|
||||||
|
|
||||||
|
#undef RS_DBG0
|
||||||
|
#define RS_DBG0(...) RsDbg(__PRETTY_FUNCTION__, " ", __VA_ARGS__)
|
||||||
|
|
||||||
|
#undef RS_DBG1
|
||||||
|
#define RS_DBG1(...) RsDbg(__PRETTY_FUNCTION__, " ", __VA_ARGS__)
|
||||||
|
|
||||||
|
#undef RS_DBG2
|
||||||
|
#define RS_DBG2(...) RsDbg(__PRETTY_FUNCTION__, " ", __VA_ARGS__)
|
||||||
|
|
||||||
|
#undef RS_DBG3
|
||||||
|
#define RS_DBG3(...) RsDbg(__PRETTY_FUNCTION__, " ", __VA_ARGS__)
|
||||||
|
|
||||||
|
#undef RS_DBG4
|
||||||
|
#define RS_DBG4(...) RsNoDbg()
|
42
libretroshare/src/util/rsdebuglevel4.h
Normal file
42
libretroshare/src/util/rsdebuglevel4.h
Normal file
@ -0,0 +1,42 @@
|
|||||||
|
/*******************************************************************************
|
||||||
|
* RetroShare debugging level *
|
||||||
|
* *
|
||||||
|
* Copyright (C) 2020 Gioacchino Mazzurco <gio@eigenlab.org> *
|
||||||
|
* Copyright (C) 2020 Asociación Civil Altermundi <info@altermundi.net> *
|
||||||
|
* *
|
||||||
|
* This program is free software: you can redistribute it and/or modify *
|
||||||
|
* it under the terms of the GNU Lesser General Public License as *
|
||||||
|
* published by the Free Software Foundation, either version 3 of the *
|
||||||
|
* License, or (at your option) any later version. *
|
||||||
|
* *
|
||||||
|
* This program is distributed in the hope that it will be useful, *
|
||||||
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
|
||||||
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
|
||||||
|
* GNU Lesser General Public License for more details. *
|
||||||
|
* *
|
||||||
|
* You should have received a copy of the GNU Lesser General Public License *
|
||||||
|
* along with this program. If not, see <https://www.gnu.org/licenses/>. *
|
||||||
|
* *
|
||||||
|
*******************************************************************************/
|
||||||
|
|
||||||
|
// #pragma once // This is commented out on purpose!
|
||||||
|
|
||||||
|
#include <util/rsdebug.h>
|
||||||
|
|
||||||
|
#undef RS_DEBUG_LEVEL
|
||||||
|
#define RS_DEBUG_LEVEL 4
|
||||||
|
|
||||||
|
#undef RS_DBG0
|
||||||
|
#define RS_DBG0(...) RsDbg(__PRETTY_FUNCTION__, " ", __VA_ARGS__)
|
||||||
|
|
||||||
|
#undef RS_DBG1
|
||||||
|
#define RS_DBG1(...) RsDbg(__PRETTY_FUNCTION__, " ", __VA_ARGS__)
|
||||||
|
|
||||||
|
#undef RS_DBG2
|
||||||
|
#define RS_DBG2(...) RsDbg(__PRETTY_FUNCTION__, " ", __VA_ARGS__)
|
||||||
|
|
||||||
|
#undef RS_DBG3
|
||||||
|
#define RS_DBG3(...) RsDbg(__PRETTY_FUNCTION__, " ", __VA_ARGS__)
|
||||||
|
|
||||||
|
#undef RS_DBG4
|
||||||
|
#define RS_DBG4(...) RsDbg(__PRETTY_FUNCTION__, " ", __VA_ARGS__)
|
Loading…
Reference in New Issue
Block a user