Files
redAcore/LogCore.cpp
Charl Wentzel c01c8f5e9b Major Update:
- Implemented global var DebugLevel
- Update LogCore to check DebugLevel
- Added many log messages and standadised all log messages
- Further improved validation checks on all methods
- Updated SelectCore, only remove SelectHandle from list during Test()
- Close Handles in SelectableCore destructor
Bug fixes:
- Non-blocking Client Socket Connection now working correctly
- Remove FD from Select lists at the correct time
2016-05-26 15:03:13 +02:00

95 lines
2.4 KiB
C++

/*
* LogCore.cpp
*
* Created on: 17 May 2016
* Author: wentzelc
*/
// redA Libraries
#include "LogCore.h"
// Standard C/C++ Libraries
#include <stdio.h>
#include <unistd.h>
#include <stdlib.h>
#include <string.h>
//---------------------------------------------------------------------------
// Global vars
EDebugLevel DebugLevel = dlLow;
char LogStr[1000]; // Temporary var to create log messages, globally available to save on memory operations
//---------------------------------------------------------------------------
bool LogMessage( const char * Heading, EDebugLevel Level, const char *Message )
{
// Validate values
if (!Message)
return false;
// Check debug level
if (Level > DebugLevel) {
return true;
}
// Show normal output
if (!Heading) {
printf( "%s\n", Message );
}
else {
printf( "%s: %s\n", Heading, Message );
}
return true;
}
//---------------------------------------------------------------------------
bool ShowOutput( const char * Heading, EDebugLevel Level, const short Show, const char * Buffer, int Len )
{
// Validate values
if (!Buffer)
return false;
if (Len == -1)
Len = strlen( Buffer );
// Check debug level
if (Level > DebugLevel) {
return true;
}
// Show Hex output
if (Show & OUT_HEX) {
printf( "%s [%d]: ", Heading, Len );
for (int i=0; i<Len; i++) {
printf( "%02X ", Buffer[i] );
}
printf( "\n" );
}
// Show normal output
if (Show & OUT_NORMAL) {
printf( "%s [%d]: ", Heading, Len );
if (Show & OUT_ASIS) {
printf( "%s", Buffer );
}
else {
for (int i=0; i<Len; i++) {
if ((Buffer[i] < 32) || (Buffer[i] > 126)) {
if ((Show & OUT_CRLF) && ((Buffer[i] == '\r') || (Buffer[i] == '\n')))
printf( "%c", Buffer[i] );
else
printf( "." );
}
else {
printf( "%c", Buffer[i] );
}
}
}
if (!(Show & (OUT_ASIS | OUT_CRLF)) || (Buffer[Len-1] != '\n')) {
printf( "\n" );
}
}
return true;
}
//---------------------------------------------------------------------------