Major update:
- Logging
- Created LogCore Class
- Updated LogCore to use file descriptors instead of stdout
- Add Log object reference to constructors for:
FunctionCore, SelectCore
- Use extern Log() object in SignalCore
- SelectableCore
- Added new connection type: ForkedPipe
Create pipe, fork process, connect pipe out to child stdin, exec
This commit is contained in:
42
LogCore.cpp
42
LogCore.cpp
@@ -22,7 +22,13 @@ char LogStr[1000]; // Temporary var to create log messages,
|
||||
|
||||
//---------------------------------------------------------------------------
|
||||
|
||||
bool LogMessage( EDebugLevel DebugLevel, EDebugLevel MsgLevel, const char * Format, ... )
|
||||
CLogCore::CLogCore( FILE * pFileOutput )
|
||||
{
|
||||
FileOutput = pFileOutput;
|
||||
}
|
||||
//---------------------------------------------------------------------------
|
||||
|
||||
bool CLogCore::Message( EDebugLevel DebugLevel, EDebugLevel MsgLevel, const char * Format, ... )
|
||||
{
|
||||
va_list ArgPtr;
|
||||
|
||||
@@ -31,20 +37,20 @@ bool LogMessage( EDebugLevel DebugLevel, EDebugLevel MsgLevel, const char * Form
|
||||
return false;
|
||||
|
||||
// Check debug level
|
||||
if (MsgLevel > DebugLevel) {
|
||||
if (!FileOutput || (MsgLevel > DebugLevel)) {
|
||||
return true;
|
||||
}
|
||||
|
||||
// Show normal output
|
||||
va_start( ArgPtr, Format );
|
||||
vprintf( Format, ArgPtr );
|
||||
printf( "\r\n" );
|
||||
vfprintf( FileOutput, Format, ArgPtr );
|
||||
fprintf( FileOutput, "\r\n" );
|
||||
va_end( ArgPtr );
|
||||
return true;
|
||||
}
|
||||
//---------------------------------------------------------------------------
|
||||
|
||||
bool ShowOutput( EDebugLevel DebugLevel, EDebugLevel MsgLevel, const short Show, const char * Buffer, int Len, const char * Format, ... )
|
||||
bool CLogCore::Output( EDebugLevel DebugLevel, EDebugLevel MsgLevel, const short Show, const char * Buffer, int Len, const char * Format, ... )
|
||||
{
|
||||
va_list ArgPtr;
|
||||
|
||||
@@ -53,7 +59,7 @@ bool ShowOutput( EDebugLevel DebugLevel, EDebugLevel MsgLevel, const short Show,
|
||||
return false;
|
||||
|
||||
// Check debug level
|
||||
if (MsgLevel > DebugLevel) {
|
||||
if (!FileOutput || (MsgLevel > DebugLevel)) {
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -64,7 +70,7 @@ bool ShowOutput( EDebugLevel DebugLevel, EDebugLevel MsgLevel, const short Show,
|
||||
// Show Lead
|
||||
if (Format && *Format) {
|
||||
va_start( ArgPtr, Format );
|
||||
vprintf( Format, ArgPtr );
|
||||
vfprintf( FileOutput, Format, ArgPtr );
|
||||
va_end( ArgPtr );
|
||||
}
|
||||
|
||||
@@ -72,11 +78,11 @@ bool ShowOutput( EDebugLevel DebugLevel, EDebugLevel MsgLevel, const short Show,
|
||||
if (Show & OUT_COUNT)
|
||||
{
|
||||
// Print byte count
|
||||
printf( " [%d] ", Len );
|
||||
fprintf( FileOutput, " [%d] ", Len );
|
||||
|
||||
// EOL if only count wanted
|
||||
if (Show & OUT_COUNT) {
|
||||
printf( "\n" );
|
||||
fprintf( FileOutput, "\n" );
|
||||
}
|
||||
}
|
||||
|
||||
@@ -85,25 +91,25 @@ bool ShowOutput( EDebugLevel DebugLevel, EDebugLevel MsgLevel, const short Show,
|
||||
{
|
||||
if (Show & OUT_ASIS) {
|
||||
// Print entire buffer as is (line feeds included)
|
||||
printf( "%s", Buffer );
|
||||
fprintf( FileOutput, "%s", Buffer );
|
||||
}
|
||||
else {
|
||||
// Ignore \r\n
|
||||
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] );
|
||||
fprintf( FileOutput, "%c", Buffer[i] );
|
||||
else
|
||||
printf( "." );
|
||||
fprintf( FileOutput, "." );
|
||||
}
|
||||
else {
|
||||
printf( "%c", Buffer[i] );
|
||||
fprintf( FileOutput, "%c", Buffer[i] );
|
||||
}
|
||||
}
|
||||
}
|
||||
// Add EOL if not present or ignored
|
||||
if (!(Show & (OUT_ASIS | OUT_CRLF)) || (Buffer[Len-1] != '\n')) {
|
||||
printf( "\n" );
|
||||
fprintf( FileOutput, "\n" );
|
||||
}
|
||||
}
|
||||
|
||||
@@ -112,9 +118,9 @@ bool ShowOutput( EDebugLevel DebugLevel, EDebugLevel MsgLevel, const short Show,
|
||||
{
|
||||
// Print Hex values of individual bytes
|
||||
for (int i=0; i<Len; i++) {
|
||||
printf( "%02X ", (unsigned char)Buffer[i] );
|
||||
fprintf( FileOutput, "%02X ", (unsigned char)Buffer[i] );
|
||||
}
|
||||
printf( "\n" );
|
||||
fprintf( FileOutput, "\n" );
|
||||
}
|
||||
|
||||
// Show Binary output
|
||||
@@ -122,10 +128,10 @@ bool ShowOutput( EDebugLevel DebugLevel, EDebugLevel MsgLevel, const short Show,
|
||||
// Print each byte as 8-bit binary
|
||||
for (int i=0; i<Len; i++) {
|
||||
for (int j=0; j<8; j++) {
|
||||
printf( "%d", (bool)((Buffer[i] << j) & 0x80) );
|
||||
fprintf( FileOutput, "%d", (bool)((Buffer[i] << j) & 0x80) );
|
||||
}
|
||||
}
|
||||
printf( "\n" );
|
||||
fprintf( FileOutput, "\n" );
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user