feat(imports/logger): add fivemanage as logging option (#536)

This commit is contained in:
Christopher
2024-04-06 15:43:38 +02:00
committed by GitHub
parent e476736761
commit eb31c4d83c

View File

@@ -84,6 +84,53 @@ local function formatTags(source, tags)
return tags
end
if service == 'fivemanage' then
local key = GetConvar('fivemanage:key', '')
if key ~= '' then
local endpoint = 'https://api.fivemanage.com/api/logs/batch'
local headers = {
['Content-Type'] = 'application/json',
['Authorization'] = key,
['User-Agent'] = 'ox_lib'
}
function lib.logger(source, event, message, ...)
if not buffer then
buffer = {}
SetTimeout(500, function()
PerformHttpRequest(endpoint, function(status, _, _, response)
if status ~= 200 then
if type(response) == 'string' then
response = json.decode(response) or response
badResponse(endpoint, status, response)
end
end
end, 'POST', json.encode(buffer), headers)
buffer = nil
bufferSize = 0
end)
end
bufferSize += 1
buffer[bufferSize] = {
level = "info",
message = message,
resource = cache.resource,
metadata = {
hostname = hostname,
service = event,
source = source,
tags = formatTags(source, ... and string.strjoin(',', string.tostringall(...)) or nil),
}
}
end
end
end
if service == 'datadog' then
local key = GetConvar('datadog:key', ''):gsub("[\'\"]", '')