Skip to content

Commit

Permalink
feat: logging backwards compat
Browse files Browse the repository at this point in the history
  • Loading branch information
solareon committed Dec 6, 2023
1 parent 98e3967 commit e9695d9
Show file tree
Hide file tree
Showing 3 changed files with 42 additions and 3 deletions.
21 changes: 21 additions & 0 deletions bridge/qb/server/events.lua
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
local config = require 'config.server'
local logger = require 'modules.logger'

-- Vehicles
RegisterServerEvent('baseevents:enteringVehicle', function(veh, seat, modelName, netId)
local src = source
Expand Down Expand Up @@ -38,4 +41,22 @@ RegisterServerEvent('baseevents:leftVehicle', function(veh, seat, modelName, net
event = 'Left'
}
TriggerClientEvent('QBCore:Client:VehicleInfo', src, data)
end)

---Compatability event for logging
---@param name string source of the log. Usually a playerId or name of a script.
---@param title string the action or 'event' being logged. Usually a verb describing what the name is doing. Example: SpawnVehicle
---@param message string the message attached to the log
---@param color? string what color the message should be
---@param tagEveryone? boolean Whether a role tag should be applied to this log. Uses config variable for logging role
---@deprecated use logger module from qbx_core
RegisterNetEvent('qb-log:server:CreateLog', function(name, title, color, message, tagEveryone)
logger.log({
source = GetInvokingResource() or "qbx_core",
webhook = name,
event = title,
message = message,
color = color,
tags = tagEveryone and config.logging.role or nil
})
end)
14 changes: 14 additions & 0 deletions config/server.lua
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,20 @@ return {
end
},
},
logging = {
enableOxLogging = false,
enableWebhooks = false,
webhook = {
['default'] = '', -- default
['joinleave'] = '', -- default
['ooc'] = '', -- default
['anticheat'] = '', -- default
['playermoney'] = '', -- default
},
role = {
'@everyone' --Role to tag for logging data. Roles use <@%roleid> and users/channels are <@userid/channelid>
}
},

giveVehicleKeys = function(src, plate)
return exports.qbx_vehiclekeys:GiveKeys(src, plate)
Expand Down
10 changes: 7 additions & 3 deletions modules/logger.lua
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
local config = require 'config.server'
local isServer = IsDuplicityVersion()
if not isServer then
lib.print.error('cannot use the logger on the client')
Expand Down Expand Up @@ -43,7 +44,7 @@ local allowedErr = {
}

---Log Queue
---@param payload Log Queue
---@param payload DiscordLog Queue
local function logPayload(payload)
local tags
local username = 'QBX Logs'
Expand Down Expand Up @@ -104,6 +105,7 @@ end
---@field webhook string url of the webhook this log should send to
---@field color? string what color the message should be
---@field tags? string[] tags in discord. Example: ['@admin', '@everyone']
---@field embed table formatted embed table for discord webhook

---Creates a discord log
---@param log DiscordLog
Expand Down Expand Up @@ -145,10 +147,12 @@ end
---Creates a log using either ox_lib logger, discord webhooks depending on convar
---@param log Log
local function createLog(log)
if log.webhook then
if config.logging.enableWebhooks then
log.webhook = config.logging.webhook[log.webhook] or nil
---@diagnostic disable-next-line: param-type-mismatch
discordLog(log)
else
end
if config.logging.enableOxLogging then
lib.logger(log.source, log.event, log.message)
end
end
Expand Down

0 comments on commit e9695d9

Please sign in to comment.