mirror of
https://github.com/CommunityOx/ox_lib.git
synced 2026-08-17 06:56:03 +01:00
feat(server/logger): add player data to tags
This commit is contained in:
@@ -7,6 +7,12 @@ local function badResponse(endpoint, response)
|
|||||||
print(('unable to submit logs to %s\n%s'):format(endpoint, json.encode(response, { indent = true })))
|
print(('unable to submit logs to %s\n%s'):format(endpoint, json.encode(response, { indent = true })))
|
||||||
end
|
end
|
||||||
|
|
||||||
|
local playerData = {}
|
||||||
|
|
||||||
|
AddEventHandler('playerDropped', function()
|
||||||
|
playerData[source] = nil
|
||||||
|
end)
|
||||||
|
|
||||||
if service == 'datadog' then
|
if service == 'datadog' then
|
||||||
local key = GetConvar('datadog:key', ''):gsub("[\'\"]", '')
|
local key = GetConvar('datadog:key', ''):gsub("[\'\"]", '')
|
||||||
|
|
||||||
@@ -18,6 +24,37 @@ if service == 'datadog' then
|
|||||||
['DD-API-KEY'] = key,
|
['DD-API-KEY'] = key,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
local function formatTags(source, tags)
|
||||||
|
if type(source) == 'number' and source > 0 then
|
||||||
|
local data = playerData[source]
|
||||||
|
|
||||||
|
if not data then
|
||||||
|
local _data = {
|
||||||
|
('username:%s'):format(GetPlayerName(source))
|
||||||
|
}
|
||||||
|
|
||||||
|
local num = 1
|
||||||
|
|
||||||
|
---@cast source string
|
||||||
|
for i = 0, GetNumPlayerIdentifiers(source) - 1 do
|
||||||
|
local identifier = GetPlayerIdentifier(source, i)
|
||||||
|
|
||||||
|
if not identifier:find('ip') then
|
||||||
|
num += 1
|
||||||
|
_data[num] = identifier
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
data = table.concat(_data, ',')
|
||||||
|
playerData[source] = data
|
||||||
|
end
|
||||||
|
|
||||||
|
tags = tags and ('%s,%s'):format(tags, data) or data
|
||||||
|
end
|
||||||
|
|
||||||
|
return tags
|
||||||
|
end
|
||||||
|
|
||||||
function lib.logger(source, event, message, ...)
|
function lib.logger(source, event, message, ...)
|
||||||
if not buffer then
|
if not buffer then
|
||||||
buffer = {}
|
buffer = {}
|
||||||
@@ -41,7 +78,7 @@ if service == 'datadog' then
|
|||||||
message = message,
|
message = message,
|
||||||
resource = cache.resource,
|
resource = cache.resource,
|
||||||
ddsource = tostring(source),
|
ddsource = tostring(source),
|
||||||
ddtags = string.strjoin(',', string.tostringall(...))
|
ddtags = formatTags(source, ... and string.strjoin(',', string.tostringall(...)) or nil),
|
||||||
}
|
}
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|||||||
Reference in New Issue
Block a user