1
Fork 0
mirror of https://github.com/SapphireServer/Sapphire.git synced 2025-04-28 23:27:45 +00:00

add logger message formatting

This commit is contained in:
NotAdam 2019-01-04 21:46:37 +11:00
parent dfc43dfae6
commit a140eeac4c
5 changed files with 55 additions and 19 deletions

View file

@ -47,9 +47,8 @@ void Sapphire::Db::DbWorkerPool< T >::setConnectionInfo( const ConnectionInfo& i
template< class T > template< class T >
uint32_t Sapphire::Db::DbWorkerPool< T >::open() uint32_t Sapphire::Db::DbWorkerPool< T >::open()
{ {
Logger::info( "[DbPool] Opening DatabasePool " + getDatabaseName() + Logger::info( "[DbPool] Opening DatabasePool {0} Asynchronous connections: {1} Synchronous connections: {2}",
" Asynchronous connections: " + std::to_string( m_asyncThreads ) + getDatabaseName(), m_asyncThreads, m_synchThreads );
" Synchronous connections: " + std::to_string( m_synchThreads ) );
uint32_t error = openConnections( IDX_ASYNC, m_asyncThreads ); uint32_t error = openConnections( IDX_ASYNC, m_asyncThreads );
@ -60,9 +59,8 @@ uint32_t Sapphire::Db::DbWorkerPool< T >::open()
if( !error ) if( !error )
{ {
Logger::info( "[DbPool] DatabasePool " + getDatabaseName() + " opened successfully. " + Logger::info( "[DbPool] DatabasePool '{0}' opened successfully. {1} total connections running.",
std::to_string( ( m_connections[ IDX_SYNCH ].size() + m_connections[ IDX_ASYNC ].size() ) ) + getDatabaseName(), ( m_connections[ IDX_SYNCH ].size() + m_connections[ IDX_ASYNC ].size() ) );
" total connections running." );
} }
return error; return error;
@ -71,10 +69,10 @@ uint32_t Sapphire::Db::DbWorkerPool< T >::open()
template< class T > template< class T >
void Sapphire::Db::DbWorkerPool< T >::close() void Sapphire::Db::DbWorkerPool< T >::close()
{ {
Logger::info( "[DbPool] Closing down DatabasePool " + getDatabaseName() ); Logger::info( "[DbPool] Closing down DatabasePool {0}", getDatabaseName() );
m_connections[ IDX_ASYNC ].clear(); m_connections[ IDX_ASYNC ].clear();
m_connections[ IDX_SYNCH ].clear(); m_connections[ IDX_SYNCH ].clear();
Logger::info( "[DbPool] All connections on DatabasePool " + getDatabaseName() + "closed." ); Logger::info( "[DbPool] All connections on DatabasePool {0} closed.", getDatabaseName() );
} }
template< class T > template< class T >

View file

@ -184,13 +184,13 @@ void Sapphire::Db::ZoneDbConnection::doPrepareStatements()
CONNECTION_BOTH ); CONNECTION_BOTH );
prepareStatement( ZONE_SEL_SPAWNGROUPS, prepareStatement( ZONE_SEL_SPAWNGROUPS,
"SELECT id, bNpcTemplateId, level, maxHp " "SELECT id, bNpcTemplateId, level, maxHp "
"FROM spawngroup " "FROM spawngroup "
"WHERE territoryTypeId = ?", "WHERE territoryTypeId = ?",
CONNECTION_BOTH ); CONNECTION_BOTH );
prepareStatement( ZONE_SEL_SPAWNPOINTS, prepareStatement( ZONE_SEL_SPAWNPOINTS,
"SELECT id, x, y, z, r " "SELECT id, x, y, z, r "
"FROM spawnpoint " "FROM spawnpoint "
"WHERE spawnGroupId = ?", "WHERE spawnGroupId = ?",
CONNECTION_BOTH ); CONNECTION_BOTH );

View file

@ -3,6 +3,8 @@
#include <string> #include <string>
#include <spdlog/fmt/fmt.h>
namespace Sapphire namespace Sapphire
{ {
@ -18,17 +20,54 @@ namespace Sapphire
static void init( const std::string& logPath ); static void init( const std::string& logPath );
// todo: this is a minor increase in build time because of fmtlib, but much less than including spdlog directly
static void error( const std::string& text ); static void error( const std::string& text );
template< typename... Args >
static void error( const std::string& fmt, const Args&... args )
{
error( fmt::format( fmt, args... ) );
}
static void warn( const std::string& text ); static void warn( const std::string& text );
template< typename... Args >
static void warn( const std::string& fmt, const Args&... args )
{
warn( fmt::format( fmt, args... ) );
}
static void info( const std::string& text ); static void info( const std::string& text );
template< typename... Args >
static void info( const std::string& fmt, const Args&... args )
{
info( fmt::format( fmt, args... ) );
}
static void debug( const std::string& text ); static void debug( const std::string& text );
template< typename... Args >
static void debug( const std::string& fmt, const Args&... args )
{
debug( fmt::format( fmt, args... ) );
}
static void fatal( const std::string& text ); static void fatal( const std::string& text );
template< typename... Args >
static void fatal( const std::string& fmt, const Args&... args )
{
fatal( fmt::format( fmt, args... ) );
}
static void trace( const std::string& text ); static void trace( const std::string& text );
template< typename... Args >
static void trace( const std::string& fmt, const Args&... args )
{
trace( fmt::format( fmt, args... ) );
}
}; };

View file

@ -259,8 +259,8 @@ int dumpSpawns()
//auto nameStruct = g_exdData.get< Sapphire::Data::BNpcName >( entry.first ); //auto nameStruct = g_exdData.get< Sapphire::Data::BNpcName >( entry.first );
auto teri1 = g_exdData.get< Sapphire::Data::TerritoryType >( entry.first ); auto teri1 = g_exdData.get< Sapphire::Data::TerritoryType >( entry.first );
auto teriPlaceName = g_exdData.get< Sapphire::Data::PlaceName >( teri1->placeName ); auto teriPlaceName = g_exdData.get< Sapphire::Data::PlaceName >( teri1->placeName );
Logger::info( std::to_string( entry.first ) + " - " + teri1->name + " - " + teriPlaceName->name ); Logger::info( "{0} - {1} - {2}", entry.first, teri1->name, teriPlaceName->name );
Logger::info( "Mob Count: " + std::to_string( entry.second.size() ) ); Logger::info( "Mob Count: {0}", entry.second.size() );
for( auto mob : entry.second ) for( auto mob : entry.second )
{ {
@ -283,9 +283,8 @@ int dumpSpawns()
for( auto mobName : lvlToPacket ) for( auto mobName : lvlToPacket )
{ {
auto nameStruct = g_exdData.get< Sapphire::Data::BNpcName >( mobName.second.at(0).bNPCName ); auto nameStruct = g_exdData.get< Sapphire::Data::BNpcName >( mobName.second.at(0).bNPCName );
Logger::info( "|--> " + nameStruct->singular + "(" + std::to_string( mobName.second.size() ) + ")" ); Logger::info( "|--> {0}, ({1})", nameStruct->singular, mobName.second.size() );
Logger::info( "|-> {0}", entry.first );
Logger::info( "|-> " + std::to_string( entry.first ) );
std::string name1 = delChar( nameStruct->singular, ' ' ); std::string name1 = delChar( nameStruct->singular, ' ' );
name1 = delChar( name1, '\'' ); name1 = delChar( name1, '\'' );

View file

@ -65,11 +65,11 @@ bool Sapphire::World::ServerMgr::loadSettings( int32_t argc, char* argv[] )
{ {
auto pConfig = framework()->get< Sapphire::ConfigMgr >(); auto pConfig = framework()->get< Sapphire::ConfigMgr >();
Logger::info( "Loading config " + m_configName ); Logger::info( "Loading config {0}", m_configName );
if( !pConfig->loadConfig( m_configName ) ) if( !pConfig->loadConfig( m_configName ) )
{ {
Logger::fatal( "Error loading config " + m_configName ); Logger::fatal( "Error loading config {0}", m_configName );
Logger::fatal( "If this is the first time starting the server, we've copied the default one for your editing pleasure." ); Logger::fatal( "If this is the first time starting the server, we've copied the default one for your editing pleasure." );
return false; return false;
} }
@ -103,7 +103,7 @@ void Sapphire::World::ServerMgr::run( int32_t argc, char* argv[] )
if( !pExdData->init( dataPath ) ) if( !pExdData->init( dataPath ) )
{ {
Logger::fatal( "Error setting up generated EXD data. Make sure that DataPath is set correctly in config.ini" ); Logger::fatal( "Error setting up generated EXD data. Make sure that DataPath is set correctly in config.ini" );
Logger::fatal( "DataPath: " + dataPath ); Logger::fatal( "DataPath: {0}", dataPath );
return; return;
} }
framework()->set< Data::ExdDataGenerated >( pExdData ); framework()->set< Data::ExdDataGenerated >( pExdData );
@ -192,7 +192,7 @@ void Sapphire::World::ServerMgr::run( int32_t argc, char* argv[] )
framework()->set< Manager::EventMgr >( pEventMgr ); framework()->set< Manager::EventMgr >( pEventMgr );
framework()->set< Manager::ItemMgr >( pItemMgr ); framework()->set< Manager::ItemMgr >( pItemMgr );
Logger::info( "World server running on " + m_ip + ":" + std::to_string( m_port ) ); Logger::info( "World server running on {0}:{1}", m_ip, m_port );
mainLoop(); mainLoop();