Fixed logging (refs #65) and improved logging format in standalone mode

This commit is contained in:
Timo Smit 2017-01-21 10:43:39 +01:00
parent 702ed2748d
commit 86a427964d
2 changed files with 28 additions and 19 deletions

View file

@ -17,8 +17,6 @@
require (wolfa_getLuaPath()..".util.debug") require (wolfa_getLuaPath()..".util.debug")
local admin = require (wolfa_getLuaPath()..".admin.admin")
local auth = require (wolfa_getLuaPath()..".auth.auth") local auth = require (wolfa_getLuaPath()..".auth.auth")
local teams = require (wolfa_getLuaPath()..".game.teams") local teams = require (wolfa_getLuaPath()..".game.teams")
@ -28,6 +26,7 @@ local players = require (wolfa_getLuaPath()..".players.players")
local util = require (wolfa_getLuaPath()..".util.util") local util = require (wolfa_getLuaPath()..".util.util")
local events = require (wolfa_getLuaPath()..".util.events") local events = require (wolfa_getLuaPath()..".util.events")
local files = require (wolfa_getLuaPath()..".util.files") local files = require (wolfa_getLuaPath()..".util.files")
local settings = require (wolfa_getLuaPath()..".util.settings")
local commands = {} local commands = {}
@ -115,16 +114,6 @@ function commands.load()
end end
function commands.log(clientId, command, cmdArguments) function commands.log(clientId, command, cmdArguments)
local functionStart = et.trap_Milliseconds()
local fileDescriptor = files.open(et.trap_Cvar_Get("g_logAdmin"), et.FS_APPEND)
local logLine
local levelTime = et.trap_Milliseconds() / 1000
local clientGUID = clientId and players.getGUID(clientId) or "XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX"
local clientName = clientId and players.getName(clientId) or "console"
local clientFlags = ""
local victimId local victimId
-- funny, NoQuarter actually checks EACH command for a victim (so even -- funny, NoQuarter actually checks EACH command for a victim (so even
@ -143,16 +132,35 @@ function commands.log(clientId, command, cmdArguments)
victimId = cmdClient victimId = cmdClient
end end
end end
if victimId then local fileDescriptor = files.open(settings.get("g_logAdmin"), et.FS_APPEND)
local victimName = players.getName(victimId)
logLine = string.format("%3i:%02f: %i: %s: %s: %s: %s: %s: %s: \"%s\"\n", math.floor(levelTime / 60), (levelTime % 60), clientId, clientGUID, clientName, clientFlags, command, victimId, victimName, table.concat(cmdArguments, " ", 2)) local logLine
local clientGUID = clientId and players.getGUID(clientId) or "XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX"
local clientName = clientId and players.getName(clientId) or "console"
local clientFlags = ""
if settings.get("g_standalone") == 1 then
if victimId then
local victimName = players.getName(victimId)
logLine = string.format("[%s] %s: %s: %s: %s: \"%s\"\n", os.date("%Y-%m-%d %H:%M:%S"), clientGUID, clientName, command, victimName, table.concat(cmdArguments, " ", 2))
else
logLine = string.format("[%s] %s: %s: %s: \"%s\"\n", os.date("%Y-%m-%d %H:%M:%S"), clientGUID, clientName, command, table.concat(cmdArguments, " "))
end
else else
logLine = string.format("%3i:%02f: %i: %s: %s: %s: %s: \"%s\"\n", math.floor(levelTime / 60), (levelTime % 60), clientId, clientGUID, clientName, clientFlags, command, table.concat(cmdArguments, " ")) local levelTime = et.trap_Milliseconds() / 1000
if victimId then
local victimName = players.getName(victimId)
logLine = string.format("%3i:%02f: %i: %s: %s: %s: %s: %s: %s: \"%s\"\n", math.floor(levelTime / 60), (levelTime % 60), clientId, clientGUID, clientName, clientFlags, command, victimId, victimName, table.concat(cmdArguments, " ", 2))
else
logLine = string.format("%3i:%02f: %i: %s: %s: %s: %s: \"%s\"\n", math.floor(levelTime / 60), (levelTime % 60), clientId, clientGUID, clientName, clientFlags, command, table.concat(cmdArguments, " "))
end
end end
et.trap_FS_Write(logLine, string.len(logLine), fileDescriptor) et.trap_FS_Write(logLine, string.len(logLine), fileDescriptor)
et.trap_FS_FCloseFile(fileDescriptor) et.trap_FS_FCloseFile(fileDescriptor)
end end

View file

@ -21,6 +21,7 @@ local events = require (wolfa_getLuaPath()..".util.events")
local settings = {} local settings = {}
local data = { local data = {
["g_logAdmin"] = "admin.log",
["g_fileGreetings"] = "greetings.cfg", ["g_fileGreetings"] = "greetings.cfg",
["g_fileRules"] = "rules.cfg", ["g_fileRules"] = "rules.cfg",
["g_fileSprees"] = "sprees.cfg", ["g_fileSprees"] = "sprees.cfg",