mirror of
https://github.com/darksaid98/oxmysql.git
synced 2026-12-02 22:22:50 +00:00
refactor(logger): dynamically load logger service
This commit is contained in:
1 parent
f005a2f200
commit
9920ae7ffe
4 files changed
+31
-27
No files matched your search
+7
-21
@@ -1,16 +1,17 @@
|
||||
// https://fivemanage.com/?ref=overextended
|
||||
|
||||
const apiKey = GetConvar('FIVEMANAGE_LOGS_API_KEY', '');
|
||||
const endpoint = 'https://api.fivemanage.com/api/logs/batch';
|
||||
|
||||
if (!apiKey) return console.warning(`convar "FIVEMANAGE_LOGS_API_KEY" has not been set`);
|
||||
|
||||
const batchedLogs = [];
|
||||
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);
|
||||
@@ -30,23 +31,8 @@ async function sendLogs() {
|
||||
}
|
||||
}
|
||||
|
||||
async function logger(level, resource, message, metadata) {
|
||||
if (!apiKey) return;
|
||||
|
||||
return function logger(data) {
|
||||
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);
|
||||
batchedLogs.push(data);
|
||||
};
|
||||
Reference in new issue
Block a user