mirror of
https://github.com/DarkflameUniverse/DarkflameServer.git
synced 2025-08-04 17:54:01 +00:00
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:
@@ -9,5 +9,5 @@ AddActionMessage::AddActionMessage(AMFArrayValue* arguments) : BehaviorMessageBa
|
||||
|
||||
action = Action(actionValue);
|
||||
|
||||
Game::logger->LogDebug("AddActionMessage", "actionIndex %i stripId %i stateId %i type %s valueParameterName %s valueParameterString %s valueParameterDouble %f behaviorId %i", actionIndex, actionContext.GetStripId(), actionContext.GetStateId(), action.GetType().c_str(), action.GetValueParameterName().c_str(), action.GetValueParameterString().c_str(), action.GetValueParameterDouble(), behaviorId);
|
||||
LOG_DEBUG("actionIndex %i stripId %i stateId %i type %s valueParameterName %s valueParameterString %s valueParameterDouble %f behaviorId %i", actionIndex, actionContext.GetStripId(), actionContext.GetStateId(), action.GetType().c_str(), action.GetValueParameterName().c_str(), action.GetValueParameterString().c_str(), action.GetValueParameterDouble(), behaviorId);
|
||||
}
|
||||
|
@@ -7,5 +7,5 @@ AddMessage::AddMessage(AMFArrayValue* arguments) : BehaviorMessageBase(arguments
|
||||
if (!behaviorIndexValue) return;
|
||||
|
||||
behaviorIndex = static_cast<uint32_t>(behaviorIndexValue->GetValue());
|
||||
Game::logger->LogDebug("AddMessage", "behaviorId %i index %i", behaviorId, behaviorIndex);
|
||||
LOG_DEBUG("behaviorId %i index %i", behaviorId, behaviorIndex);
|
||||
}
|
||||
|
@@ -18,7 +18,7 @@ AddStripMessage::AddStripMessage(AMFArrayValue* arguments) : BehaviorMessageBase
|
||||
|
||||
actionsToAdd.push_back(Action(actionValue));
|
||||
|
||||
Game::logger->LogDebug("AddStripMessage", "xPosition %f yPosition %f stripId %i stateId %i behaviorId %i t %s valueParameterName %s valueParameterString %s valueParameterDouble %f", position.GetX(), position.GetY(), actionContext.GetStripId(), actionContext.GetStateId(), behaviorId, actionsToAdd.back().GetType().c_str(), actionsToAdd.back().GetValueParameterName().c_str(), actionsToAdd.back().GetValueParameterString().c_str(), actionsToAdd.back().GetValueParameterDouble());
|
||||
LOG_DEBUG("xPosition %f yPosition %f stripId %i stateId %i behaviorId %i t %s valueParameterName %s valueParameterString %s valueParameterDouble %f", position.GetX(), position.GetY(), actionContext.GetStripId(), actionContext.GetStateId(), behaviorId, actionsToAdd.back().GetType().c_str(), actionsToAdd.back().GetValueParameterName().c_str(), actionsToAdd.back().GetValueParameterString().c_str(), actionsToAdd.back().GetValueParameterDouble());
|
||||
}
|
||||
Game::logger->Log("AddStripMessage", "number of actions %i", actionsToAdd.size());
|
||||
LOG_DEBUG("number of actions %i", actionsToAdd.size());
|
||||
}
|
||||
|
@@ -8,7 +8,7 @@
|
||||
#include "dCommonVars.h"
|
||||
|
||||
#include "Game.h"
|
||||
#include "dLogger.h"
|
||||
#include "Logger.h"
|
||||
|
||||
enum class BehaviorState : uint32_t;
|
||||
|
||||
|
@@ -6,6 +6,6 @@ MergeStripsMessage::MergeStripsMessage(AMFArrayValue* arguments) : BehaviorMessa
|
||||
destinationActionContext = ActionContext(arguments, "dstStateID", "dstStripID");
|
||||
dstActionIndex = GetActionIndexFromArgument(arguments, "dstActionIndex");
|
||||
|
||||
Game::logger->LogDebug("MergeStripsMessage", "srcstripId %i dststripId %i srcstateId %i dststateId %i dstactionIndex %i behaviorId %i", sourceActionContext.GetStripId(), destinationActionContext.GetStripId(), sourceActionContext.GetStateId(), destinationActionContext.GetStateId(), dstActionIndex, behaviorId);
|
||||
LOG_DEBUG("srcstripId %i dststripId %i srcstateId %i dststateId %i dstactionIndex %i behaviorId %i", sourceActionContext.GetStripId(), destinationActionContext.GetStripId(), sourceActionContext.GetStateId(), destinationActionContext.GetStateId(), dstActionIndex, behaviorId);
|
||||
}
|
||||
|
||||
|
@@ -7,5 +7,5 @@ MigrateActionsMessage::MigrateActionsMessage(AMFArrayValue* arguments) : Behavio
|
||||
destinationActionContext = ActionContext(arguments, "dstStateID", "dstStripID");
|
||||
dstActionIndex = GetActionIndexFromArgument(arguments, "dstActionIndex");
|
||||
|
||||
Game::logger->LogDebug("MigrateActionsMessage", "srcactionIndex %i dstactionIndex %i srcstripId %i dststripId %i srcstateId %i dststateId %i behaviorId %i", srcActionIndex, dstActionIndex, sourceActionContext.GetStripId(), destinationActionContext.GetStripId(), sourceActionContext.GetStateId(), destinationActionContext.GetStateId(), behaviorId);
|
||||
LOG_DEBUG("srcactionIndex %i dstactionIndex %i srcstripId %i dststripId %i srcstateId %i dststateId %i behaviorId %i", srcActionIndex, dstActionIndex, sourceActionContext.GetStripId(), destinationActionContext.GetStripId(), sourceActionContext.GetStateId(), destinationActionContext.GetStateId(), behaviorId);
|
||||
}
|
||||
|
@@ -5,5 +5,5 @@ MoveToInventoryMessage::MoveToInventoryMessage(AMFArrayValue* arguments) : Behav
|
||||
if (!behaviorIndexValue) return;
|
||||
|
||||
behaviorIndex = static_cast<uint32_t>(behaviorIndexValue->GetValue());
|
||||
Game::logger->LogDebug("MoveToInventoryMessage", "behaviorId %i behaviorIndex %i", behaviorId, behaviorIndex);
|
||||
LOG_DEBUG("behaviorId %i behaviorIndex %i", behaviorId, behaviorIndex);
|
||||
}
|
||||
|
@@ -6,5 +6,5 @@ RearrangeStripMessage::RearrangeStripMessage(AMFArrayValue* arguments) : Behavio
|
||||
|
||||
dstActionIndex = GetActionIndexFromArgument(arguments, "dstActionIndex");
|
||||
|
||||
Game::logger->LogDebug("RearrangeStripMessage", "srcactionIndex %i dstactionIndex %i stripId %i behaviorId %i stateId %i", srcActionIndex, dstActionIndex, actionContext.GetStripId(), behaviorId, actionContext.GetStateId());
|
||||
LOG_DEBUG("srcactionIndex %i dstactionIndex %i stripId %i behaviorId %i stateId %i", srcActionIndex, dstActionIndex, actionContext.GetStripId(), behaviorId, actionContext.GetStateId());
|
||||
}
|
||||
|
@@ -4,5 +4,5 @@ RemoveActionsMessage::RemoveActionsMessage(AMFArrayValue* arguments) : BehaviorM
|
||||
actionContext = ActionContext(arguments);
|
||||
actionIndex = GetActionIndexFromArgument(arguments);
|
||||
|
||||
Game::logger->LogDebug("RemoveActionsMessage", "behaviorId %i actionIndex %i stripId %i stateId %i", behaviorId, actionIndex, actionContext.GetStripId(), actionContext.GetStateId());
|
||||
LOG_DEBUG("behaviorId %i actionIndex %i stripId %i stateId %i", behaviorId, actionIndex, actionContext.GetStripId(), actionContext.GetStateId());
|
||||
}
|
||||
|
@@ -3,5 +3,5 @@
|
||||
RemoveStripMessage::RemoveStripMessage(AMFArrayValue* arguments) : BehaviorMessageBase(arguments) {
|
||||
actionContext = ActionContext(arguments);
|
||||
|
||||
Game::logger->LogDebug("RemoveStripMessage", "stripId %i stateId %i behaviorId %i", actionContext.GetStripId(), actionContext.GetStateId(), behaviorId);
|
||||
LOG_DEBUG("stripId %i stateId %i behaviorId %i", actionContext.GetStripId(), actionContext.GetStateId(), behaviorId);
|
||||
}
|
||||
|
@@ -5,5 +5,5 @@ RenameMessage::RenameMessage(AMFArrayValue* arguments) : BehaviorMessageBase(arg
|
||||
if (!nameAmf) return;
|
||||
|
||||
name = nameAmf->GetValue();
|
||||
Game::logger->LogDebug("RenameMessage", "behaviorId %i n %s", behaviorId, name.c_str());
|
||||
LOG_DEBUG("behaviorId %i n %s", behaviorId, name.c_str());
|
||||
}
|
||||
|
@@ -7,5 +7,5 @@ SplitStripMessage::SplitStripMessage(AMFArrayValue* arguments) : BehaviorMessage
|
||||
destinationActionContext = ActionContext(arguments, "dstStateID", "dstStripID");
|
||||
destinationPosition = StripUiPosition(arguments, "dstStripUI");
|
||||
|
||||
Game::logger->LogDebug("SplitStripMessage", "behaviorId %i xPosition %f yPosition %f sourceStrip %i destinationStrip %i sourceState %i destinationState %i srcActindex %i", behaviorId, destinationPosition.GetX(), destinationPosition.GetY(), sourceActionContext.GetStripId(), destinationActionContext.GetStripId(), sourceActionContext.GetStateId(), destinationActionContext.GetStateId(), srcActionIndex);
|
||||
LOG_DEBUG("behaviorId %i xPosition %f yPosition %f sourceStrip %i destinationStrip %i sourceState %i destinationState %i srcActindex %i", behaviorId, destinationPosition.GetX(), destinationPosition.GetY(), sourceActionContext.GetStripId(), destinationActionContext.GetStripId(), sourceActionContext.GetStateId(), destinationActionContext.GetStateId(), srcActionIndex);
|
||||
}
|
||||
|
@@ -11,5 +11,5 @@ UpdateActionMessage::UpdateActionMessage(AMFArrayValue* arguments) : BehaviorMes
|
||||
action = Action(actionValue);
|
||||
actionIndex = GetActionIndexFromArgument(arguments);
|
||||
|
||||
Game::logger->LogDebug("UpdateActionMessage", "type %s valueParameterName %s valueParameterString %s valueParameterDouble %f behaviorId %i actionIndex %i stripId %i stateId %i", action.GetType().c_str(), action.GetValueParameterName().c_str(), action.GetValueParameterString().c_str(), action.GetValueParameterDouble(), behaviorId, actionIndex, actionContext.GetStripId(), actionContext.GetStateId());
|
||||
LOG_DEBUG("type %s valueParameterName %s valueParameterString %s valueParameterDouble %f behaviorId %i actionIndex %i stripId %i stateId %i", action.GetType().c_str(), action.GetValueParameterName().c_str(), action.GetValueParameterString().c_str(), action.GetValueParameterDouble(), behaviorId, actionIndex, actionContext.GetStripId(), actionContext.GetStateId());
|
||||
}
|
||||
|
@@ -4,5 +4,5 @@ UpdateStripUiMessage::UpdateStripUiMessage(AMFArrayValue* arguments) : BehaviorM
|
||||
position = StripUiPosition(arguments);
|
||||
actionContext = ActionContext(arguments);
|
||||
|
||||
Game::logger->LogDebug("UpdateStripUIMessage", "xPosition %f yPosition %f stripId %i stateId %i behaviorId %i", position.GetX(), position.GetY(), actionContext.GetStripId(), actionContext.GetStateId(), behaviorId);
|
||||
LOG_DEBUG("xPosition %f yPosition %f stripId %i stateId %i behaviorId %i", position.GetX(), position.GetY(), actionContext.GetStripId(), actionContext.GetStateId(), behaviorId);
|
||||
}
|
||||
|
@@ -6,7 +6,7 @@
|
||||
#include "GameMessages.h"
|
||||
#include "ModelComponent.h"
|
||||
#include "../../dWorldServer/ObjectIDManager.h"
|
||||
#include "dLogger.h"
|
||||
#include "Logger.h"
|
||||
#include "BehaviorStates.h"
|
||||
#include "AssetManager.h"
|
||||
#include "BlockDefinition.h"
|
||||
@@ -170,7 +170,7 @@ void ControlBehaviors::SendBehaviorBlocksToClient(ModelComponent* modelComponent
|
||||
// AMFArrayValue* stateSerialize = new AMFArrayValue();
|
||||
|
||||
// for (auto it = states.begin(); it != states.end(); it++) {
|
||||
// Game::logger->Log("PropertyBehaviors", "Begin serialization of state %i!\n", it->first);
|
||||
// LOG("Begin serialization of state %i!\n", it->first);
|
||||
// AMFArrayValue* state = new AMFArrayValue();
|
||||
|
||||
// AMFDoubleValue* stateAsDouble = new AMFDoubleValue();
|
||||
@@ -180,7 +180,7 @@ void ControlBehaviors::SendBehaviorBlocksToClient(ModelComponent* modelComponent
|
||||
// AMFArrayValue* strips = new AMFArrayValue();
|
||||
// auto stripsInState = it->second->GetStrips();
|
||||
// for (auto strip = stripsInState.begin(); strip != stripsInState.end(); strip++) {
|
||||
// Game::logger->Log("PropertyBehaviors", "Begin serialization of strip %i!\n", strip->first);
|
||||
// LOG("Begin serialization of strip %i!\n", strip->first);
|
||||
// AMFArrayValue* thisStrip = new AMFArrayValue();
|
||||
|
||||
// AMFDoubleValue* stripID = new AMFDoubleValue();
|
||||
@@ -202,7 +202,7 @@ void ControlBehaviors::SendBehaviorBlocksToClient(ModelComponent* modelComponent
|
||||
|
||||
// AMFArrayValue* stripSerialize = new AMFArrayValue();
|
||||
// for (auto behaviorAction : strip->second->GetActions()) {
|
||||
// Game::logger->Log("PropertyBehaviors", "Begin serialization of action %s!\n", behaviorAction->actionName.c_str());
|
||||
// LOG("Begin serialization of action %s!\n", behaviorAction->actionName.c_str());
|
||||
// AMFArrayValue* thisAction = new AMFArrayValue();
|
||||
|
||||
// AMFStringValue* actionName = new AMFStringValue();
|
||||
@@ -247,20 +247,20 @@ void ControlBehaviors::UpdateAction(AMFArrayValue* arguments) {
|
||||
auto* blockDefinition = GetBlockInfo(updateActionMessage.GetAction().GetType());
|
||||
|
||||
if (!blockDefinition) {
|
||||
Game::logger->Log("ControlBehaviors", "Received undefined block type %s. Ignoring.", updateActionMessage.GetAction().GetType().c_str());
|
||||
LOG("Received undefined block type %s. Ignoring.", updateActionMessage.GetAction().GetType().c_str());
|
||||
return;
|
||||
}
|
||||
|
||||
if (updateActionMessage.GetAction().GetValueParameterString().size() > 0) {
|
||||
if (updateActionMessage.GetAction().GetValueParameterString().size() < blockDefinition->GetMinimumValue() ||
|
||||
updateActionMessage.GetAction().GetValueParameterString().size() > blockDefinition->GetMaximumValue()) {
|
||||
Game::logger->Log("ControlBehaviors", "Updated block %s is out of range. Ignoring update", updateActionMessage.GetAction().GetType().c_str());
|
||||
LOG("Updated block %s is out of range. Ignoring update", updateActionMessage.GetAction().GetType().c_str());
|
||||
return;
|
||||
}
|
||||
} else {
|
||||
if (updateActionMessage.GetAction().GetValueParameterDouble() < blockDefinition->GetMinimumValue() ||
|
||||
updateActionMessage.GetAction().GetValueParameterDouble() > blockDefinition->GetMaximumValue()) {
|
||||
Game::logger->Log("ControlBehaviors", "Updated block %s is out of range. Ignoring update", updateActionMessage.GetAction().GetType().c_str());
|
||||
LOG("Updated block %s is out of range. Ignoring update", updateActionMessage.GetAction().GetType().c_str());
|
||||
return;
|
||||
}
|
||||
}
|
||||
@@ -320,18 +320,18 @@ void ControlBehaviors::ProcessCommand(Entity* modelEntity, const SystemAddress&
|
||||
else if (command == "updateAction")
|
||||
UpdateAction(arguments);
|
||||
else
|
||||
Game::logger->Log("ControlBehaviors", "Unknown behavior command (%s)\n", command.c_str());
|
||||
LOG("Unknown behavior command (%s)\n", command.c_str());
|
||||
}
|
||||
|
||||
ControlBehaviors::ControlBehaviors() {
|
||||
auto blocksDefStreamBuffer = Game::assetManager->GetFileAsBuffer("ui\\ingame\\blocksdef.xml");
|
||||
if (!blocksDefStreamBuffer.m_Success) {
|
||||
Game::logger->Log("ControlBehaviors", "failed to open blocksdef");
|
||||
LOG("failed to open blocksdef");
|
||||
return;
|
||||
}
|
||||
std::istream blocksBuffer(&blocksDefStreamBuffer);
|
||||
if (!blocksBuffer.good()) {
|
||||
Game::logger->Log("ControlBehaviors", "Blocks buffer is not good!");
|
||||
LOG("Blocks buffer is not good!");
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -356,14 +356,14 @@ ControlBehaviors::ControlBehaviors() {
|
||||
|
||||
auto ret = m_Doc.Parse(buffer.c_str());
|
||||
if (ret == tinyxml2::XML_SUCCESS) {
|
||||
Game::logger->LogDebug("ControlBehaviors", "Successfully parsed the blocksdef file!");
|
||||
LOG_DEBUG("Successfully parsed the blocksdef file!");
|
||||
} else {
|
||||
Game::logger->Log("Character", "Failed to parse BlocksDef xmlData due to error %i!", ret);
|
||||
LOG("Failed to parse BlocksDef xmlData due to error %i!", ret);
|
||||
return;
|
||||
}
|
||||
auto* blockLibrary = m_Doc.FirstChildElement();
|
||||
if (!blockLibrary) {
|
||||
Game::logger->Log("ControlBehaviors", "No Block Library child element found.");
|
||||
LOG("No Block Library child element found.");
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -413,13 +413,13 @@ ControlBehaviors::ControlBehaviors() {
|
||||
} else {
|
||||
values = argument->FirstChildElement("EnumerationSource");
|
||||
if (!values) {
|
||||
Game::logger->Log("ControlBehaviors", "Failed to parse EnumerationSource from block (%s)", blockName.c_str());
|
||||
LOG("Failed to parse EnumerationSource from block (%s)", blockName.c_str());
|
||||
continue;
|
||||
}
|
||||
|
||||
auto* serviceNameNode = values->FirstChildElement("ServiceName");
|
||||
if (!serviceNameNode) {
|
||||
Game::logger->Log("ControlBehaviors", "Failed to parse ServiceName from block (%s)", blockName.c_str());
|
||||
LOG("Failed to parse ServiceName from block (%s)", blockName.c_str());
|
||||
continue;
|
||||
}
|
||||
|
||||
@@ -429,12 +429,12 @@ ControlBehaviors::ControlBehaviors() {
|
||||
blockDefinition->SetMaximumValue(res.getIntField("countSounds"));
|
||||
blockDefinition->SetDefaultValue("0");
|
||||
} else {
|
||||
Game::logger->Log("ControlBehaviors", "Unsupported Enumeration ServiceType (%s)", serviceName.c_str());
|
||||
LOG("Unsupported Enumeration ServiceType (%s)", serviceName.c_str());
|
||||
continue;
|
||||
}
|
||||
}
|
||||
} else {
|
||||
Game::logger->Log("ControlBehaviors", "Unsupported block value type (%s)!", typeName.c_str());
|
||||
LOG("Unsupported block value type (%s)!", typeName.c_str());
|
||||
continue;
|
||||
}
|
||||
}
|
||||
@@ -444,9 +444,9 @@ ControlBehaviors::ControlBehaviors() {
|
||||
blockSections = blockSections->NextSiblingElement();
|
||||
}
|
||||
isInitialized = true;
|
||||
Game::logger->LogDebug("ControlBehaviors", "Created all base block classes");
|
||||
LOG_DEBUG("Created all base block classes");
|
||||
for (auto b : blockTypes) {
|
||||
Game::logger->LogDebug("ControlBehaviors", "block name is %s default %s min %f max %f", b.first.c_str(), b.second->GetDefaultValue().c_str(), b.second->GetMinimumValue(), b.second->GetMaximumValue());
|
||||
LOG_DEBUG("block name is %s default %s min %f max %f", b.first.c_str(), b.second->GetDefaultValue().c_str(), b.second->GetMinimumValue(), b.second->GetMaximumValue());
|
||||
}
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user