From daaadc490cdac18f19abaf0b33628723e2364914 Mon Sep 17 00:00:00 2001 From: Linden <65407488+thelindat@users.noreply.github.com> Date: Tue, 1 Oct 2024 10:57:44 +1000 Subject: [PATCH] feat(logger): support loading external loggers --- src/logger/index.ts | 20 ++++++++++++++++++-- 1 file changed, 18 insertions(+), 2 deletions(-) diff --git a/src/logger/index.ts b/src/logger/index.ts index eb22d52..fbf9410 100644 --- a/src/logger/index.ts +++ b/src/logger/index.ts @@ -2,8 +2,24 @@ import { mysql_debug, mysql_log_size, mysql_slow_query_warning, mysql_ui } from import type { CFXCallback, CFXParameters } from '../types'; import { dbVersion } from '../database'; -const loggerService = GetConvar('mysql_logger_service', ''); -export const logger = new Function(LoadResourceFile('oxmysql', `logger/${loggerService}.js`))() || (() => {}); +let loggerResource = ''; +let loggerService = GetConvar('mysql_logger_service', ''); + +if (loggerService) { + if (loggerService.startsWith('@')) { + const [resource, ...path] = loggerService.slice(1).split('/'); + + if (resource && path) { + loggerResource = resource; + loggerService = path.join('/'); + } + } else loggerService = `logger/${loggerService}`; +} + +export const logger = + (loggerService && + new Function(LoadResourceFile(loggerResource || GetCurrentResourceName(), `${loggerService}.js`))()) || + (() => {}); export function logError( invokingResource: string,