diff options
Diffstat (limited to '')
-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 | } | ||