diff --git a/core/log.cpp b/core/log.cpp index e0b6548..ac889c4 100755 --- a/core/log.cpp +++ b/core/log.cpp @@ -31,6 +31,13 @@ Log::~Log() } +int Log::LogLevel() +{ + return log_level; +} + + + void Log::Init(int log_level_, bool save_each_line_, const std::string & log_file_, bool log_std, int log_max_requests) { log_level = log_level_; @@ -289,6 +296,79 @@ return *this; + +char Log::GetHEXdigit(unsigned char c) +{ + if( c < 10 ) + return c + '0'; + +return c - 10 + 'A'; +} + + + +void Log::ToHEX(char * buf, unsigned char c) +{ + buf[0] = GetHEXdigit(c >> 4); + buf[1] = GetHEXdigit(c & 0xf); + buf[2] = 0; +} + + +void Log::LogBinary(const char * blob, size_t blob_len) +{ +size_t i=0; +char buf[3]; + + + while( i < blob_len ) + { + size_t oldi = i; + + for(size_t a=0 ; a<16 ; ++a) + { + if( i < blob_len ) + { + ToHEX(buf, blob[i]); + buffer << buf << ' '; + ++i; + } + else + { + buffer << " "; + } + + if( a == 7 ) + { + if( i < blob_len ) + buffer << "- "; + else + buffer << " "; + } + } + + i = oldi; + buffer << ' '; + + for(size_t a=0 ; a<16 && i 31 && blob[i] < 127 ) + buffer << blob[i]; + else + buffer << '.'; + } + + (*this) << logend; + } +} + + +void Log::LogBinary(const std::string & blob) +{ + LogBinary(blob.c_str(), blob.size()); +} + + void Log::SystemErr(int err) { (*this) << "errno: " << err; diff --git a/core/log.h b/core/log.h index 223dd94..5d0cadd 100755 --- a/core/log.h +++ b/core/log.h @@ -54,10 +54,17 @@ public: template void LogString(const StringType & value, size_t max_size); + void LogBinary(const char * blob, size_t blob_len); + void LogBinary(const std::string & blob); + + void SystemErr(int err); void SaveLog(); void SaveLogAndClear(); + int LogLevel(); + + private: // buffer for the log @@ -97,6 +104,8 @@ private: bool save_each_line; void OpenFile(); + char GetHEXdigit(unsigned char c); + void ToHEX(char * buf, unsigned char c); };