Skip to content

Commit

Permalink
Changed the way the EVEmu server logs the console to logfiles. The ev…
Browse files Browse the repository at this point in the history
…e-server.xml tag <log> under <files> was changed to <logDir> so you must change your existing eve-server.xml file to use this new tag and delete the old one. You must also change the value inside the tag to be a path ending with a forward slash '/'. Log files will now show up in the path specified in that tag. If you do not specify a tag, the default relative path ../log/ will be used instead.
  • Loading branch information
aknorjaden committed Aug 17, 2011
1 parent f23d82f commit 29ce1fa
Show file tree
Hide file tree
Showing 6 changed files with 62 additions and 29 deletions.
11 changes: 10 additions & 1 deletion include/common/log/LogNew.h
Original file line number Diff line number Diff line change
Expand Up @@ -44,9 +44,16 @@ class NewLog
public:
/// Primary constructor, initializes logging.
NewLog();
NewLog(std::string logPath);
/// Destructor, closes the logfile.
~NewLog();

/**
* @brief Initializes and sets the Log file path.
*
* @param[in] logPath is the absolute or relative path where log files are to be stored
*/
void InitializeLogging( std::string logPath );
/**
* @brief Logs a message to file.
*
Expand Down Expand Up @@ -177,7 +184,7 @@ class NewLog
/**
* @brief Sets the default logfile.
*/
void SetLogfileDefault();
void SetLogfileDefault(std::string logPath);

/// The active logfile.
FILE* mLogfile;
Expand All @@ -186,6 +193,8 @@ class NewLog
/// Protection against concurrent log messages
Mutex mMutex;

bool m_initialized;

#ifdef WIN32
/// Handle to standard output stream.
const HANDLE mStdOutHandle;
Expand Down
4 changes: 2 additions & 2 deletions include/eve-server/EVEServerConfig.h
Original file line number Diff line number Diff line change
Expand Up @@ -94,8 +94,8 @@ class EVEServerConfig
// From <files/>
struct
{
/// A logfile to be used.
std::string log;
/// A directory in which the log files are stored
std::string logDir;
/// A log configuration file.
std::string logSettings;
/// A directory at which the cache files should be stored.
Expand Down
31 changes: 26 additions & 5 deletions src/common/log/LogNew.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -68,10 +68,12 @@ NewLog::NewLog()
mStdErrHandle( GetStdHandle( STD_ERROR_HANDLE ) )
#endif /* WIN32 */
{
// open default logfile
SetLogfileDefault();
//// open default logfile
//std::string logPath = EVEMU_ROOT_DIR"log/";
//SetLogfileDefault(logPath);

Debug( "Log", "Log system initiated" );
//Debug( "Log", "Log system initiated" );
m_initialized = false;
}

NewLog::~NewLog()
Expand All @@ -82,6 +84,19 @@ NewLog::~NewLog()
SetLogfile( (FILE*)NULL );
}

void NewLog::InitializeLogging( std::string logPath )
{
// open default logfile
if( logPath.empty() )
logPath = EVEMU_ROOT_DIR"log/";

m_initialized = true;

SetLogfileDefault(logPath);

Debug( "Log", "Log system initiated" );
}

void NewLog::Log( const char* source, const char* fmt, ... )
{
va_list ap;
Expand Down Expand Up @@ -166,6 +181,9 @@ bool NewLog::SetLogfile( FILE* file )

void NewLog::PrintMsg( Color color, char pfx, const char* source, const char* fmt, va_list ap )
{
if( !m_initialized )
return;

MutexLock l( mMutex );

PrintTime();
Expand Down Expand Up @@ -246,7 +264,7 @@ void NewLog::SetColor( Color color )
#endif /* !WIN32 */
}

void NewLog::SetLogfileDefault()
void NewLog::SetLogfileDefault(std::string logPath)
{
MutexLock l( mMutex );

Expand All @@ -258,8 +276,11 @@ void NewLog::SetLogfileDefault()

// open default logfile
char filename[ MAX_PATH + 1 ];
snprintf( filename, MAX_PATH + 1, EVEMU_ROOT_DIR"log/log_%02u-%02u-%04u-%02u-%02u.log",
std::string logFile = logPath + "log_%02u-%02u-%04u-%02u-%02u.log";
snprintf( filename, MAX_PATH + 1, logFile.c_str(),
t.tm_mday, t.tm_mon + 1, t.tm_year + 1900, t.tm_hour, t.tm_min );
//snprintf( filename, MAX_PATH + 1, EVEMU_ROOT_DIR"log/log_%02u-%02u-%04u-%02u-%02u.log",
// t.tm_mday, t.tm_mon + 1, t.tm_year + 1900, t.tm_hour, t.tm_min );

if( SetLogfile( filename ) )
Success( "Log", "Opened logfile '%s'.", filename );
Expand Down
6 changes: 3 additions & 3 deletions src/eve-server/EVEServerConfig.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ EVEServerConfig::EVEServerConfig()
database.db = "evemu";

// files
files.log = "../log/eve-server.log";
files.logDir = "../log/";
files.logSettings = "../etc/log.ini";
files.cacheDir = "../server_cache/";
files.imageDir = "../image_cache/";
Expand Down Expand Up @@ -179,14 +179,14 @@ bool EVEServerConfig::ProcessDatabase( const TiXmlElement* ele )

bool EVEServerConfig::ProcessFiles( const TiXmlElement* ele )
{
AddValueParser( "log", files.log );
AddValueParser( "logDir", files.logDir );
AddValueParser( "logSettings", files.logSettings );
AddValueParser( "cacheDir", files.cacheDir );
AddValueParser( "imageDir", files.imageDir );

const bool result = ParseElementChildren( ele );

RemoveParser( "log" );
RemoveParser( "logDir" );
RemoveParser( "logSettings" );
RemoveParser( "cacheDir" );
RemoveParser( "imageDir" );
Expand Down
37 changes: 20 additions & 17 deletions src/eve-server/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,18 @@ int main( int argc, char* argv[] )
printf("details.\n");
printf("\n");

sLog.Log("main", "EVEmu "EVEMU_VERSION );
// Load server configuration
if( !sConfig.ParseFile( CONFIG_FILE ) )
{
printf("ERROR: Loading server configuration '%s' failed.", CONFIG_FILE );
//sLog.Error( "server init", "Loading server configuration '%s' failed.", CONFIG_FILE );
return 1;
}

sLog.InitializeLogging(sConfig.files.logDir);
sLog.Log("server init", "Loading server configuration...");

sLog.Log("main", "EVEmu "EVEMU_VERSION );
sLog.Log("server init", "\n"
"\tSupported Client: %s\n"
"\tVersion %.2f\n"
Expand All @@ -69,28 +80,20 @@ int main( int argc, char* argv[] )
//it is important to do this before doing much of anything, in case they use it.
Timer::SetCurrentTime();

// Load server configuration
sLog.Log("server init", "Loading server configuration...");

if( !sConfig.ParseFile( CONFIG_FILE ) )
{
sLog.Error( "server init", "Loading server configuration '%s' failed.", CONFIG_FILE );
return 1;
}

// Load server log settings ( will be removed )
if( load_log_settings( sConfig.files.logSettings.c_str() ) )
sLog.Success( "server init", "Log settings loaded from %s", sConfig.files.logSettings.c_str() );
else
sLog.Warning( "server init", "Unable to read %s (this file is optional)", sConfig.files.logSettings.c_str() );

// open up the log file if specified ( will be removed )
if( !sConfig.files.log.empty() )
if( !sConfig.files.logDir.empty() )
{
if( log_open_logfile( sConfig.files.log.c_str() ) )
sLog.Success( "server init", "Opened log file %s", sConfig.files.log.c_str() );
std::string logFile = sConfig.files.logDir + "eve-server.log";
if( log_open_logfile( logFile.c_str() ) )
sLog.Success( "server init", "Found log directory %s", sConfig.files.logDir.c_str() );
else
sLog.Warning( "server init", "Unable to open log file '%s', only logging to the screen now.", sConfig.files.log.c_str() );
sLog.Warning( "server init", "Unable to find log directory '%s', only logging to the screen now.", sConfig.files.logDir.c_str() );
}

//connect to the database...
Expand Down Expand Up @@ -272,9 +275,9 @@ int main( int argc, char* argv[] )
log_close_logfile();

// win crap.
#if defined( MSVC ) && !defined( NDEBUG )
_CrtDumpMemoryLeaks();
#endif /* defined( MSVC ) && !defined( NDEBUG ) */
//#if defined( MSVC ) && !defined( NDEBUG )
// _CrtDumpMemoryLeaks();
//#endif /* defined( MSVC ) && !defined( NDEBUG ) */

return 0;
}
Expand Down
2 changes: 1 addition & 1 deletion utils/eve-server.xml
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ a likely exception to this goal).
</database>

<files>
<!-- <log>../log/eve-server.log</log> -->
<!-- <logDir>../log/</logDir> -->
<!-- <logSettings>../etc/log.ini</logSettings> -->
<!-- <cacheDir>../server_cache/</cacheDir> -->
<!-- <imageDir>../image_cache/</imageDir> -->
Expand Down

0 comments on commit 29ce1fa

Please sign in to comment.