Skip to content

Commit

Permalink
feat(logger): support loading external loggers
Browse files Browse the repository at this point in the history
  • Loading branch information
thelindat committed Oct 1, 2024
1 parent 5b76dcb commit daaadc4
Showing 1 changed file with 18 additions and 2 deletions.
20 changes: 18 additions & 2 deletions src/logger/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down

0 comments on commit daaadc4

Please sign in to comment.