Skip to content

Commit

Permalink
remove custom code for debug choice + default console
Browse files Browse the repository at this point in the history
  • Loading branch information
paulo-ocean committed Jul 18, 2024
1 parent 1d31946 commit 0a50aaf
Showing 1 changed file with 33 additions and 56 deletions.
89 changes: 33 additions & 56 deletions src/utils/logging/Logger.ts
Original file line number Diff line number Diff line change
Expand Up @@ -114,16 +114,12 @@ export class CustomOceanNodesTransport extends Transport {
meta: JSON.stringify(info.meta) // Ensure meta is a string
}

if (!isLogLevelLogable(document.level)) {
return
}

try {
// Use the insertLog method of the LogDatabase instance
if (
this.dbInstance &&
this.dbInstance.logs &&
!isTypesenseIgnoreLogMessage(document.moduleName, document.message)
this.dbInstance.logs // &&
// !isTypesenseIgnoreLogMessage(document.moduleName, document.message)
) {
// double check before writing
await this.dbInstance.logs.insertLog(document)
Expand All @@ -144,19 +140,19 @@ export class CustomOceanNodesTransport extends Transport {
* @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))
)
}
// 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
Expand All @@ -165,14 +161,16 @@ export const MAX_LOGGER_INSTANCES = 10
export const NUM_LOGGER_INSTANCES = INSTANCE_COUNT

// log locations
const USE_CONSOLE_TRANSPORT: boolean =
process.env.LOG_CONSOLE && process.env.LOG_CONSOLE !== 'false'
const USE_FILE_TRANSPORT: boolean =
process.env.LOG_FILES && process.env.LOG_FILES !== 'false'
// default to true, if not explicitly set otherwise
export const USE_DB_TRANSPORT: boolean = !(
process.env.LOG_DB && process.env.LOG_DB === 'false'
)

export 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 =
(process.env.LOG_CONSOLE && process.env.LOG_CONSOLE !== 'false') ||
(!USE_FILE_TRANSPORT && !USE_DB_TRANSPORT)

// if not set, then gets default 'development' level & colors
export function isDevelopmentEnvironment(): boolean {
Expand All @@ -199,27 +197,6 @@ export const getDefaultLevel = (): string => {
)
}

// only log if >= configured level
function isLogLevelLogable(level: string): boolean {
const configured: string = getDefaultLevel()
let configuredLevelNum = -1
let currentLevelNum = -1
for (const [key, value] of Object.entries(LOG_LEVELS_NUM)) {
if ((key as string) === configured) {
configuredLevelNum = value
}
if ((key as string) === level) {
currentLevelNum = value
}

if (currentLevelNum > -1 && configuredLevelNum > -1) {
break
}
}

return currentLevelNum >= configuredLevelNum
}

if (isDevelopmentEnvironment()) {
winston.addColors(LOG_COLORS)
}
Expand Down Expand Up @@ -501,18 +478,18 @@ export class CustomNodeLogger {
this.addTransport(customDBTransport)
}

if (!isLogLevelLogable(level)) {
return
}
// if (!isLogLevelLogable(level)) {
// return
// }

// ignore tons of typesense garbage
if (!isTypesenseIgnoreLogMessage(this.getModuleName(), message)) {
this.getLogger().log(
level,
includeModuleName ? this.buildMessage(message) : message,
{ moduleName: this.getModuleName().toUpperCase() }
)
}
// if (!isTypesenseIgnoreLogMessage(this.getModuleName(), message)) {
this.getLogger().log(
level,
includeModuleName ? this.buildMessage(message) : message,
{ moduleName: this.getModuleName().toUpperCase() }
)
// }
}

logMessage(message: string, includeModuleName: boolean = false) {
Expand Down

0 comments on commit 0a50aaf

Please sign in to comment.