Changed logging to go to either the console or a file.

master
Pacman Ghost 7 years ago
parent c8c828a5ef
commit 418db4b978
  1. 2
      MouseDll/core2.cpp
  2. 20
      MouseDll/debug.cpp
  3. 13
      MouseDll/debug.hpp

@ -388,7 +388,7 @@ findAppProfile( const DeviceConfig* pDeviceConfig , const AppProfile** ppDefault
if ( hProcess != NULL )
{
wchar_t buf[ MAX_PATH+1 ] ;
DWORD nChars = sizeof(buf) / sizeof(wchar_t) ;
DWORD nChars = ARRAY_SIZE( buf ) ;
BOOL rc = QueryFullProcessImageName( hProcess , 0 , buf , &nChars ) ;
if ( rc )
processExeName = toUtf8( buf , nChars ) ;

@ -1,4 +1,5 @@
#include <windows.h>
#include <fstream>
#include <set>
#include <ctime>
@ -9,8 +10,9 @@ using namespace std ;
// --- LOCAL DATA ------------------------------------------------------
ofstream gLogFile ;
static wstring gLogFilename ;
ostream* gpLogStream = NULL ;
static ofstream gLogFile ;
static wstring gLogFilename = L"<unset>" ;
static StringSet gEnabledLogging ; // FIXME! make this case-insensitive
@ -19,6 +21,8 @@ static StringSet gEnabledLogging ; // FIXME! make this case-insensitive
void
loadDebugConfig( const wchar_t* pDebugConfigFilename )
{
// NOTE: We have to do everything using wide strings, so that we can have a wide file path :-/
// initialize logging
gEnabledLogging.clear() ;
wchar_t buf[ 4*1024 ] ;
@ -36,11 +40,17 @@ loadDebugConfig( const wchar_t* pDebugConfigFilename )
{
if ( gLogFile.is_open() )
gLogFile.close() ;
if ( pLogFilename[0] != L'\0' )
if ( _wcsicmp( pLogFilename , L"console" ) == 0 || pLogFilename[0] == L'\0' )
{
// FIXME! When the main app calls AttachConsole(), we don't seem to be able to access cout/cerr separately.
gpLogStream = & cout ;
}
else
{
gLogFile.open( pLogFilename ) ;
gLogFilename = pLogFilename ;
gpLogStream = & gLogFile ;
}
gLogFilename = pLogFilename ;
}
}
@ -61,7 +71,7 @@ makeLogMsg( const string& msg )
time_t now = time( NULL ) ;
struct tm tmNow ;
(void) localtime_s( &tmNow , &now ) ;
strftime( buf2 , sizeof(buf2) , "%d/%b/%y %H:%M:%S" , &tmNow ) ;
strftime( buf2 , ARRAY_SIZE(buf2) , "%d/%b/%y %H:%M:%S" , &tmNow ) ;
for ( int i=0 ; buf2[i] != ' ' ; ++i )
buf2[i] = toupper( buf2[i] ) ;
buf << buf2 ;

@ -2,7 +2,6 @@
#define DEBUG_HPP
#include <iostream>
#include <fstream>
// ---------------------------------------------------------------------
@ -12,15 +11,13 @@ extern void loadDebugConfig( const wchar_t* pDebugConfigFilename ) ;
#define LOG_MSG( msg ) \
{ \
string _buf_ = makeLogMsg( MAKE_STRING( msg ) ) ; \
cout << _buf_ ; \
cout.flush() ; \
if ( gLogFile.is_open() ) \
if ( gpLogStream != NULL ) \
{ \
gLogFile << _buf_ ; \
gLogFile.flush() ; \
*gpLogStream << makeLogMsg( MAKE_STRING( msg ) ) ; \
gpLogStream->flush() ; \
} \
}
#define LOG_CMSG( c , msg ) \
{ \
if ( isLoggingEnabled( c ) ) \
@ -30,7 +27,7 @@ extern void loadDebugConfig( const wchar_t* pDebugConfigFilename ) ;
extern bool isLoggingEnabled( const std::string& ) ;
extern std::string makeLogMsg( const std::string& ) ;
extern std::ofstream gLogFile ;
extern std::ostream* gpLogStream ;
// ---------------------------------------------------------------------

Loading…
Cancel
Save