Skip to content

Commit

Permalink
clean code. binary print support print visible character.
Browse files Browse the repository at this point in the history
  • Loading branch information
zsummer committed Jun 30, 2016
1 parent 4ce1e0f commit 5b4b56d
Show file tree
Hide file tree
Showing 3 changed files with 40 additions and 12 deletions.
5 changes: 2 additions & 3 deletions log4z.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -404,7 +404,6 @@ class LogerManager : public ThreadHelper, public ILog4zManager
SemHelper _semaphore;

//! hot change name or path for one logger
LockHelper _hotLock;
int _hotUpdateInterval;
unsigned int _checksum;

Expand Down Expand Up @@ -1693,10 +1692,10 @@ bool LogerManager::openLogger(LogData * pLog)
tm t = timeToTm(pLogger->_curFileCreateTime);
std::string name;
std::string path;
_hotLock.lock();

name = pLogger->_name;
path = pLogger->_path;
_hotLock.unLock();


char buf[100] = { 0 };
if (pLogger->_monthdir)
Expand Down
31 changes: 23 additions & 8 deletions log4z.h
Original file line number Diff line number Diff line change
Expand Up @@ -479,9 +479,9 @@ _ZSUMMER_LOG4Z_BEGIN
class Log4zBinary
{
public:
Log4zBinary(const char * buf, int len)
Log4zBinary(const void * buf, int len)
{
_buf = buf;
_buf = (const char *)buf;
_len = len;
}
const char * _buf;
Expand Down Expand Up @@ -728,16 +728,31 @@ inline Log4zStream & Log4zStream::writePointer(const void * t)
inline Log4zStream & Log4zStream::writeBinary(const Log4zBinary & t)
{
writeData("%s", "\r\n\t[");
for (int i = 0; i < t._len; i++)
for (int i=0; i<(t._len / 16)+1; i++)
{
if (i % 16 == 0)
writeData("%s", "\r\n\t");
*this << (void*)(t._buf + i*16);
writeData("%s", ": ");
for (int j=i*16; j < (i+1)*16 && j < t._len; j++)
{
writeData("%s", "\r\n\t");
*this << (void*)(t._buf + i);
writeData("%s", ": ");
writeData("%02x ", (unsigned char)t._buf[j]);
}
writeData("%s", "\r\n\t");
*this << (void*)(t._buf + i*16);
writeData("%s", ": ");
for (int j = i * 16; j < (i + 1) * 16 && j < t._len; j++)
{
if (isprint((unsigned char)t._buf[j]))
{
writeData(" %c ", t._buf[j]);
}
else
{
*this << " . ";
}
}
writeData("%02x ", (unsigned char)t._buf[i]);
}

writeData("%s", "\r\n\t]\r\n\t");
return *this;
}
Expand Down
16 changes: 15 additions & 1 deletion test/fast_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
#include <iostream>
#include <stdio.h>
#include <stdarg.h>
#include <time.h>
using namespace zsummer::log4z;

#ifdef WIN32
Expand Down Expand Up @@ -49,8 +50,21 @@ int main(int argc, char *argv[])
<< ", constant:" << 100.12345678
<< ", bool:" << true
<< ", show hex data:" << Log4zBinary("1234567890abcdefghigklmnopqrstuvwxyz_zyw_zsummer_log4z", 50)
);
);

if (true)
{
LogData ld;
ld._id = 0;
ld._type = 2;
ld._typeval = 0;
ld._level = LOG_LEVEL_DEBUG;
ld._time = time(NULL);
ld._precise = 0;
ld._contentLen = 7;
strcpy(ld._content, "newname");
LOGD(Log4zBinary(&ld, sizeof(ld) - LOG4Z_LOG_BUF_SIZE + ld._contentLen));
}
//test stl
if (true)
{
Expand Down

0 comments on commit 5b4b56d

Please sign in to comment.