Skip to content

Commit

Permalink
feat: logs using ox_lib if possible in addition to discord logging, i…
Browse files Browse the repository at this point in the history
…nstead of either or

* feat: logging backwards compat

* style: documentation

* fix: enable fallback webhook log to default

* style: tightly scope configuration

* refactor: logging config for core events only

* refactor: remove compat event

* style: documentation

Co-authored-by: Manason <clanerp@gmail.com>

* style: documentation

* refactor: remove core event log config

* refactor: hit save before commit

* style: move class definition

* style: documentation update

---------

Co-authored-by: Manason <clanerp@gmail.com>
  • Loading branch information
solareon and Manason committed Dec 9, 2023
1 parent 806527d commit a37a531
Showing 1 changed file with 10 additions and 14 deletions.
24 changes: 10 additions & 14 deletions modules/logger.lua
Original file line number Diff line number Diff line change
Expand Up @@ -42,8 +42,13 @@ local allowedErr = {
[304] = true
}

---@class DiscordLog
---@field webhook string url of the webhook this log should send to
---@field tags? string[] tags in discord. Example: {'<@%roleid>', '@everyone'}
---@field embed table formatted embed table for discord webhook

---Log Queue
---@param payload Log Queue
---@param payload DiscordLog Queue
local function logPayload(payload)
local tags
local username = 'QBX Logs'
Expand Down Expand Up @@ -97,16 +102,8 @@ local function processLogQueue()
end
end

---@class DiscordLog
---@field source string source of the log. Usually a playerId or name of a resource.
---@field event string the action or 'event' being logged. Usually a verb describing what the name is doing. Example: SpawnVehicle
---@field message string the message attached to the log
---@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']

---Creates a discord log
---@param log DiscordLog
---@param log Log
local function discordLog(log)
local embedData = {
{
Expand Down Expand Up @@ -140,17 +137,16 @@ end
---@field message string the message attached to the log
---@field webhook? string Discord logs only. url of the webhook this log should send to
---@field color? string Discord logs only. what color the message should be
---@field tags? string[] Discord logs only. tags in discord. Example: ['@admin', '@everyone']
---@field tags? string[] Discord logs only. tags in discord. Example: {'<@%roleid>', '@everyone'}

---Creates a log using either ox_lib logger, discord webhooks depending on convar
---Logs using ox_lib if ox_lib logging is configured. Additionally logs to discord if a web hook is passed.
---@param log Log
local function createLog(log)
if log.webhook then
---@diagnostic disable-next-line: param-type-mismatch
discordLog(log)
else
lib.logger(log.source, log.event, log.message)
end
lib.logger(log.source, log.event, log.message) -- oxlib fails silently if logging isn't setup correctly.
end

return {
Expand Down

0 comments on commit a37a531

Please sign in to comment.