-
-
Notifications
You must be signed in to change notification settings - Fork 196
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #232 from overextended/dev
- Loading branch information
Showing
22 changed files
with
1,206 additions
and
799 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
// https://fivemanage.com/?ref=overextended | ||
|
||
const apiKey = GetConvar('FIVEMANAGE_LOGS_API_KEY', ''); | ||
const endpoint = 'https://api.fivemanage.com/api/logs/batch'; | ||
|
||
const headers = { | ||
['Content-Type']: 'application/json', | ||
['Authorization']: apiKey, | ||
['User-Agent']: 'oxmysql', | ||
}; | ||
|
||
const batchedLogs = []; | ||
|
||
async function sendLogs() { | ||
try { | ||
const body = JSON.stringify(batchedLogs); | ||
batchedLogs.length = 0; | ||
|
||
const response = await fetch(endpoint, { | ||
method: 'POST', | ||
body: body, | ||
headers: headers, | ||
}); | ||
|
||
if (response.ok) return; | ||
|
||
console.error(`Failed to submit logs to fivemanage - ${response.status} ${response.statusText}`); | ||
} catch (err) { | ||
console.error(err); | ||
} | ||
} | ||
|
||
async function logger(level, resource, message, metadata) { | ||
if (!apiKey) return; | ||
|
||
if (batchedLogs.length === 0) setTimeout(sendLogs, 500); | ||
|
||
batchedLogs.push({ | ||
level: level, | ||
message: message, | ||
resource: resource, | ||
metadata: metadata, | ||
}); | ||
} | ||
|
||
function errorEvent(data) { | ||
delete data.err.sqlMessage; | ||
logger('error', data.resource, `${data.resource} was unable to execute a query!`, data.err); | ||
} | ||
|
||
on('oxmysql:error', errorEvent); | ||
on('oxmysql:transaction-error', errorEvent); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.