added: to Log:
void LogBinary(const char * blob, size_t blob_len); void LogBinary(const std::string & blob); int LogLevel(); git-svn-id: svn://ttmath.org/publicrep/winix/trunk@866 e52654a7-88a9-db11-a3e9-0013d4bc506e
This commit is contained in:
parent
1ec61ffa11
commit
1c2589a2f2
80
core/log.cpp
80
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<blob_len ; ++a, ++i)
|
||||
{
|
||||
if( blob[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;
|
||||
|
|
|
@ -54,10 +54,17 @@ public:
|
|||
template<class StringType>
|
||||
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);
|
||||
|
||||
};
|
||||
|
||||
|
|
Loading…
Reference in New Issue