Skip to content

Commit 65ab552

Browse files
beats-dhdudantas
andauthored
perf: optimized logging with profiling and efficient file management (#7777) (opentibiabr#2832)
This improves the performance of the logging system and adds profiling functionality with automatic log generation. Additionally, optimizations have been performed to ensure that logs are written efficiently to text files. --------- Co-authored-by: Eduardo Dantas <[email protected]>
1 parent 469e09a commit 65ab552

24 files changed

Lines changed: 285 additions & 113 deletions

cmake/modules/BaseConfig.cmake

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -87,6 +87,7 @@ endif()
8787
# cmake -DDEBUG_LOG=ON ..
8888
if(DEBUG_LOG)
8989
add_definitions(-DDEBUG_LOG=ON)
90+
add_definitions(-DSPDLOG_ACTIVE_LEVEL=SPDLOG_LEVEL_TRACE)
9091
log_option_enabled("DEBUG LOG")
9192
else()
9293
log_option_disabled("DEBUG LOG")

config.lua.dist

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,8 @@ coreDirectory = "data"
99

1010
-- Set log level
1111
-- It can be trace, debug, info, warning, error, critical, off (default: info).
12-
-- NOTE: Will only display logs with level higher or equal the one set.
12+
-- NOTE: It will only be valid after the server starts up and only display logs with level higher or equal the one set.
13+
-- NOTE: Debug and trace logs are only available if compiled in debug mode.
1314
logLevel = "info"
1415

1516
--- Toggles the server's maintenance mode.
@@ -52,7 +53,7 @@ cleanProtectionZones = false
5253
-- Connection Config
5354
-- NOTE: allowOldProtocol can allow login on 10x protocol. (11.00)
5455
-- NOTE: maxPlayers set to 0 means no limit
55-
-- NOTE: MaxPacketsPerSeconds if you change you will be subject to bugs by WPE, keep the default value of 25,
56+
-- NOTE: MaxPacketsPerSeconds if you change you will be subject to bugs by WPE, keep the default value of 25,
5657
-- It's recommended to use a range like min 50 in this function, otherwise you will be disconnected after equipping two-handed distance weapons.
5758
ip = "127.0.0.1"
5859
allowOldProtocol = false

src/account/account.cpp

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,6 @@
1414
#include "utils/definitions.hpp"
1515
#include "security/argon.hpp"
1616
#include "utils/tools.hpp"
17-
#include "lib/logging/log_with_spd_log.hpp"
1817

1918
#include "enums/account_type.hpp"
2019
#include "enums/account_coins.hpp"

src/account/account_repository_db.cpp

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@
1010
#include "account/account_repository_db.hpp"
1111

1212
#include "database/database.hpp"
13-
#include "lib/logging/logger.hpp"
1413
#include "utils/definitions.hpp"
1514
#include "utils/tools.hpp"
1615
#include "enums/account_type.hpp"

src/canary_server.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,6 @@ int CanaryServer::run() {
9797
#endif
9898

9999
g_game().start(&serviceManager);
100-
g_game().setGameState(GAME_STATE_NORMAL);
101100
if (g_configManager().getBoolean(TOGGLE_MAINTAIN_MODE)) {
102101
g_game().setGameState(GAME_STATE_CLOSED);
103102
g_logger().warn("Initialized in maintain mode!");
@@ -133,6 +132,7 @@ int CanaryServer::run() {
133132
}
134133

135134
logger.info("{} {}", g_configManager().getString(SERVER_NAME), "server online!");
135+
g_logger().setLevel(g_configManager().getString(LOGLEVEL));
136136

137137
serviceManager.run();
138138

@@ -203,7 +203,7 @@ void CanaryServer::logInfos() {
203203
logger.info("{} - Version {}", ProtocolStatus::SERVER_NAME, SERVER_RELEASE_VERSION);
204204
#endif
205205

206-
logger.debug("Compiled with {}, on {} {}, for platform {}\n", getCompiler(), __DATE__, __TIME__, getPlatform());
206+
logger.debug("Compiled with {}, on {} {}, for platform {}", getCompiler(), __DATE__, __TIME__, getPlatform());
207207

208208
#if defined(LUAJIT_VERSION)
209209
logger.debug("Linked with {} for Lua support", LUAJIT_VERSION);

src/config/configmanager.cpp

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -35,10 +35,6 @@ bool ConfigManager::load() {
3535
return false;
3636
}
3737

38-
#ifndef DEBUG_LOG
39-
g_logger().setLevel(loadStringConfig(L, LOGLEVEL, "logLevel", "info"));
40-
#endif
41-
4238
// Parse config
4339
// Info that must be loaded one time (unless we reset the modules involved)
4440
if (!loaded) {
@@ -363,6 +359,7 @@ bool ConfigManager::load() {
363359
loadStringConfig(L, TIBIADROME_CONCOCTION_TICK_TYPE, "tibiadromeConcoctionTickType", "online");
364360
loadStringConfig(L, URL, "url", "");
365361
loadStringConfig(L, WORLD_TYPE, "worldType", "pvp");
362+
loadStringConfig(L, LOGLEVEL, "logLevel", "info");
366363

367364
loaded = true;
368365
lua_close(L);

src/database/database.hpp

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@
1010
#pragma once
1111

1212
#include "declarations.hpp"
13-
#include "lib/logging/log_with_spd_log.hpp"
1413

1514
#ifndef USE_PRECOMPILED_HEADERS
1615
#include <mysql/mysql.h>

src/game/scheduling/task.cpp

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@
99

1010
#include "task.hpp"
1111

12-
#include "lib/logging/log_with_spd_log.hpp"
1312
#include "lib/metrics/metrics.hpp"
1413

1514
std::atomic_uint_fast64_t Task::LAST_EVENT_ID = 0;

src/kv/kv.hpp

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,6 @@
2020
#include <list>
2121
#endif
2222

23-
#include "lib/logging/logger.hpp"
2423
#include "kv/value_wrapper.hpp"
2524

2625
class KV : public std::enable_shared_from_this<KV> {

src/kv/kv_sql.cpp

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@
1010
#include "kv/kv_sql.hpp"
1111

1212
#include "database/database.hpp"
13-
#include "lib/logging/logger.hpp"
1413
#include "kv/value_wrapper_proto.hpp"
1514
#include "utils/tools.hpp"
1615

0 commit comments

Comments
 (0)