diff --git a/src/components/database/index.ts b/src/components/database/index.ts index a59b3342f..d47032c62 100644 --- a/src/components/database/index.ts +++ b/src/components/database/index.ts @@ -5,8 +5,7 @@ import { TypesenseSearchParams } from '../../@types/index.js' import { LOG_LEVELS_STR, configureCustomDBTransport, - GENERIC_EMOJIS, - USE_DB_TRANSPORT + GENERIC_EMOJIS } from '../../utils/logging/Logger.js' import { DATABASE_LOGGER } from '../../utils/logging/common.js' import { validateObject } from '../core/utils/validateDdoHandler.js' @@ -1019,7 +1018,7 @@ export class Database { // add this DB transport too // once we create a DB instance, the logger will be using this transport as well // we cannot have this the other way around because of the dependencies cycle - if (USE_DB_TRANSPORT) { + if (ENVIRONMENT_VARIABLES.LOG_DB.value === 'true') { configureCustomDBTransport(this, DATABASE_LOGGER) } else { DATABASE_LOGGER.warn( diff --git a/src/test/unit/logging.test.ts b/src/test/unit/logging.test.ts index b4c32eea6..699ecbe33 100644 --- a/src/test/unit/logging.test.ts +++ b/src/test/unit/logging.test.ts @@ -24,7 +24,10 @@ describe('Logger instances and transports tests', async () => { // need to do it first envOverrides = await setupEnvironment( null, - buildEnvOverrideConfig([ENVIRONMENT_VARIABLES.NODE_ENV], ['development']) + buildEnvOverrideConfig( + [ENVIRONMENT_VARIABLES.NODE_ENV, ENVIRONMENT_VARIABLES.LOG_DB], + ['development', 'false'] + ) ) // because of this it('should be development environment', () => { @@ -43,14 +46,14 @@ describe('Logger instances and transports tests', async () => { null, buildEnvOverrideConfig( [ENVIRONMENT_VARIABLES.LOG_DB, ENVIRONMENT_VARIABLES.DB_URL], - ['true', 'http://172.15.0.6:8108?apiKey=xyz'] + ['true', 'http://localhost:8108?apiKey=xyz'] ) ) expect(process.env.LOG_DB).to.be.equal('true') // will build the DB transport layer const config = await getConfiguration(true) // eslint-disable-next-line no-unused-vars - const DB = new Database(config.dbConfig) + const DB = await new Database(config.dbConfig) // Could generate Typesene error if DB is not running, but does not matter for this test OCEAN_NODE_LOGGER.logMessage('Should build DB transport layer') diff --git a/src/utils/logging/Logger.ts b/src/utils/logging/Logger.ts index 8bcef1fce..68d925b05 100644 --- a/src/utils/logging/Logger.ts +++ b/src/utils/logging/Logger.ts @@ -3,6 +3,7 @@ import Transport from 'winston-transport' import DailyRotateFile from 'winston-daily-rotate-file' import fs from 'fs' import { Database } from '../../components/database/index.js' +import { ENVIRONMENT_VARIABLES } from '../constants.js' // all the types of modules/components export const LOGGER_MODULE_NAMES = { @@ -134,26 +135,6 @@ export class CustomOceanNodesTransport extends Transport { } } -/** - * Avoid these annoyng typesense log message (too much garbage and no utility) - * @param loggerModuleName module name - * @param logMessage the actual message - * @returns boolean - */ -// function isTypesenseIgnoreLogMessage(loggerModuleName: string, logMessage: string) { -// const msg1: string = 'Response Code was 200.' -// const msg2: string = 'Response Code was 201.' -// const msg3 = 'request Try #1 to Node' -// const msg4 = 'Request /collections/' -// return ( -// loggerModuleName.toLowerCase() === LOGGER_MODULE_NAMES.DATABASE && -// (logMessage.includes(msg2) || -// logMessage.includes(msg3) || -// logMessage.includes(msg1) || -// logMessage.includes(msg4)) -// ) -// } - let INSTANCE_COUNT = 0 let customDBTransport: CustomOceanNodesTransport = null @@ -164,8 +145,7 @@ export const NUM_LOGGER_INSTANCES = INSTANCE_COUNT const USE_FILE_TRANSPORT: boolean = process.env.LOG_FILES && process.env.LOG_FILES !== 'false' -export const USE_DB_TRANSPORT: boolean = - process.env.LOG_DB && process.env.LOG_DB !== 'false' +const USE_DB_TRANSPORT: boolean = process.env.LOG_DB && process.env.LOG_DB !== 'false' // default to true, if not explicitly set otherwise AND no other locations defined const USE_CONSOLE_TRANSPORT: boolean = @@ -471,19 +451,13 @@ export class CustomNodeLogger { ) { // lazy check db custom transport, needed beacause of dependency cycles if ( - customDBTransport !== null && // if null then what? - USE_DB_TRANSPORT && + customDBTransport !== null && + (USE_DB_TRANSPORT || ENVIRONMENT_VARIABLES.LOG_DB.value === 'true') && !this.hasDBTransport() ) { this.addTransport(customDBTransport) } - // if (!isLogLevelLogable(level)) { - // return - // } - - // ignore tons of typesense garbage - // if (!isTypesenseIgnoreLogMessage(this.getModuleName(), message)) { this.getLogger().log( level, includeModuleName ? this.buildMessage(message) : message,