Skip to content

Commit

Permalink
feat(logger): add fivemanage logging service
Browse files Browse the repository at this point in the history
  • Loading branch information
thelindat committed Jun 17, 2024
1 parent 0691160 commit 5697326
Show file tree
Hide file tree
Showing 4 changed files with 67 additions and 14 deletions.
6 changes: 2 additions & 4 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -57,12 +57,10 @@ jobs:
- name: Bundle files
run: |
mkdir -p ./temp/oxmysql
mkdir -p ./temp/oxmysql/web/
mkdir -p ./temp/oxmysql/lib/
mkdir -p ./temp/oxmysql/{web,lib}
cp ./{LICENSE,README.md,fxmanifest.lua,ui.lua} ./temp/oxmysql
cp ./lib/MySQL.lua ./temp/oxmysql/lib
cp -r ./dist ./temp/oxmysql
cp -r ./dist ./logger ./temp/oxmysql
cp -r ./web/build ./temp/oxmysql/web/
cd ./temp && zip -r ../oxmysql.zip ./oxmysql
Expand Down
18 changes: 9 additions & 9 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,13 @@ A FiveM resource to communicate with a MySQL database using [node-mysql2](https:
![](https://img.shields.io/github/contributors/overextended/oxmysql?logo=github)
![](https://img.shields.io/github/v/release/overextended/oxmysql?logo=github)

## 📚 Documentation

https://overextended.dev/oxmysql

## 💾 Download

https://github.com/overextended/oxmysql/releases/latest/download/oxmysql.zip
## 🔗 Links
- 💾 [Download](https://github.com/overextended/oxmysql/releases/latest/download/oxmysql.zip)
- Download the latest release directly.
- 📚 [Documentation](https://overextended.dev/oxmysql)
- For installation, setup, and everything else.
- 📦 [npm](https://www.npmjs.com/package/@overextended/oxmysql)
- Use our npm package for enhanced functionality and TypeScript support.

## ✨ Features

Expand All @@ -24,9 +24,9 @@ https://github.com/overextended/oxmysql/releases/latest/download/oxmysql.zip
- Support for URI connection strings and semicolon separated values.
- Improved parameter checking and error handling.

## npm Package
## 🧾 Logging

https://www.npmjs.com/package/@overextended/oxmysql
We have included a module for submitting error logs to [Fivemanage](https://fivemanage.com/?ref=overextended), a cloud management service tailored for game servers. Additional logging options and support for other services will be available in the future.

## Lua Language Server

Expand Down
5 changes: 4 additions & 1 deletion build.js
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,10 @@ dependencies {
}
client_script 'ui.lua'
server_script 'dist/build.js'
server_scripts {
'dist/build.js',
'logger/fivemanage.js'
}
files {
'web/build/index.html',
Expand Down
52 changes: 52 additions & 0 deletions logger/fivemanage.js
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);

0 comments on commit 5697326

Please sign in to comment.