Added configurable logging.

master
Pacman Ghost 8 years ago
parent 940e34af2e
commit 577a7e0af8
  1. 22
      MainApp/DebugConfig.cs
  2. 1
      MouseDll/api.hpp
  3. 51
      MouseDll/core.cpp

@ -1,4 +1,5 @@
using System.IO ;
using System ;
using System.IO ;
using System.Xml ;
using System.Runtime.InteropServices ;
@ -13,6 +14,7 @@ namespace MouseInterception
public struct ApiSettings
{
public string mLogFilename ;
public string mLogging ;
}
private ApiSettings mSettings ;
@ -33,10 +35,24 @@ namespace MouseInterception
xmlDoc.Load( xmlReader ) ;
// parse the values
XmlNode configXmlNode = xmlDoc.SelectSingleNode( "/debug" ) ;
XmlNode xmlNode = configXmlNode.SelectSingleNode( "logFilename" ) ;
XmlNode debugXmlNode = xmlDoc.SelectSingleNode( "/debug" ) ;
XmlNode xmlNode = debugXmlNode.SelectSingleNode( "logFilename" ) ;
if ( xmlNode != null )
mSettings.mLogFilename = xmlNode.InnerText.Trim() ;
mSettings.mLogging = "" ;
xmlNode = debugXmlNode.SelectSingleNode( "logging" ) ;
if ( xmlNode != null )
{
foreach( XmlAttribute xa in xmlNode.Attributes )
{
if ( Boolean.Parse( xa.Value ) )
{
if ( mSettings.mLogging.Length > 0 )
mSettings.mLogging += "|" ;
mSettings.mLogging += xa.Name.ToLower() ;
}
}
}
}
}

@ -50,6 +50,7 @@ struct ApiAction
struct ApiDebugConfig
{
const wchar_t* mpLogFilename ;
const wchar_t* mpLogging ;
} ;
// ---------------------------------------------------------------------

@ -3,6 +3,7 @@
#include <fstream>
#include <stdexcept>
#include <map>
#include <set>
#include "api.hpp"
#include "device.hpp"
@ -11,6 +12,8 @@
using namespace std ;
typedef set<string> StringSet ;
// --- LOCAL DATA ------------------------------------------------------
static HMODULE ghInterceptionDll = NULL ;
@ -26,9 +29,13 @@ static DeviceConfigTable gDeviceConfigTable ;
// --- LOCAL DATA ------------------------------------------------------
static bool gEnableConsole = false ;
static wstring gLogFilename ;
static ofstream gLogFile ;
static StringSet gLogging ;
static bool isLoggingEnabled( const string& s ) { return gLogging.find(s) != gLogging.end() ; }
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
#define LOG_MSG( msg ) \
@ -85,7 +92,8 @@ openApi(
assert( false ) ;
wcscpy_s( buf , ARRAY_SIZE(buf) , L"interception.dll" ) ;
}
LOG_MSG( "Loading Interception: " << toUtf8(buf) ) ;
if ( isLoggingEnabled( "startup" ) )
LOG_MSG( "Loading Interception: " << toUtf8(buf) ) ;
ghInterceptionDll = LoadLibrary( buf ) ;
if ( ghInterceptionDll == NULL )
throw runtime_error( MAKE_STRING( "Can't load Interception: " << getLastErrorString() ) ) ;
@ -159,6 +167,21 @@ reloadConfig(
}
}
// initialize logging
gLogging.clear() ;
const wchar_t* p = pDebugConfig->mpLogging ;
for ( ; ; )
{
const wchar_t* q = wcschr( p , L'|' ) ;
if ( q == NULL )
{
gLogging.insert( toUtf8(p) ) ;
break ;
}
gLogging.insert( toUtf8(p,q-p) ) ;
p = q + 1 ;
}
// load the Device's
gDeviceTable.deleteAll() ;
for ( int i=0 ; i < nDevices ; ++i )
@ -166,11 +189,14 @@ reloadConfig(
const ApiDevice* pDevice = pDevices+i ;
gDeviceTable[ pDevice->mDeviceId ] = new Device( pDevice ) ;
}
#if 1 // FIXME!
LOG_MSG( "Loaded devices:" ) ;
for ( DeviceTable::const_iterator it=gDeviceTable.begin() ; it != gDeviceTable.end() ; ++it )
(*it).second->dumpDevice( cout , " " ) ;
#endif
if ( isLoggingEnabled( "config" ) )
{
stringstream buf ;
buf << "Loaded devices:" << endl ;
for ( DeviceTable::const_iterator it=gDeviceTable.begin() ; it != gDeviceTable.end() ; ++it )
(*it).second->dumpDevice( buf , " " ) ;
LOG_MSG( buf.str() ) ;
}
// load the DeviceConfig's
gDeviceConfigTable.deleteAll() ;
@ -204,9 +230,12 @@ for ( DeviceTable::const_iterator it=gDeviceTable.begin() ; it != gDeviceTable.e
pActions , nActions
) ;
}
#if 1 // FIXME!
LOG_MSG( "Loaded device configs:" ) ;
for ( DeviceConfigTable::const_iterator it=gDeviceConfigTable.begin() ; it != gDeviceConfigTable.end() ; ++it )
(*it).second->dumpDeviceConfig( cout , " " ) ;
#endif
if ( isLoggingEnabled( "config" ) )
{
stringstream buf ;
buf << "Loaded device configs:" << endl ;
for ( DeviceConfigTable::const_iterator it=gDeviceConfigTable.begin() ; it != gDeviceConfigTable.end() ; ++it )
(*it).second->dumpDeviceConfig( buf , " " ) ;
LOG_MSG( buf.str() ) ;
}
}

Loading…
Cancel
Save