feat: Abstract Logger and simplify code (#1207)

* Logger: Rename logger to Logger from dLogger

* Logger: Add compile time filename

Fix include issues
Add writers
Add macros
Add macro to force compilation

* Logger: Replace calls with macros

Allows for filename and line number to be logged

* Logger: Add comments

and remove extra define

Logger: Replace with unique_ptr

also flush console at exit. regular file writer should be flushed on file close.

Logger: Remove constexpr on variable

* Logger: Simplify code

* Update Logger.cpp
This commit is contained in:
David Markowitz
2023-10-21 16:31:55 -07:00
committed by GitHub
parent 131239538b
commit 5942182486
160 changed files with 1013 additions and 985 deletions

View File

@@ -5,7 +5,7 @@
#include <sstream>
#include <string>
#include "BinaryIO.h"
#include "dLogger.h"
#include "Logger.h"
#include "Spawner.h"
#include "dZoneManager.h"
#include "GeneralUtils.h"
@@ -21,7 +21,7 @@ Level::Level(Zone* parentZone, const std::string& filepath) {
auto buffer = Game::assetManager->GetFileAsBuffer(filepath.c_str());
if (!buffer.m_Success) {
Game::logger->Log("Level", "Failed to load %s", filepath.c_str());
LOG("Failed to load %s", filepath.c_str());
return;
}

View File

@@ -1,6 +1,6 @@
#include "Spawner.h"
#include "EntityManager.h"
#include "dLogger.h"
#include "Logger.h"
#include "Game.h"
#include <sstream>
#include <functional>

View File

@@ -3,7 +3,7 @@
#include <fstream>
#include <sstream>
#include "Game.h"
#include "dLogger.h"
#include "Logger.h"
#include "GeneralUtils.h"
#include "BinaryIO.h"
#include "LUTriggers.h"
@@ -29,7 +29,7 @@ Zone::Zone(const LWOMAPID& mapID, const LWOINSTANCEID& instanceID, const LWOCLON
}
Zone::~Zone() {
Game::logger->Log("Zone", "Destroying zone %i", m_ZoneID.GetMapID());
LOG("Destroying zone %i", m_ZoneID.GetMapID());
for (std::map<LWOSCENEID, SceneRef>::iterator it = m_Scenes.begin(); it != m_Scenes.end(); ++it) {
if (it->second.level != nullptr) delete it->second.level;
}
@@ -49,7 +49,7 @@ void Zone::LoadZoneIntoMemory() {
AssetMemoryBuffer buffer = Game::assetManager->GetFileAsBuffer(m_ZoneFilePath.c_str());
if (!buffer.m_Success) {
Game::logger->Log("Zone", "Failed to load %s", m_ZoneFilePath.c_str());
LOG("Failed to load %s", m_ZoneFilePath.c_str());
throw std::runtime_error("Aborting Zone loading due to no Zone File.");
}
@@ -61,7 +61,7 @@ void Zone::LoadZoneIntoMemory() {
if (m_FileFormatVersion >= Zone::FileFormatVersion::Alpha) BinaryIO::BinaryRead(file, mapRevision);
BinaryIO::BinaryRead(file, m_WorldID);
if ((uint16_t)m_WorldID != m_ZoneID.GetMapID()) Game::logger->Log("Zone", "WorldID: %i doesn't match MapID %i! Is this intended?", m_WorldID, m_ZoneID.GetMapID());
if ((uint16_t)m_WorldID != m_ZoneID.GetMapID()) LOG("WorldID: %i doesn't match MapID %i! Is this intended?", m_WorldID, m_ZoneID.GetMapID());
AddRevision(LWOSCENEID_INVALID, mapRevision);
@@ -156,7 +156,7 @@ void Zone::LoadZoneIntoMemory() {
}
}
} else {
Game::logger->Log("Zone", "Failed to open: %s", m_ZoneFilePath.c_str());
LOG("Failed to open: %s", m_ZoneFilePath.c_str());
}
m_ZonePath = m_ZoneFilePath.substr(0, m_ZoneFilePath.rfind('/') + 1);
@@ -223,7 +223,7 @@ void Zone::AddRevision(LWOSCENEID sceneID, uint32_t revision) {
const void Zone::PrintAllGameObjects() {
for (std::pair<LWOSCENEID, SceneRef> scene : m_Scenes) {
Game::logger->Log("Zone", "In sceneID: %i", scene.first.GetSceneID());
LOG("In sceneID: %i", scene.first.GetSceneID());
scene.second.level->PrintAllObjects();
}
}
@@ -279,7 +279,7 @@ std::vector<LUTriggers::Trigger*> Zone::LoadLUTriggers(std::string triggerFile,
auto buffer = Game::assetManager->GetFileAsBuffer((m_ZonePath + triggerFile).c_str());
if (!buffer.m_Success) {
Game::logger->Log("Zone", "Failed to load %s from disk. Skipping loading triggers", (m_ZonePath + triggerFile).c_str());
LOG("Failed to load %s from disk. Skipping loading triggers", (m_ZonePath + triggerFile).c_str());
return lvlTriggers;
}
@@ -295,9 +295,9 @@ std::vector<LUTriggers::Trigger*> Zone::LoadLUTriggers(std::string triggerFile,
if (!doc) return lvlTriggers;
if (doc->Parse(data.str().c_str(), data.str().size()) == 0) {
//Game::logger->Log("Zone", "Loaded LUTriggers from file %s!", triggerFile.c_str());
//LOG("Loaded LUTriggers from file %s!", triggerFile.c_str());
} else {
Game::logger->Log("Zone", "Failed to load LUTriggers from file %s", triggerFile.c_str());
LOG("Failed to load LUTriggers from file %s", triggerFile.c_str());
return lvlTriggers;
}

View File

@@ -2,7 +2,7 @@
#include "dCommonVars.h"
#include "dZoneManager.h"
#include "EntityManager.h"
#include "dLogger.h"
#include "Logger.h"
#include "dConfig.h"
#include "InventoryComponent.h"
#include "DestroyableComponent.h"
@@ -18,7 +18,7 @@
#include "../dWorldServer/ObjectIDManager.h"
void dZoneManager::Initialize(const LWOZONEID& zoneID) {
Game::logger->Log("dZoneManager", "Preparing zone: %i/%i/%i", zoneID.GetMapID(), zoneID.GetInstanceID(), zoneID.GetCloneID());
LOG("Preparing zone: %i/%i/%i", zoneID.GetMapID(), zoneID.GetInstanceID(), zoneID.GetCloneID());
int64_t startTime = 0;
int64_t endTime = 0;
@@ -43,11 +43,11 @@ void dZoneManager::Initialize(const LWOZONEID& zoneID) {
}
}
Game::logger->Log("dZoneManager", "Creating zone control object %i", zoneControlTemplate);
LOG("Creating zone control object %i", zoneControlTemplate);
// Create ZoneControl object
if (!Game::entityManager) {
Game::logger->Log("dZoneManager", "ERROR: No entity manager loaded. Cannot proceed.");
LOG("ERROR: No entity manager loaded. Cannot proceed.");
throw std::invalid_argument("No entity manager loaded. Cannot proceed.");
}
Game::entityManager->Initialize();
@@ -63,7 +63,7 @@ void dZoneManager::Initialize(const LWOZONEID& zoneID) {
LoadWorldConfig();
Game::logger->Log("dZoneManager", "Zone prepared in: %llu ms", (endTime - startTime));
LOG("Zone prepared in: %llu ms", (endTime - startTime));
VanityUtilities::SpawnVanity();
}
@@ -100,7 +100,7 @@ void dZoneManager::NotifyZone(const dZoneNotifier& notifier, const LWOOBJID& obj
case dZoneNotifier::SpawnedChildObjectDestroyed:
break;
case dZoneNotifier::ReloadZone:
Game::logger->Log("dZoneManager", "Forcing reload of zone %i", m_ZoneID.GetMapID());
LOG("Forcing reload of zone %i", m_ZoneID.GetMapID());
LoadZone(m_ZoneID);
m_pZone->Initalize();
@@ -113,10 +113,10 @@ void dZoneManager::NotifyZone(const dZoneNotifier& notifier, const LWOOBJID& obj
m_pZone->PrintAllGameObjects();
break;
case dZoneNotifier::InvalidNotifier:
Game::logger->Log("dZoneManager", "Got an invalid zone notifier.");
LOG("Got an invalid zone notifier.");
break;
default:
Game::logger->Log("dZoneManager", "Unknown zone notifier: %i", int(notifier));
LOG("Unknown zone notifier: %i", int(notifier));
}
}
@@ -174,7 +174,7 @@ void dZoneManager::RemoveSpawner(const LWOOBJID id) {
auto* spawner = GetSpawner(id);
if (spawner == nullptr) {
Game::logger->Log("dZoneManager", "Failed to find spawner (%llu)", id);
LOG("Failed to find spawner (%llu)", id);
return;
}
@@ -184,14 +184,14 @@ void dZoneManager::RemoveSpawner(const LWOOBJID id) {
entity->Kill();
} else {
Game::logger->Log("dZoneManager", "Failed to find spawner entity (%llu)", id);
LOG("Failed to find spawner entity (%llu)", id);
}
spawner->DestroyAllEntities();
spawner->Deactivate();
Game::logger->Log("dZoneManager", "Destroying spawner (%llu)", id);
LOG("Destroying spawner (%llu)", id);
m_Spawners.erase(id);
@@ -244,14 +244,14 @@ bool dZoneManager::CheckIfAccessibleZone(LWOMAPID zoneID) {
}
void dZoneManager::LoadWorldConfig() {
Game::logger->Log("dZoneManager", "Loading WorldConfig into memory");
LOG("Loading WorldConfig into memory");
auto worldConfig = CDClientDatabase::ExecuteQuery("SELECT * FROM WorldConfig;");
if (!m_WorldConfig) m_WorldConfig = new WorldConfig();
if (worldConfig.eof()) {
Game::logger->Log("dZoneManager", "WorldConfig table is empty. Is this intended?");
LOG("WorldConfig table is empty. Is this intended?");
return;
}
@@ -314,5 +314,5 @@ void dZoneManager::LoadWorldConfig() {
m_WorldConfig->characterVersion = worldConfig.getIntField("CharacterVersion");
m_WorldConfig->levelCapCurrencyConversion = worldConfig.getIntField("LevelCapCurrencyConversion");
worldConfig.finalize();
Game::logger->Log("dZoneManager", "Loaded WorldConfig into memory");
LOG("Loaded WorldConfig into memory");
}