diff options
author | Mike Buland <eichlan@xagasoft.com> | 2007-07-09 19:25:42 +0000 |
---|---|---|
committer | Mike Buland <eichlan@xagasoft.com> | 2007-07-09 19:25:42 +0000 |
commit | b4da565534b3826037576a6c44e40716b024f89a (patch) | |
tree | d04b7d3a6240dea2471f1d08fbdaf91dad651f58 /src/logger.cpp | |
parent | 62a1a445ab61fe31367054c094b7e0bb0495833d (diff) | |
download | libbu++-b4da565534b3826037576a6c44e40716b024f89a.tar.gz libbu++-b4da565534b3826037576a6c44e40716b024f89a.tar.bz2 libbu++-b4da565534b3826037576a6c44e40716b024f89a.tar.xz libbu++-b4da565534b3826037576a6c44e40716b024f89a.zip |
The new logHexDump function seems to work just fine.
Diffstat (limited to 'src/logger.cpp')
-rw-r--r-- | src/logger.cpp | 44 |
1 files changed, 44 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 | ||
132 | void 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 | } | ||