feat: add logging functionality with LoggerService; implement log entity and controller; enhance query processing with logging support
This commit is contained in:
@ -1,7 +1,10 @@
|
||||
import { TLogType } from "./../query/logger/logger.types";
|
||||
import * as ivm from "isolated-vm";
|
||||
import { VModule } from "./module.class";
|
||||
import { Plugin } from "./plugin.class";
|
||||
import { QueryResponse } from "./vm.constants";
|
||||
import { TLog } from "src/query/logger/logger.types";
|
||||
import { LoggerService } from "src/query/logger/logger.service";
|
||||
|
||||
export class Vm {
|
||||
private memoryLimit: number;
|
||||
@ -83,7 +86,8 @@ export class Vm {
|
||||
async runScript(
|
||||
script: string,
|
||||
args: Record<string, any>,
|
||||
headers: Record<string, any>
|
||||
headers: Record<string, any>,
|
||||
log: TLog
|
||||
): Promise<QueryResponse> {
|
||||
let resolvePromise: (value: any) => void;
|
||||
let rejectPromise: (reason?: any) => void;
|
||||
@ -94,14 +98,29 @@ export class Vm {
|
||||
});
|
||||
|
||||
this.setFunction("returnResult", (res) => {
|
||||
console.log("Returning result from VM:", res);
|
||||
|
||||
resolvePromise(res);
|
||||
resolvePromise({ ...res, log });
|
||||
});
|
||||
|
||||
// TODO: log
|
||||
this.setFunction("log", (...args) => {
|
||||
console.log("vm log:", args);
|
||||
if (!log) {
|
||||
return;
|
||||
}
|
||||
|
||||
const logType = args.find(
|
||||
(arg) =>
|
||||
arg &&
|
||||
typeof arg === "object" &&
|
||||
arg.type &&
|
||||
Object.values(TLogType).includes(arg.type)
|
||||
);
|
||||
|
||||
log = LoggerService.log(log, {
|
||||
content: args
|
||||
.map((arg) => (typeof arg === "string" ? arg : JSON.stringify(arg)))
|
||||
.join(" "),
|
||||
type: logType?.type || TLogType.info,
|
||||
timeStamp: new Date().getTime(),
|
||||
});
|
||||
});
|
||||
|
||||
this.setFunction("error", (error: any) => {
|
||||
|
||||
Reference in New Issue
Block a user