/* * LogCore.cpp * * Created on: 17 May 2016 * Author: wentzelc */ // redA Libraries #include "LogCore.h" // Standard C/C++ Libraries #include #include #include #include #include //--------------------------------------------------------------------------- // Global vars char LogStr[1000]; // Temporary var to create log messages, globally available to save on memory operations //--------------------------------------------------------------------------- CLogCore::CLogCore( FILE * pFileOutput ) { FileOutput = pFileOutput; } //--------------------------------------------------------------------------- bool CLogCore::Message( EDebugLevel DebugLevel, EDebugLevel MsgLevel, const char * Format, ... ) { va_list ArgPtr; // Validate values if (!Format || !*Format) return false; // Check debug level if (!FileOutput || (MsgLevel > DebugLevel)) { return true; } // Show normal output va_start( ArgPtr, Format ); vfprintf( FileOutput, Format, ArgPtr ); fprintf( FileOutput, "\r\n" ); va_end( ArgPtr ); return true; } //--------------------------------------------------------------------------- bool CLogCore::Output( EDebugLevel DebugLevel, EDebugLevel MsgLevel, const short Show, const char * Buffer, int Len, const char * Format, ... ) { va_list ArgPtr; // Validate values if (!Buffer || !(Show & (OUT_COUNT |OUT_NORMAL | OUT_HEX | OUT_BIN))) return false; // Check debug level if (!FileOutput || (MsgLevel > DebugLevel)) { return true; } // Get length if (Len == -1) Len = strlen( Buffer ); // Show Lead if (Format && *Format) { va_start( ArgPtr, Format ); vfprintf( FileOutput, Format, ArgPtr ); va_end( ArgPtr ); } // Show byte count if (Show & OUT_COUNT) { // Print byte count fprintf( FileOutput, " [%d] ", Len ); // EOL if only count wanted if (Show & OUT_COUNT) { fprintf( FileOutput, "\n" ); } } // Show Normal output if (Show & OUT_NORMAL) { if (Show & OUT_ASIS) { // Print entire buffer as is (line feeds included) fprintf( FileOutput, "%s", Buffer ); } else { // Ignore \r\n for (int i=0; i 126)) { if ((Show & OUT_CRLF) && ((Buffer[i] == '\r') || (Buffer[i] == '\n'))) fprintf( FileOutput, "%c", Buffer[i] ); else fprintf( FileOutput, "." ); } else { fprintf( FileOutput, "%c", Buffer[i] ); } } } // Add EOL if not present or ignored if (!(Show & (OUT_ASIS | OUT_CRLF)) || (Buffer[Len-1] != '\n')) { fprintf( FileOutput, "\n" ); } } // Show Hex output if (Show & OUT_HEX) { // Print Hex values of individual bytes for (int i=0; i