|
|
@ -17,16 +17,13 @@ |
|
|
|
#include <chrono> |
|
|
|
#include <chrono> |
|
|
|
#include <memory> |
|
|
|
#include <memory> |
|
|
|
#include <thread> |
|
|
|
#include <thread> |
|
|
|
|
|
|
|
#include <functional> |
|
|
|
#include "Queue.h" |
|
|
|
#include "Queue.h" |
|
|
|
|
|
|
|
|
|
|
|
#ifndef _WIN32 |
|
|
|
#ifndef _WIN32 |
|
|
|
#include <syslog.h> |
|
|
|
#include <syslog.h> |
|
|
|
#endif |
|
|
|
#endif |
|
|
|
|
|
|
|
|
|
|
|
#ifdef WIN32_APP |
|
|
|
|
|
|
|
#include <windows.h> // TODO: move away to win32app |
|
|
|
|
|
|
|
#endif |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
enum LogLevel |
|
|
|
enum LogLevel |
|
|
|
{ |
|
|
|
{ |
|
|
|
eLogNone = 0, |
|
|
|
eLogNone = 0, |
|
|
@ -155,6 +152,10 @@ namespace log { |
|
|
|
}; |
|
|
|
}; |
|
|
|
|
|
|
|
|
|
|
|
Log & Logger(); |
|
|
|
Log & Logger(); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
typedef std::function<void (const std::string&)> ThrowFunction; |
|
|
|
|
|
|
|
ThrowFunction GetThrowFunction (); |
|
|
|
|
|
|
|
void SetThrowFunction (ThrowFunction f); |
|
|
|
} // log
|
|
|
|
} // log
|
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
@ -201,7 +202,6 @@ void LogPrint (LogLevel level, TArgs&&... args) noexcept |
|
|
|
log.Append(msg); |
|
|
|
log.Append(msg); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
/**
|
|
|
|
* @brief Throw fatal error message with the list of arguments |
|
|
|
* @brief Throw fatal error message with the list of arguments |
|
|
|
* @param args Array of message parts |
|
|
|
* @param args Array of message parts |
|
|
@ -209,6 +209,8 @@ void LogPrint (LogLevel level, TArgs&&... args) noexcept |
|
|
|
template<typename... TArgs> |
|
|
|
template<typename... TArgs> |
|
|
|
void ThrowFatal (TArgs&&... args) noexcept |
|
|
|
void ThrowFatal (TArgs&&... args) noexcept |
|
|
|
{ |
|
|
|
{ |
|
|
|
|
|
|
|
auto f = i2p::log::GetThrowFunction (); |
|
|
|
|
|
|
|
if (!f) return; |
|
|
|
// fold message to single string
|
|
|
|
// fold message to single string
|
|
|
|
std::stringstream ss(""); |
|
|
|
std::stringstream ss(""); |
|
|
|
#if (__cplusplus >= 201703L) // C++ 17 or higher
|
|
|
|
#if (__cplusplus >= 201703L) // C++ 17 or higher
|
|
|
@ -216,12 +218,7 @@ void ThrowFatal (TArgs&&... args) noexcept |
|
|
|
#else |
|
|
|
#else |
|
|
|
LogPrint (ss, std::forward<TArgs>(args)...); |
|
|
|
LogPrint (ss, std::forward<TArgs>(args)...); |
|
|
|
#endif |
|
|
|
#endif |
|
|
|
|
|
|
|
f (ss.str ()); |
|
|
|
#ifdef WIN32_APP |
|
|
|
|
|
|
|
MessageBox(0, TEXT(ss.str ().c_str ()), TEXT("i2pd"), MB_ICONERROR | MB_TASKMODAL | MB_OK ); |
|
|
|
|
|
|
|
#else |
|
|
|
|
|
|
|
std::cout << ss.str (); |
|
|
|
|
|
|
|
#endif |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
#endif // LOG_H__
|
|
|
|
#endif // LOG_H__
|
|
|
|