Timestamp log messages.

master
Pacman Ghost 7 years ago
parent 6551257a6d
commit a9517d7f92
  1. 42
      MouseDll/globals.cpp
  2. 7
      MouseDll/globals.hpp

@ -1,4 +1,5 @@
#include <set>
#include <ctime>
#include "globals.hpp"
@ -41,3 +42,44 @@ void initLogging( const wchar_t* pLogging )
}
bool isLoggingEnabled( const string& s ) { return gLogging.find(s) != gLogging.end() ; }
string
makeLogMsg( const string& msg )
{
// prepare the log message
stringstream buf ;
const char* p = msg.c_str() ;
for ( ; ; )
{
// output the timestamp/tab
if ( p == msg.c_str() )
{
char buf2[80] ;
time_t now = time( NULL ) ;
struct tm tmNow ;
(void) localtime_s( &tmNow , &now ) ;
strftime( buf2 , sizeof(buf2) , "%d/%b/%y %H:%M:%S" , &tmNow ) ;
for ( int i=0 ; buf2[i] != ' ' ; ++i )
buf2[i] = toupper( buf2[i] ) ;
buf << buf2 ;
}
else
buf << " " ;
buf << " | " ;
// output the next line
const char* q = strchr( p , '\n' ) ;
if ( q == NULL )
{
buf << p << endl ;
break ; // nb: this was the last line
}
buf.write( p , q-p ) ;
buf << endl ;
p = q + 1 ;
if ( *p == '\0' )
break ;
}
return buf.str() ;
}

@ -26,14 +26,15 @@ extern PCALLBACKFN gpCallbackFn ;
#define LOG_MSG( msg ) \
{ \
string _buf_ = MAKE_STRING( msg ) ; \
cout << _buf_ << endl ; \
string _buf_ = makeLogMsg( MAKE_STRING( msg ) ) ; \
cout << _buf_ ; \
if ( gLogFile.is_open() ) \
gLogFile << _buf_ << endl ; \
gLogFile << _buf_ ; \
}
extern void initLogging( const wchar_t* ) ;
extern bool isLoggingEnabled( const std::string& ) ;
extern std::string makeLogMsg( const std::string& ) ;
extern std::wstring gLogFilename ;
extern std::ofstream gLogFile ;

Loading…
Cancel
Save