enhanced raw command to log complete messages, fix for shutdown

This commit is contained in:
john30
2017-04-22 17:43:13 +02:00
parent 4fdc9b2fce
commit 930ae49513
4 changed files with 73 additions and 20 deletions
+10 -6
View File
@@ -54,7 +54,7 @@ bool RotateFile::setEnabled(bool enabled) {
return true;
}
void RotateFile::write(unsigned char* value, unsigned int size, bool received) {
void RotateFile::write(const unsigned char* value, const size_t size, const bool received, const bool bytes) {
if (!m_enabled || !m_stream) {
return;
}
@@ -63,12 +63,16 @@ void RotateFile::write(unsigned char* value, unsigned int size, bool received) {
struct tm td;
clockGettime(&ts);
localtime_r(&ts.tv_sec, &td);
fprintf(m_stream, "%04d-%02d-%02d %02d:%02d:%02d.%03ld %c",
fprintf(m_stream, "%04d-%02d-%02d %02d:%02d:%02d.%03ld ",
td.tm_year+1900, td.tm_mon+1, td.tm_mday,
td.tm_hour, td.tm_min, td.tm_sec, ts.tv_nsec/1000000,
received ? '<' : '>');
for (unsigned int pos = 0; pos < size; pos++) {
fprintf(m_stream, "%2.2x ", value[pos]);
td.tm_hour, td.tm_min, td.tm_sec, ts.tv_nsec/1000000);
if (bytes) {
fprintf(m_stream, received ? "<" : ">");
for (unsigned int pos = 0; pos < size; pos++) {
fprintf(m_stream, "%2.2x ", value[pos]);
}
} else {
fwrite(value, 1, size, m_stream);
}
fprintf(m_stream, "\n");
m_fileSize += 25+3*size+1;
+4 -2
View File
@@ -57,7 +57,7 @@ class RotateFile {
* @param enabled @p true to enable writing to the file, @p false to disable it.
* @return @p true when the state was changed, @p false otherwise.
*/
bool setEnabled(bool enabled = true);
bool setEnabled(bool enabled);
/**
* Return whether writing to the file is enabled.
@@ -70,8 +70,10 @@ class RotateFile {
* @param value the pointer to the bytes to write.
* @param size the number of bytes to write.
* @param received @a true on reception, @a false on sending (only relevant in text mode).
* @param bytes whether to log single bytes (only relevant in text mode).
*/
void write(unsigned char* value, unsigned int size, bool received = true);
void write(const unsigned char* value, const size_t size, const bool received = true,
const bool bytes = true);
private: