diff --git a/packages/nocodb/src/Noco.ts b/packages/nocodb/src/Noco.ts index a10c00647d..56ab6032b2 100644 --- a/packages/nocodb/src/Noco.ts +++ b/packages/nocodb/src/Noco.ts @@ -9,7 +9,7 @@ import dotenv from 'dotenv'; import { IoAdapter } from '@nestjs/platform-socket.io'; import requestIp from 'request-ip'; import cookieParser from 'cookie-parser'; -import { Logger } from '@nestjs/common'; +import type { INestApplication } from '@nestjs/common'; import type { MetaService } from '~/meta/meta.service'; import type { IEventEmitter } from '~/modules/event-emitter/event-emitter.interface'; import type { Express } from 'express'; @@ -21,17 +21,16 @@ import { isEE } from '~/utils'; dotenv.config(); export default class Noco { - private static _this: Noco; - private static ee: boolean; + protected static _this: Noco; + protected static ee: boolean; public static readonly env: string = '_noco'; - private static _httpServer: http.Server; - private static _server: Express; - private static logger = new Logger(Noco.name); + protected static _httpServer: http.Server; + protected static _server: Express; public static get dashboardUrl(): string { const siteUrl = `http://localhost:${process.env.PORT || 8080}`; - return `${siteUrl}${Noco._this?.config?.dashboardPath}`; + return `${siteUrl}${this._this?.config?.dashboardPath}`; } public static config: any; @@ -43,8 +42,8 @@ export default class Noco { public readonly metaMgrv2: any; public env: string; - private config: any; - private requestContext: any; + protected config: any; + protected requestContext: any; constructor() { process.env.PORT = process.env.PORT || '8080'; @@ -82,22 +81,26 @@ export default class Noco { } public static getConfig(): any { - return Noco.config; + return this.config; } public static isEE(): boolean { - return Noco.ee || process.env.NC_CLOUD === 'true'; + return this.ee || process.env.NC_CLOUD === 'true'; } public static async loadEEState(): Promise { try { - return (Noco.ee = isEE); + return (this.ee = isEE); } catch {} - return (Noco.ee = false); + return (this.ee = false); } static async init(param: any, httpServer: http.Server, server: Express) { - const nestApp = await NestFactory.create(AppModule); + const nestApp = await NestFactory.create(AppModule, { + bufferLogs: true, + }); + this.initCustomLogger(nestApp); + nestApp.flushLogs(); if (process.env.NC_WORKER_CONTAINER === 'true') { if (!process.env.NC_REDIS_URL) { @@ -136,23 +139,23 @@ export default class Noco { } public static get httpServer(): http.Server { - return Noco._httpServer; + return this._httpServer; } public static get server(): Express { - return Noco._server; + return this._server; } public static async initJwt(): Promise { if (this.config?.auth?.jwt) { if (!this.config.auth.jwt.secret) { let secret = ( - await Noco._ncMeta.metaGet('', '', MetaTable.STORE, { + await this._ncMeta.metaGet('', '', MetaTable.STORE, { key: 'nc_auth_jwt_secret', }) )?.value; if (!secret) { - await Noco._ncMeta.metaInsert('', '', MetaTable.STORE, { + await this._ncMeta.metaInsert('', '', MetaTable.STORE, { key: 'nc_auth_jwt_secret', value: (secret = uuidv4()), }); @@ -167,16 +170,20 @@ export default class Noco { } } let serverId = ( - await Noco._ncMeta.metaGet('', '', MetaTable.STORE, { + await this._ncMeta.metaGet('', '', MetaTable.STORE, { key: 'nc_server_id', }) )?.value; if (!serverId) { - await Noco._ncMeta.metaInsert('', '', MetaTable.STORE, { + await this._ncMeta.metaInsert('', '', MetaTable.STORE, { key: 'nc_server_id', value: (serverId = T.id), }); } process.env.NC_SERVER_UUID = serverId; } + + protected static initCustomLogger(_nestApp: INestApplication) { + // setup custom logger for nestjs if needed + } } diff --git a/packages/nocodb/src/filters/global-exception/global-exception.filter.ts b/packages/nocodb/src/filters/global-exception/global-exception.filter.ts index 9c40d418ef..1933b66e08 100644 --- a/packages/nocodb/src/filters/global-exception/global-exception.filter.ts +++ b/packages/nocodb/src/filters/global-exception/global-exception.filter.ts @@ -43,7 +43,7 @@ export class GlobalExceptionFilter implements ExceptionFilter { exception instanceof ThrottlerException ) ) - this.logger.error(exception.message, exception.stack); + this.logError(exception, request); if (exception instanceof ThrottlerException) { this.logger.log( @@ -118,4 +118,8 @@ export class GlobalExceptionFilter implements ExceptionFilter { protected captureException(exception: any, _request: any) { this.sentryClient?.instance().captureException(exception); } + + protected logError(exception: any, _request: any) { + this.logger.error(exception.message, exception.stack); + } }