Skip to content

Commit

Permalink
feat(imports/logger): add fivemanage as logging option (#536)
Browse files Browse the repository at this point in the history
  • Loading branch information
itschip authored Apr 6, 2024
1 parent e476736 commit eb31c4d
Showing 1 changed file with 47 additions and 0 deletions.
47 changes: 47 additions & 0 deletions imports/logger/server.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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("[\'\"]", '')

Expand Down

0 comments on commit eb31c4d

Please sign in to comment.