UNPKG

whale-nest-nacos

Version:

If you are a nest micro service architecture, you can use the SDK, so as to realize service discovery based on nacos, distributed load balancing strategy

54 lines 1.88 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.NacosLogger = void 0; const common_1 = require("@nestjs/common"); const util_1 = require("util"); const LoggerLevels = { DEBUG: 0, LOG: 1, INFO: 1, WARN: 2, ERROR: 3, }; class NacosLogger { constructor(loggerLevel = 'INFO', logger = new common_1.Logger('NacosNative')) { this.loggerLevel = loggerLevel; this.logger = logger; this.heartbeatLogCount = 0; } log(message, ...optionalParams) { if (LoggerLevels.LOG >= LoggerLevels[this.loggerLevel]) { this.logger.log((0, util_1.format)(message, ...optionalParams)); } } info(message, ...optionalParams) { // 屏蔽nacos心跳日志,默认10s一次 if (message.indexOf('[HostReactor] current ips') >= 0) { if (this.heartbeatLogCount <= 6) { this.heartbeatLogCount += 1; return; } this.heartbeatLogCount = 0; } if (LoggerLevels.INFO >= LoggerLevels[this.loggerLevel]) { this.logger.log((0, util_1.format)(message, ...optionalParams)); } } warn(message, ...optionalParams) { if (LoggerLevels.WARN >= LoggerLevels[this.loggerLevel]) { this.logger.warn((0, util_1.format)(message, ...optionalParams)); } } debug(message, ...optionalParams) { if (LoggerLevels.DEBUG >= LoggerLevels[this.loggerLevel]) { this.logger.debug && this.logger.debug((0, util_1.format)(message, ...optionalParams)); } } error(message, ...optionalParams) { if (LoggerLevels.ERROR >= LoggerLevels[this.loggerLevel]) { this.logger.error((0, util_1.format)(message, ...optionalParams)); } } } exports.NacosLogger = NacosLogger; //# sourceMappingURL=index.js.map