feat: add gmInte.config.logTimestamp

This commit is contained in:
Linventif 2025-05-27 19:32:12 +00:00
parent de480a8934
commit 39db1436b2
5 changed files with 37 additions and 8 deletions

View File

@ -2,13 +2,23 @@ if game.SinglePlayer() then return print("Gmod Integration is not supported in S
gmInte = gmInte || {}
gmInte.version = "0.5.0"
gmInte.config = {}
gmInte.useDataConfig = true
function gmInte.simpleLog(msg, debug)
print(" | " .. os.date(gmInte.config.logTimestamp || "%Y-%m-%d %H:%M:%S") .. " | Gmod Integration | " .. msg)
end
local function loadConfig()
RunConsoleCommand("sv_hibernate_think", "1")
if !file.Exists("gm_integration", "DATA") || !file.Exists("gm_integration/config.json", "DATA") then
file.CreateDir("gm_integration")
file.Write("gm_integration/config.json", util.TableToJSON(gmInte.config, true))
else
if gmInte.config.id && gmInte.config.id != "" then return end
if gmInte.config.id && gmInte.config.id != "" then
gmInte.useDataConfig = false
timer.Simple(1, function() gmInte.simpleLog("Using Data Config | This is not recommended, please revert change and use ig cmd !gmi to edit your config", true) end)
return
end
local oldConfig = util.JSONToTable(file.Read("gm_integration/config.json", "DATA"))
if !oldConfig.version || (oldConfig.version < gmInte.version) then
table.Merge(gmInte.config, oldConfig)
@ -17,6 +27,8 @@ local function loadConfig()
else
gmInte.config = oldConfig
end
gmInte.simpleLog("Using Data Config | Data config loaded from data/gm_integration/config.json")
end
end
@ -25,7 +37,6 @@ local function loadFile(folder, fileName)
local path = folder .. "/" .. fileName
if loadedFiles[path] then return end
loadedFiles[path] = true
print(" | Loading File | " .. path)
if string.StartWith(fileName, "cl_") then
if SERVER then
AddCSLuaFile(path)
@ -40,6 +51,7 @@ local function loadFile(folder, fileName)
end
if fileName == "sv_config.lua" then loadConfig() end
gmInte.simpleLog("File Loaded | " .. path)
end
local function loadFolder(folder)

View File

@ -222,6 +222,21 @@ function gmInte.openConfigMenu(data)
["onEditDelay"] = 0.5,
["category"] = gmInte.getTranslation("admin.advanced", "Advanced")
},
{
["id"] = "logTimestamp",
["label"] = gmInte.getTranslation("admin.internal_log_format", "Internal Log Format"),
["description"] = gmInte.getTranslation("admin.internal_log_format_description", "The timestamp format of the logs."),
["type"] = "textEntry",
["resetIfEmpty"] = true,
["defaultValue"] = "%Y-%m-%d %H:%M:%S",
["value"] = function(setting, value) return value end,
["onEdit"] = function(setting, value)
if !value || value == "" then return end
saveConfig(setting, value)
end,
["onEditDelay"] = 0.5,
["category"] = gmInte.getTranslation("admin.advanced", "Advanced")
},
}
local buttonsInfo = {

View File

@ -58,7 +58,8 @@ function gmInte.publicGetConfig(ply)
["websocketFQDN"] = gmInte.config.websocketFQDN,
["adminRank"] = gmInte.config.adminRank,
["language"] = gmInte.config.language,
["clientBranch"] = gmInte.config.clientBranch
["clientBranch"] = gmInte.config.clientBranch,
["logTimestamp"] = gmInte.config.logTimestamp
},
["other"] = {
["aprovedCredentials"] = gmInte.aprovedCredentials,

View File

@ -1,29 +1,29 @@
local function getTimeStamp()
if !gmInte.config.debug then return "" end
return os.date("[%Y-%m-%d %H:%M:%S]")
return os.date(gmInte.config.logTimestamp || "%Y-%m-%d %H:%M:%S")
end
function gmInte.log(msg, debug)
if debug && !gmInte.config.debug then return end
print(getTimeStamp() .. " [Gmod Integration] " .. msg)
print(getTimeStamp() .. " | Gmod Integration | " .. msg)
end
// Log Error
function gmInte.logError(msg, debug)
if debug && !gmInte.config.debug then return end
print(getTimeStamp() .. " [Gmod Integration] [ERROR] " .. msg)
print(getTimeStamp() .. " | Gmod Integration | ERROR | " .. msg)
end
// Log Warning
function gmInte.logWarning(msg, debug)
if debug && !gmInte.config.debug then return end
print(getTimeStamp() .. " [Gmod Integration] [WARNING] " .. msg)
print(getTimeStamp() .. " | Gmod Integration | WARNING | " .. msg)
end
// Log Hint
function gmInte.logHint(msg, debug)
if debug && !gmInte.config.debug then return end
print(getTimeStamp() .. " [Gmod Integration] [HINT] " .. msg)
print(getTimeStamp() .. " | Gmod Integration | HINT | " .. msg)
end
// Is Private IP

View File

@ -38,6 +38,7 @@ gmInte.config.clientBranch = "any" // The branch of the addon that the clients s
gmInte.config.supportLink = "" // The link of your support (shown when a player do not have the requiments to join the server)
gmInte.config.maintenance = false // If true, the addon will only allow the players with the "gmod-integration.maintenance" permission to join the server
gmInte.config.language = "en" // The language of the addon (en, fr, de, es, it, tr, ru)
gmInte.config.logTimestamp = "%H:%M:%S" // The timestamp format of the logs
gmInte.config.adminRank = {
// How can edit the configuration of the addon / bypass the maintenance mode
["superadmin"] = true,