Skip to content
This repository has been archived by the owner on Feb 8, 2024. It is now read-only.

Commit

Permalink
allow additional data to logging
Browse files Browse the repository at this point in the history
  • Loading branch information
geramy92 committed Apr 7, 2020
1 parent d169af5 commit 653b162
Show file tree
Hide file tree
Showing 6 changed files with 24 additions and 11 deletions.
1 change: 1 addition & 0 deletions scripts/tools/copyErrorsToGithub.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
`time` INT NOT NULL ,
`user` VARCHAR(255) NOT NULL ,
`stacktrace` TEXT NOT NULL ,
`additionalData` TEXT NOT NULL ,
`level` VARCHAR(50) NOT NULL ,
`logType` VARCHAR(15) NOT NULL ,
`file` TEXT NOT NULL ,
Expand Down
14 changes: 11 additions & 3 deletions scripts/tools/issueDbFunctions.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
time: number,
user: string,
stacktrace: string,
additionalData: string,
level: string,
logType: string,
file: string}} issueData
Expand Down Expand Up @@ -37,6 +38,7 @@ WHERE
time: number,
user: string,
stacktrace: string,
additionalData: string,
level: string,
logType: string,
file: string}} issueData
Expand Down Expand Up @@ -68,6 +70,7 @@ WHERE
time: number,
user: string,
stacktrace: string,
additionalData: string,
level: string,
logType: string,
file: string}} issueData
Expand All @@ -76,13 +79,13 @@ WHERE
exports.writeIssueToDatabase = async (issueData) => {
const rows = await db.query(`
INSERT INTO log_errors_to_github (
message, line, time, user, stacktrace, level, logType, file
message, line, time, user, stacktrace, level, logType, file, additionalData
)
VALUES (?,?,?,?,?,?,?,?);
VALUES (?,?,?,?,?,?,?,?,?);
`, [
issueData.message, issueData.line, (issueData.time /1000),
issueData.user, issueData.stacktrace, issueData.level, issueData.logType,
issueData.file
issueData.file, JSON.stringify(issueData.additionalData, null,4)
]);


Expand Down Expand Up @@ -134,6 +137,7 @@ WHERE ID = ?
user: string,
stacktrace: string,
level: string,
additionalData: string,
logType: string,
file: string}} issueData
*/
Expand Down Expand Up @@ -163,6 +167,10 @@ ${stackmark}
- Source: ${issueData.file}:${issueData.line}
- LogType: ${issueData.logType}
- Appeared at User: ${issueData.user}
- Stacktrace:
${stackmark}
${JSON.stringify(issueData.additionalData, null,4)}
${stackmark}
${oldGithubText}
`,
Expand Down
3 changes: 2 additions & 1 deletion terratex_reallife/SYSTEM/logging/debug_log_client.lua
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,8 @@ end)
--- 3: Information message.
---
---@param message string - message
function logMessageWithStackTrace(level, message)
---@param additionalData table - table with additionalData
function logMessageWithStackTrace(level, message, additionalData)
local callInfo = debug.getinfo(2);

triggerLatentServerEvent ( "store_client_debug", 5000, true, getLocalPlayer(), getRealTime(), message, level, callInfo.source, callInfo.linedefined, debug.traceback())
Expand Down
4 changes: 2 additions & 2 deletions terratex_reallife/SYSTEM/logging/debug_log_server.lua
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
function store_client_debug_func(time, message, level, file, line, stacktrace)
function store_client_debug_func(time, message, level, file, line, stacktrace, data)
addLogEntryToBulkFileWriter(getPlayerName(client), time, message, level, file, line)
storeLogEntriesAsjson(message, level, file, line, time, stacktrace, getPlayerName(client))
storeLogEntriesAsjson(message, level, file, line, time, stacktrace, getPlayerName(client), data)
end
addEvent("store_client_debug", true)
addEventHandler ( "store_client_debug", getRootElement(), store_client_debug_func, true, "low" )
Expand Down
6 changes: 4 additions & 2 deletions terratex_reallife/SYSTEM/logging/json_logger.lua
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,8 @@ local lastBulkTable = {}
---@param time table getRealTime()
---@param stacktrace string stacktrace
---@param user userdata|nil User or not if it is serversided
function storeLogEntriesAsjson(message, level, file, line, time, stacktrace, user)
---@param additionalData table|nil Additional Data to store
function storeLogEntriesAsjson(message, level, file, line, time, stacktrace, user, additionalData)
local logType = "client"
if (not user) then
user = "server"
Expand All @@ -36,7 +37,8 @@ function storeLogEntriesAsjson(message, level, file, line, time, stacktrace, use
time = time.timestamp * 1000,
stacktrace = stacktrace,
user = user,
logType = logType
logType = logType,
additionalData = additionalData
}) .. "\n";

table.insert(currentBulkTable, json);
Expand Down
7 changes: 4 additions & 3 deletions terratex_reallife/SYSTEM/logging/logging_server_func.lua
Original file line number Diff line number Diff line change
Expand Up @@ -6,16 +6,17 @@
--- 3: Information message.
---
---@param message string - message
function logMessageWithStackTrace(level, message)
---@param additionalData table - table with additional data stuff
function logMessageWithStackTrace(level, message, additionalData)
local callInfo = debug.getinfo(2);
local stackTrace = debug.traceback();
storeLogEntriesAsjson(message, level, callInfo.source, callInfo.linedefined, getRealTime(), stackTrace)
storeLogEntriesAsjson(message, level, callInfo.source, callInfo.linedefined, getRealTime(), stackTrace, additionalData)
end

addEventHandler("onDebugMessage", getRootElement(),
function(message, level, file, line)
local stackTrace = debug.traceback();
storeLogEntriesAsjson(message, level, file, line, getRealTime(), stackTrace)
storeLogEntriesAsjson(message, level, file, line, getRealTime(), stackTrace, nil, {})
end)

LOG_LEVEL = {
Expand Down

0 comments on commit 653b162

Please sign in to comment.