From be59fbb9e2cd3bb0a16844c0dd24a7d912f3ce37 Mon Sep 17 00:00:00 2001 From: teddys48 Date: Mon, 14 Sep 2026 09:20:33 +0700 Subject: [PATCH] update loki without label --- application/helpers/getbodyrequest.js | 68 +++++++++++---------------- application/helpers/loki.js | 41 ++++++++-------- 2 files changed, 48 insertions(+), 61 deletions(-) diff --git a/application/helpers/getbodyrequest.js b/application/helpers/getbodyrequest.js index 304a35a..265dbcc 100644 --- a/application/helpers/getbodyrequest.js +++ b/application/helpers/getbodyrequest.js @@ -134,24 +134,20 @@ const logger = { console.log(statusCode); winstonLoki.log.error({ message: message, - labels: { - route: url, - status_code: statusCode, - issuer_name: issuerName, - }, + route: url, + status_code: statusCode, + issuer_name: issuerName, }); } else { let reservation_number = info.meta.res.body.data.reservation_number; let card_number = info.meta.res.body.data.card_number; winstonLoki.log.info({ message: message, - labels: { - route: url, - status_code: statusCode, - issuer_name: issuerName, - reservation_number: reservation_number, - card_number: card_number, - }, + route: url, + status_code: statusCode, + issuer_name: issuerName, + reservation_number: reservation_number, + card_number: card_number, }); } } else if (url == "/api/topup6" || url == "/api/topup7") { @@ -167,26 +163,22 @@ const logger = { ) { winstonLoki.log.error({ message: message, - labels: { - route: url, - status_code: statusCode, - issuer_name: issuerName, - card_number: card_number, - uid: uid, - trxID: trxID, - }, + route: url, + status_code: statusCode, + issuer_name: issuerName, + card_number: card_number, + uid: uid, + trxID: trxID, }); } else { winstonLoki.log.info({ message: message, - labels: { - route: url, - status_code: statusCode, - issuer_name: issuerName, - card_number: card_number, - uid: uid, - trxID: trxID, - }, + route: url, + status_code: statusCode, + issuer_name: issuerName, + card_number: card_number, + uid: uid, + trxID: trxID, }); } } else { @@ -200,22 +192,18 @@ const logger = { ) { winstonLoki.log.error({ message: message, - labels: { - route: url, - status_code: statusCode, - issuer_name: issuerName, - trxID: trxID, - }, + route: url, + status_code: statusCode, + issuer_name: issuerName, + trxID: trxID, }); } else { winstonLoki.log.info({ message: message, - labels: { - route: url, - status_code: statusCode, - issuer_name: issuerName, - trxID: trxID, - }, + route: url, + status_code: statusCode, + issuer_name: issuerName, + trxID: trxID, }); } } diff --git a/application/helpers/loki.js b/application/helpers/loki.js index 3bf12ea..4946122 100644 --- a/application/helpers/loki.js +++ b/application/helpers/loki.js @@ -1,8 +1,8 @@ -const moment = require('moment'); -const winston = require('winston'); -const loki = require('winston-loki'); -require('winston-daily-rotate-file'); -require('dotenv').config(); +const moment = require("moment"); +const winston = require("winston"); +const loki = require("winston-loki"); +require("winston-daily-rotate-file"); +require("dotenv").config(); const { combine, timestamp, printf, colorize, align, json } = winston.format; let lokiUrl = process.env.LOKI_URL; @@ -18,39 +18,39 @@ var log; const fileRotateTransport = new winston.transports.DailyRotateFile({ filename: `./lokiLog/%DATE%-onlinetopup.log`, - datePattern: 'YYYY-MM-DD', - maxFiles: '1d', + datePattern: "YYYY-MM-DD", + maxFiles: "1d", }); if ( - process.env.NODE_ENV == 'production' || - process.env.NODE_ENV == 'PRODUCTION' + process.env.NODE_ENV == "production" || + process.env.NODE_ENV == "PRODUCTION" ) { log = winston.createLogger({ levels: logLevels, - level: process.env.LOG_LEVEL || 'info', + level: process.env.LOG_LEVEL || "info", exitOnError: false, // format: combine(timestamp(), json()), format: combine( // colorize({ all: true }), timestamp({ - format: 'YYYY-MM-DD HH:mm:ss.SSS', + format: "YYYY-MM-DD HH:mm:ss.SSS", }), align(), - printf((info) => `[${info.timestamp}] ${info.level}: ${info.message}`) + printf((info) => `[${info.timestamp}] ${info.level}: ${info.message}`), ), - defaultMeta: { service: 'topuponline' }, + defaultMeta: { service: "topuponline" }, transports: [ new loki({ host: lokiUrl, - labels: { app: 'topuponline' }, + labels: { app: "topuponline" }, json: true, format: json(), replaceTimestamp: true, onConnectionError: (err) => console.error(err), }), - new transports.Console({ - format: format.combine(format.simple(), format.colorize()), + new winston.transports.Console({ + format: combine(colorize()), }), ], }); @@ -59,7 +59,6 @@ if ( transports: [ new loki({ host: lokiUrl, - labels: { app: 'topuponline' }, handleExceptions: true, handleRejections: true, clearOnError: true, @@ -75,19 +74,19 @@ if ( }); } -if (process.env.NODE_ENV != 'testing' && process.env.NODE_ENV != 'TESTING') { +if (process.env.NODE_ENV != "testing" && process.env.NODE_ENV != "TESTING") { log.add( new winston.transports.Console({ // format: winston.format.cli(), format: combine( colorize({ all: true }), timestamp({ - format: 'YYYY-MM-DD HH:mm:ss.SSS', + format: "YYYY-MM-DD HH:mm:ss.SSS", }), align(), - printf((info) => `[${info.timestamp}] ${info.level}: ${info.message}`) + printf((info) => `[${info.timestamp}] ${info.level}: ${info.message}`), ), - }) + }), ); }