Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
- Improved support for message replies and allowed mentions
- Added client statistics (latency, uptime, etc)
- Loggers, including the client's default logger, can now be configured at runtime (you can toggle the colors, too)
- HTTP errors now log the full message (can be disabled in client options)
- Most previously raw tables are now available as rich classes or structs
- Added many direct client methods (e.g. `client:createMessage(channelId, ...)` can be used as an alternative to `channel:send(...)`, which uses the former internally)
- In addition to the methods above, added "modify" methods for batch-patching objects (e.g. `channel:modify(payload)`)
Expand Down Expand Up @@ -192,6 +193,7 @@
- Added `defaultImageSize`
- Added `defaultAllowedMentions`
- Added `logColors`
- Added `logFullErrors`
- Added `status`
- Added `activity`
- Renamed `shardCount` to `totalShardCount`
Expand Down
11 changes: 8 additions & 3 deletions libs/client/API.lua
Original file line number Diff line number Diff line change
Expand Up @@ -94,8 +94,8 @@ function API:setToken(token)
end
end

function API:log(level, res, method, url)
return self._client:log(level, '%i - %s : %s %s', res.code, res.reason, method, url)
function API:log(level, res, method, url, extra)
return self._client:log(level, '%i - %s : %s %s%s', res.code, res.reason, method, url, extra or "")
end

function API:request(method, endpoint, params, query, payload, files)
Expand Down Expand Up @@ -242,7 +242,12 @@ function API:commit(method, url, req, payload, route, retries)
msg = parseErrors({msg}, data.errors, 'payload')
end

self:log('error', res, method, url)
if client.logFullErrors then
self:log('error', res, method, url, "\n" .. msg)
else
self:log('error', res, method, url)
end

return nil, msg, delay

end
Expand Down
6 changes: 6 additions & 0 deletions libs/client/Client.lua
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,7 @@ local defaultOptions = {
dateFormat = {'%F %T', function(o) return checkType('string', o) end},
logFile = {'discordia.log', function(o) return checkType('string', o) end},
logColors = {true, function(o) return checkType('boolean', o) end},
logFullErrors = {false, function(o) return checkType('boolean', o) end},
status = {nil, function(o) return checkEnum(enums.status, o) end},
activity = {nil, checkActivity},
}
Expand All @@ -116,6 +117,7 @@ function Client:__init(options)
self._defaultAllowedMentions = options.defaultAllowedMentions
self._defaultBitrate = options.defaultBitrate
self._logger = Logger(options.logLevel, options.dateFormat, options.logFile, options.logColors)
self._logFullErrors = options.logFullErrors
self._api = API(self)
self._cdn = CDN(self)
self._state = State(self)
Expand Down Expand Up @@ -495,6 +497,10 @@ function get:logger()
return self._logger
end

function get:logFullErrors()
return self._logFullErrors
end

function get:token()
return self._token
end
Expand Down