Created
October 9, 2024 04:12
-
-
Save codersidprogrammer/39ef068f5f5f246c964f45877f4d094f to your computer and use it in GitHub Desktop.
Make deactivate default log for NestJS Eureka Connector
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
... | |
EurekaModule.forRoot({ | |
disable: false, | |
disableDiscovery: false, | |
eureka: { | |
host: process.env.EUREKA_HOST || 'localhost', | |
port: Number(process.env.EUREKA_PORT) || 8761, | |
registryFetchInterval: Number(process.env.EUREKA_INTERVAL) || 1000, | |
servicePath: '/eureka/apps', | |
maxRetries: 3, | |
}, | |
service: { | |
// host: 'localhost', | |
name: process.env.APPLICATION_NAME, | |
port: Number(process.env.APPLICATION_PORT) || 8000, | |
}, | |
clientLogger: new EurekaLog('EurekaService'), <-- Use here | |
}), | |
... |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import { Logger } from '@nestjs/common'; | |
import { EurekaModuleClientLogger } from 'nestjs-eureka'; | |
export class EurekaLog implements EurekaModuleClientLogger { | |
private _logger: Logger; | |
private _isActive: boolean; | |
constructor(instanceName: string, isLogActive: boolean = false) { | |
this._logger = new Logger(instanceName); | |
this._isActive = isLogActive; | |
} | |
warn(...args: any[]): void { | |
if (this._isActive) { | |
this._logger.warn(args); | |
return; | |
} | |
return; | |
} | |
info(...args: any[]): void { | |
if (this._isActive) { | |
this._logger.log(args); | |
return; | |
} | |
return; | |
} | |
debug(...args: any[]): void { | |
if (this._isActive) { | |
this._logger.debug(args); | |
return; | |
} | |
return; | |
} | |
error(...args: any[]): void { | |
if (this._isActive) { | |
this._logger.error(args); | |
return; | |
} | |
return; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment