aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMike Buland <eichlan@xagasoft.com>2007-07-09 19:25:42 +0000
committerMike Buland <eichlan@xagasoft.com>2007-07-09 19:25:42 +0000
commitb4da565534b3826037576a6c44e40716b024f89a (patch)
treed04b7d3a6240dea2471f1d08fbdaf91dad651f58
parent62a1a445ab61fe31367054c094b7e0bb0495833d (diff)
downloadlibbu++-b4da565534b3826037576a6c44e40716b024f89a.tar.gz
libbu++-b4da565534b3826037576a6c44e40716b024f89a.tar.bz2
libbu++-b4da565534b3826037576a6c44e40716b024f89a.tar.xz
libbu++-b4da565534b3826037576a6c44e40716b024f89a.zip
The new logHexDump function seems to work just fine.
-rw-r--r--src/logger.cpp44
-rw-r--r--src/logger.h5
-rw-r--r--src/tests/logger.cpp2
3 files changed, 51 insertions, 0 deletions
diff --git a/src/logger.cpp b/src/logger.cpp
index 34b5d78..1e0313b 100644
--- a/src/logger.cpp
+++ b/src/logger.cpp
@@ -129,3 +129,47 @@ void Bu::Logger::setLevel( int n )
129 } 129 }
130} 130}
131 131
132void Bu::Logger::hexDump( int nLevel, const char *sFile, const char *sFunction,
133 int nLine, const void *pDataV, long nDataLen,
134 const char *lpName )
135{
136 log( nLevel, sFile, sFunction, nLine, "Displaying %ld bytes of %s.\n", nDataLen, lpName );
137 const unsigned char *pData = (const unsigned char *)pDataV;
138 int j = 0;
139 Bu::FString sBorder;
140 for( int l = 0; l < 8*3+2*8+2; l++ ) sBorder += ((l!=8*3)?("-"):("+"));
141 sBorder += '\n';
142 log( nLevel, sFile, sFunction, nLine, sBorder.getStr() );
143 Bu::FString sLine;
144 for(;;)
145 {
146 int kmax = 8;
147 if( nDataLen-j < 8 ) kmax = nDataLen-j;
148 for(int k = 0; k < 8; k++ )
149 {
150 if( k < kmax )
151 {
152 char buf[4];
153 sprintf( buf, "%02X ", (int)((unsigned char)pData[j+k]) );
154 sLine += buf;
155 }
156 else
157 {
158 sLine += "-- ";
159 }
160 }
161 sLine += "| ";
162 for(int k = 0; k < kmax; k++ )
163 {
164 char buf[3];
165 sprintf( buf, "%c ", (pData[j+k]>32 && pData[j+k]<=128)?(pData[j+k]):('.') );
166 sLine += buf;
167 }
168 sLine += '\n';
169 log( nLevel, sFile, sFunction, nLine, sLine.getStr() );
170 sLine = "";
171 j += kmax;
172 if( j >= nDataLen ) break;
173 }
174 log( nLevel, sFile, sFunction, nLine, sBorder.getStr() );
175}
diff --git a/src/logger.h b/src/logger.h
index f8e1692..f561e88 100644
--- a/src/logger.h
+++ b/src/logger.h
@@ -75,6 +75,8 @@ namespace Bu
75 void setMask( int n ); 75 void setMask( int n );
76 void setLevel( int n ); 76 void setLevel( int n );
77 77
78 void hexDump( int nLevel, const char *sFile, const char *sFunction, int nLine, const void *pData, long nDataLen, const char *lpName );
79
78 private: 80 private:
79 Bu::FString sLogFormat; 81 Bu::FString sLogFormat;
80 int nLevelMask; 82 int nLevelMask;
@@ -89,6 +91,9 @@ namespace Bu
89#define lineLog( nLevel, sFrmt, ...) \ 91#define lineLog( nLevel, sFrmt, ...) \
90 Bu::Logger::getInstance().log( nLevel, __FILE__, __PRETTY_FUNCTION__, __LINE__, sFrmt, ##__VA_ARGS__ ) 92 Bu::Logger::getInstance().log( nLevel, __FILE__, __PRETTY_FUNCTION__, __LINE__, sFrmt, ##__VA_ARGS__ )
91 93
94#define logHexDump( nLevel, pData, iSize, sName ) \
95 Bu::Logger::getInstance().hexDump( nLevel, __FILE__, __PRETTY_FUNCTION__, __LINE__, pData, iSize, sName )
96
92/** 97/**
93 * Set the Bu::Logger logging mask directly. See Bu::Logger::setMask for 98 * Set the Bu::Logger logging mask directly. See Bu::Logger::setMask for
94 * details. 99 * details.
diff --git a/src/tests/logger.cpp b/src/tests/logger.cpp
index 290f479..59be9d4 100644
--- a/src/tests/logger.cpp
+++ b/src/tests/logger.cpp
@@ -22,6 +22,8 @@ int main()
22 setLogFormat("%L: %y-%02m-%02d %h:%02M:%02s %f:%l:%F: %t"); 22 setLogFormat("%L: %y-%02m-%02d %h:%02M:%02s %f:%l:%F: %t");
23 lineLog( 5, "Hey, error: %s", strerror( errno ) ); 23 lineLog( 5, "Hey, error: %s", strerror( errno ) );
24 24
25 logHexDump( 5, "This is a test of the hex-dump facility", 16, "Random stuff");
26
25 Thing gh; 27 Thing gh;
26 gh.go( 6); 28 gh.go( 6);
27} 29}