summaryrefslogtreecommitdiff
path: root/lib/common
diff options
context:
space:
mode:
Diffstat (limited to 'lib/common')
-rw-r--r--lib/common/Logging.cpp21
-rw-r--r--lib/common/Logging.h27
2 files changed, 34 insertions, 14 deletions
diff --git a/lib/common/Logging.cpp b/lib/common/Logging.cpp
index 681e1352..296443ea 100644
--- a/lib/common/Logging.cpp
+++ b/lib/common/Logging.cpp
@@ -495,3 +495,24 @@ bool FileLogger::Log(Log::Level Level, const std::string& rFile,
Logging::Add(this);
return true;
}
+
+std::string PrintEscapedBinaryData(const std::string& rInput)
+{
+ std::ostringstream output;
+
+ for (size_t i = 0; i < rInput.length(); i++)
+ {
+ if (isprint(rInput[i]))
+ {
+ output << rInput[i];
+ }
+ else
+ {
+ output << "\\x" << std::hex << std::setw(2) <<
+ std::setfill('0') << (int) rInput[i] <<
+ std::dec;
+ }
+ }
+
+ return output.str();
+}
diff --git a/lib/common/Logging.h b/lib/common/Logging.h
index 35e14d83..24863d2c 100644
--- a/lib/common/Logging.h
+++ b/lib/common/Logging.h
@@ -18,17 +18,6 @@
#include "FileStream.h"
-/*
-#define BOX_LOG(level, stuff) \
-{ \
- if(Log::sMaxLoggingLevelForAnyOutput >= level) \
- std::ostringstream line; \
- line << stuff; \
- Log::Write(level, __FILE__, __LINE__, line.str()); \
- } \
-}
-*/
-
#define BOX_LOG(level, stuff) \
{ \
std::ostringstream _box_log_line; \
@@ -52,12 +41,20 @@
if (Logging::IsEnabled(Log::TRACE)) \
{ BOX_LOG(Log::TRACE, stuff) }
+#define BOX_SYS_ERROR(stuff) \
+ stuff << ": " << std::strerror(errno) << " (" << errno << ")"
+
#define BOX_LOG_SYS_WARNING(stuff) \
- BOX_WARNING(stuff << ": " << std::strerror(errno) << " (" << errno << ")")
+ BOX_WARNING(BOX_SYS_ERROR(stuff))
#define BOX_LOG_SYS_ERROR(stuff) \
- BOX_ERROR(stuff << ": " << std::strerror(errno) << " (" << errno << ")")
+ BOX_ERROR(BOX_SYS_ERROR(stuff))
#define BOX_LOG_SYS_FATAL(stuff) \
- BOX_FATAL(stuff << ": " << std::strerror(errno) << " (" << errno << ")")
+ BOX_FATAL(BOX_SYS_ERROR(stuff))
+
+#define LOG_AND_THROW_ERROR(message, filename, exception, subtype) \
+ BOX_LOG_SYS_ERROR(message << ": " << filename); \
+ THROW_EXCEPTION_MESSAGE(exception, subtype, \
+ BOX_SYS_ERROR(message << ": " << filename));
inline std::string GetNativeErrorMessage()
{
@@ -339,4 +336,6 @@ class HideExceptionMessageGuard
bool mOldHiddenState;
};
+std::string PrintEscapedBinaryData(const std::string& rInput);
+
#endif // LOGGING__H