mirror of
https://github.com/CommunityOx/ox_lib.git
synced 2026-08-19 07:56:02 +01:00
feat(imports/logger): add fivemanage as logging option (#536)
This commit is contained in:
@@ -84,6 +84,53 @@ local function formatTags(source, tags)
|
|||||||
return tags
|
return tags
|
||||||
end
|
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
|
if service == 'datadog' then
|
||||||
local key = GetConvar('datadog:key', ''):gsub("[\'\"]", '')
|
local key = GetConvar('datadog:key', ''):gsub("[\'\"]", '')
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user