30 #ifdef XERUS_LOG_BUFFER 37 namespace xerus {
namespace misc {
namespace internal {
43 programStartTime = std::chrono::system_clock::now();
47 #ifdef XERUS_LOG_ABSOLUTE_TIME 49 std::time_t xerus_err_t=std::chrono::system_clock::to_time_t(std::chrono::system_clock::now());
50 std::tm *xerus_err_ltm=std::localtime(&xerus_err_t);
51 _out << std::right << (1900+xerus_err_ltm->tm_year)
52 <<
'-' << std::setw(2) << std::setfill(
'0') << (xerus_err_ltm->tm_mon +1)
53 <<
'-' << std::setw(2) << std::setfill(
'0') << xerus_err_ltm->tm_mday
54 <<
' ' << std::setw(2) << std::setfill(
'0') << xerus_err_ltm->tm_hour
55 <<
':' << std::setw(2) << std::setfill(
'0') << xerus_err_ltm->tm_min
56 <<
':' << std::setw(2) << std::setfill(
'0') << xerus_err_ltm->tm_sec <<
' ' << std::left;
58 std::chrono::system_clock::time_point xerus_err_t = std::chrono::system_clock::now();
60 _out << std::right <<
'+' << std::setw(2) << std::setfill(
'0') << (xerus_err_timediff/3600000)
61 <<
':' << std::setw(2) << std::setfill(
'0') << ((xerus_err_timediff/60000)%60)
62 <<
':' << std::setw(2) << std::setfill(
'0') << ((xerus_err_timediff/1000)%60)
63 <<
',' << std::setw(3) << std::setfill(
'0') << (xerus_err_timediff%1000) <<
' ' << std::left;
67 void log_timestamp(std::ostream &_out,
const char* _file,
int _line,
const char* _lvl) {
69 _out << std::setfill(
' ') << std::setw(20) << std::left <<
xerus::misc::explode(_file,
'/').back() <<
':' \
70 << std::right << std::setfill(
' ') << std::setw(4) <<_line <<
" : " \
71 << std::setfill(
' ') << std::setw(12) << std::left \
72 << std::string(_lvl) <<
": ";
77 _out << std::setfill(
' ') << std::setw(12) << std::left \
78 << std::string(_lvl) <<
": ";
82 static std::ofstream fileStream;
83 if (!fileStream || !fileStream.is_open()) {
85 fileStream.open(
"error.log", std::ofstream::app | std::ofstream::out);
92 std::stringstream
old;
95 if (current.str().size() > 1024*1024) {
96 #if defined(__GNUC__) && __GNUC__ < 5 97 old.str(current.str());
98 current.str(std::string());
101 old = std::move(current);
102 current = std::stringstream();
108 std::string name = std::string(
"errors/") + logFilePrefix +
std::to_string(std::time(
nullptr)) +
".txt";
109 std::ofstream out(name, std::ofstream::out);
110 out <<
"Error: " << _comment << std::endl << std::endl;
113 out <<
"-------------------------------------------------------------------------------" << std::endl
114 <<
" Callstack : " << std::endl
115 <<
"-------------------------------------------------------------------------------" << std::endl
121 out <<
"-------------------------------------------------------------------------------" << std::endl
122 <<
" last " << (current.str().size() + old.str().size()) <<
" bytes of log:" << std::endl
123 <<
"-------------------------------------------------------------------------------" << std::endl
124 << old.str() << current.str() <<
"horst" << std::endl;
std::string logFilePrefix
void dump_log(std::string _comment)
std::ostream & get_fileStream()
The main namespace of xerus.
std::string get_call_stack()
Returns a string representation of the current call-stack (excluding the function itself)...
static void __attribute__((constructor)) initTime()
Header file for all logging macros and log-buffer functionality.
std::mutex namedLoggerMutex
Header file for some elementary string manipulation routines.
std::stringstream current
static XERUS_force_inline std::string to_string(const bool obj)
void log_timestamp(std::ostream &_out, const char *_file, int _line, const char *_lvl)
std::chrono::system_clock::time_point programStartTime
std::vector< std::string > explode(const std::string &_string, const char _delim)
: Explodes a string at positions indicated by _delim.