mirror of
https://github.com/mohamadihsan/topuponline.git
synced 2026-12-05 11:06:28 +00:00
update log format
This commit is contained in:
@@ -1,15 +0,0 @@
|
||||
{
|
||||
"keep": {
|
||||
"days": true,
|
||||
"amount": 1
|
||||
},
|
||||
"auditLog": ".71c131f2ce727b13210eef32232709400762e5fb-audit.json",
|
||||
"files": [
|
||||
{
|
||||
"date": 1661254787520,
|
||||
"name": "2022-08-23-onlinetopup.log",
|
||||
"hash": "e668ef50941194f7b10ecc9f45c4aa6a0b20dfa39dce90ddcea41607f465ef6a"
|
||||
}
|
||||
],
|
||||
"hashType": "sha256"
|
||||
}
|
||||
@@ -1,6 +1,7 @@
|
||||
const moment = require("moment");
|
||||
const winston = require("winston");
|
||||
require('winston-daily-rotate-file');
|
||||
require("winston-daily-rotate-file");
|
||||
require("dotenv").config();
|
||||
const { combine, timestamp, printf, colorize, align, json } = winston.format;
|
||||
|
||||
const logLevels = {
|
||||
@@ -11,7 +12,7 @@ const logLevels = {
|
||||
debug: 4,
|
||||
trace: 5,
|
||||
};
|
||||
let logger;
|
||||
var logger;
|
||||
|
||||
//
|
||||
// Replaces the previous transports with those in the
|
||||
@@ -24,19 +25,19 @@ let logger;
|
||||
// });
|
||||
|
||||
const fileRotateTransport = new winston.transports.DailyRotateFile({
|
||||
filename: "%DATE%-onlinetopup.log",
|
||||
filename: `application/logs/%DATE%-onlinetopup.log`,
|
||||
datePattern: "YYYY-MM-DD",
|
||||
maxFiles: "1d",
|
||||
maxFiles: "90d",
|
||||
});
|
||||
|
||||
//
|
||||
// If we're not in production then log to the `console` with the format:
|
||||
// `${info.level}: ${info.message} JSON.stringify({ ...rest }) `
|
||||
//
|
||||
if (process.env.NODE_ENV == "production") {
|
||||
let logger = winston.createLogger({
|
||||
|
||||
if (process.env.NODE_ENV == "production" || process.env.NODE_ENV == "PRODUCTION") {
|
||||
logger = winston.createLogger({
|
||||
levels: logLevels,
|
||||
level: process.env.LOG_LEVEL || "warn",
|
||||
level: process.env.LOG_LEVEL || "info",
|
||||
exitOnError: false,
|
||||
// format: combine(timestamp(), json()),
|
||||
format: combine(
|
||||
@@ -58,15 +59,15 @@ if (process.env.NODE_ENV == "production") {
|
||||
filename: `application/logs/error.log`,
|
||||
level: "error",
|
||||
}),
|
||||
new winston.transports.File({
|
||||
filename: `application/logs/${moment().format("YYYY-MM-DD")}-onlinetopup.log`,
|
||||
}),
|
||||
// new winston.transports.File({
|
||||
// filename: `application/logs/${moment().format("YYYY-MM-DD")}-onlinetopup.log`,
|
||||
// }),
|
||||
],
|
||||
});
|
||||
} else {
|
||||
logger = winston.createLogger({
|
||||
levels: logLevels,
|
||||
level: process.env.LOG_LEVEL || "info",
|
||||
level: process.env.LOG_LEVEL || "debug",
|
||||
exitOnError: false,
|
||||
// format: combine(timestamp(), json()),
|
||||
format: combine(
|
||||
@@ -92,27 +93,27 @@ if (process.env.NODE_ENV == "production") {
|
||||
filename: `application/logs/debug/${moment().format("YYYY-MM-DD")}.log`,
|
||||
level: "debug",
|
||||
}),
|
||||
new winston.transports.File({
|
||||
filename: `application/logs/${moment().format("YYYY-MM-DD")}-onlinetopup.log`,
|
||||
}),
|
||||
// new winston.transports.File({
|
||||
// filename: `application/logs/${moment().format("YYYY-MM-DD")}-onlinetopup.log`,
|
||||
// }),
|
||||
],
|
||||
});
|
||||
|
||||
logger.add(
|
||||
new winston.transports.Console({
|
||||
// format: winston.format.cli(),
|
||||
format: combine(
|
||||
colorize({ all: true }),
|
||||
timestamp({
|
||||
format: "YYYY-MM-DD HH:mm:ss.SSS",
|
||||
}),
|
||||
align(),
|
||||
printf((info) => `[${info.timestamp}] ${info.level}: ${info.message}`)
|
||||
),
|
||||
})
|
||||
);
|
||||
}
|
||||
|
||||
logger.add(
|
||||
new winston.transports.Console({
|
||||
// format: winston.format.cli(),
|
||||
format: combine(
|
||||
colorize({ all: true }),
|
||||
timestamp({
|
||||
format: "YYYY-MM-DD HH:mm:ss.SSS",
|
||||
}),
|
||||
align(),
|
||||
printf((info) => `[${info.timestamp}] ${info.level}: ${info.message}`)
|
||||
),
|
||||
})
|
||||
);
|
||||
|
||||
module.exports = {
|
||||
logger,
|
||||
};
|
||||
|
||||
@@ -14,9 +14,7 @@ const controller = async (req, res) => {
|
||||
uniqueCode = await helper.getUniqueCode();
|
||||
|
||||
// log info
|
||||
winston.logger.info(
|
||||
`${uniqueCode} REQUEST load balance - STARTING...`
|
||||
);
|
||||
winston.logger.info(`${uniqueCode} REQUEST load balance - STARTING...`);
|
||||
|
||||
// log debug
|
||||
winston.logger.debug(
|
||||
|
||||
@@ -59,9 +59,7 @@ const controller = async (req, res) => {
|
||||
|
||||
// log debug
|
||||
winston.logger.debug(
|
||||
`${uniqueCode} HSM - message Auth2v2: ${generate.buf2hex(
|
||||
message
|
||||
)}`
|
||||
`${uniqueCode} HSM - message Auth2v2: ${generate.buf2hex(message)}`
|
||||
);
|
||||
|
||||
respData = message;
|
||||
|
||||
@@ -76,9 +76,7 @@ const controller = async (req, res) => {
|
||||
};
|
||||
|
||||
// log info
|
||||
winston.logger.info(
|
||||
`${uniqueCode} RESPONSE load balance - END...`
|
||||
);
|
||||
winston.logger.info(`${uniqueCode} RESPONSE load balance - END...`);
|
||||
|
||||
// log debug
|
||||
winston.logger.debug(
|
||||
|
||||
@@ -1,33 +1,36 @@
|
||||
// Get Service Code, Block, dan System Code
|
||||
const controller = async (req, res) => {
|
||||
try {
|
||||
let sytemCode = "939E"
|
||||
let serviceReadNS = "4B1017208B20"
|
||||
let blockReadNS = "800081008200"
|
||||
let serviceMutual = "102001A04C2001A0882001A0"
|
||||
let blockReadS = "80008200"
|
||||
let blockWrite = "800081008200"
|
||||
let locFlag = 15
|
||||
return res.status(200).send({
|
||||
code: "00",
|
||||
message: 'Get Service Succeess',
|
||||
data: {
|
||||
sysCode: sytemCode,
|
||||
sReadNS: serviceReadNS,
|
||||
sMutual: serviceMutual,
|
||||
bReadNS: blockReadNS,
|
||||
bReadS: blockReadS,
|
||||
bWrite: blockWrite,
|
||||
lFlag: locFlag
|
||||
}
|
||||
})
|
||||
} catch (error) {
|
||||
return res.json({
|
||||
code: "5001",
|
||||
message: process.env.NODE_ENV != "production" ? error.message : '500 internal server error - backend server.',
|
||||
data: {},
|
||||
});
|
||||
}
|
||||
};
|
||||
try {
|
||||
let sytemCode = "939E";
|
||||
let serviceReadNS = "4B1017208B20";
|
||||
let blockReadNS = "800081008200";
|
||||
let serviceMutual = "102001A04C2001A0882001A0";
|
||||
let blockReadS = "80008200";
|
||||
let blockWrite = "800081008200";
|
||||
let locFlag = 15;
|
||||
return res.status(200).send({
|
||||
code: "00",
|
||||
message: "Get Service Succeess",
|
||||
data: {
|
||||
sysCode: sytemCode,
|
||||
sReadNS: serviceReadNS,
|
||||
sMutual: serviceMutual,
|
||||
bReadNS: blockReadNS,
|
||||
bReadS: blockReadS,
|
||||
bWrite: blockWrite,
|
||||
lFlag: locFlag,
|
||||
},
|
||||
});
|
||||
} catch (error) {
|
||||
return res.json({
|
||||
code: "5001",
|
||||
message:
|
||||
process.env.NODE_ENV != "production"
|
||||
? error.message
|
||||
: "500 internal server error - backend server.",
|
||||
data: {},
|
||||
});
|
||||
}
|
||||
};
|
||||
|
||||
module.exports = controller;
|
||||
module.exports = controller;
|
||||
|
||||
@@ -4,9 +4,11 @@ const winston = require("../../../helpers/winston.logger");
|
||||
const fs = require("fs");
|
||||
const _sleep = (ms) => new Promise((resolve) => setTimeout(resolve, ms));
|
||||
const generate = require("../utils/utils");
|
||||
require("dotenv").config();
|
||||
|
||||
let ssl_ca_crt = "./application/assets/cert/CACerts.pem";
|
||||
let ssl_client_pfx = "./application/assets/cert/FeliqClient0002-03.pfx";
|
||||
|
||||
let options = {
|
||||
ca: fs.readFileSync(ssl_ca_crt),
|
||||
agent: false,
|
||||
@@ -14,24 +16,42 @@ let options = {
|
||||
pfx: fs.readFileSync(ssl_client_pfx),
|
||||
};
|
||||
|
||||
// init server hsm
|
||||
var serverNutechPCI = "NUTECH_PCI";
|
||||
var serverKCIPCI = "KCI_PCI";
|
||||
var serverKCIHSM = "KCI_HSM";
|
||||
var serverJepangHSM = "JEPANG_HSM";
|
||||
var url;
|
||||
|
||||
if (process.env.HSM_SERVER == serverNutechPCI) {
|
||||
url = "ws://182.253.34.129/feliqserver/v1/wsapi"; // server nutech tetra
|
||||
} else if (process.env.HSM_SERVER == serverKCIPCI) {
|
||||
url = "";
|
||||
} else if (process.env.HSM_SERVER == serverKCIHSM) {
|
||||
url = "";
|
||||
} else if (process.env.HSM_SERVER == serverJepangHSM) {
|
||||
url = "wss://gateway04.cyberware.co.jp/feliqserver/v1/wsapi"; // server jepang
|
||||
} else {
|
||||
// check config HSM
|
||||
if (
|
||||
(process.env.URL_HSM_SERVER_1 == "" && process.env.URL_HSM_SERVER_2 == "") ||
|
||||
process.env.APIKEY_HSM_SERVER_1 == "" ||
|
||||
process.env.SECRETKEY_HSM_SERVER_1 == ""
|
||||
) {
|
||||
// create log
|
||||
winston.logger.error(`PLEASE SET HSM SERVER ON THE ENVIRONMENT!`);
|
||||
winston.logger.error(`PLEASE CONFIGURE HSM SERVER ON THE ENVIRONMENT!`);
|
||||
}
|
||||
|
||||
// init server hsm
|
||||
var urlSever_1;
|
||||
var apiKeyBytesServer_1;
|
||||
var secretBytesServer_1;
|
||||
var urlSever_2;
|
||||
var apiKeyBytesServer_2;
|
||||
var secretBytesServer_2;
|
||||
|
||||
if (process.env.CHANGE_TO_DRC == "YES" || process.env.CHANGE_TO_DRC == "yes") {
|
||||
// config for DRC
|
||||
urlSever_1 = process.env.URL_HSM_SERVER_BACKUP_1;
|
||||
apiKeyBytesServer_1 = Buffer.from(process.env.APIKEY_HSM_SERVER_BACKUP_1);
|
||||
secretBytesServer_1 = Buffer.from(process.env.SECRETKEY_HSM_SERVER_BACKUP_1);
|
||||
|
||||
urlSever_2 = process.env.URL_HSM_SERVER_BACKUP_2;
|
||||
apiKeyBytesServer_2 = Buffer.from(process.env.APIKEY_HSM_SERVER_BACKUP_2);
|
||||
secretBytesServer_2 = Buffer.from(process.env.SECRETKEY_HSM_SERVER_BACKUP_2);
|
||||
} else {
|
||||
// config for DC
|
||||
urlSever_1 = process.env.URL_HSM_SERVER_1;
|
||||
apiKeyBytesServer_1 = Buffer.from(process.env.APIKEY_HSM_SERVER_1);
|
||||
secretBytesServer_1 = Buffer.from(process.env.SECRETKEY_HSM_SERVER_1);
|
||||
|
||||
urlSever_2 = process.env.URL_HSM_SERVER_2;
|
||||
apiKeyBytesServer_2 = Buffer.from(process.env.APIKEY_HSM_SERVER_2);
|
||||
secretBytesServer_2 = Buffer.from(process.env.SECRETKEY_HSM_SERVER_2);
|
||||
}
|
||||
|
||||
const config = {
|
||||
@@ -46,14 +66,16 @@ function startInterval() {
|
||||
interval = setInterval(function () {
|
||||
checkInternetConnected(config)
|
||||
.then((result) => {
|
||||
console.log(result); //successfully connected to a server
|
||||
// log info
|
||||
winston.logger.info(`retry open websocket`);
|
||||
// console.log(result); //successfully connected to a server
|
||||
// log debug
|
||||
winston.logger.debug(`retry open websocket`);
|
||||
client.open();
|
||||
stopInterval();
|
||||
})
|
||||
.catch((ex) => {
|
||||
console.log(ex); // cannot connect to a server or error occurred.
|
||||
// console.log(ex); // cannot connect to a server or error occurred.
|
||||
// log error
|
||||
winston.logger.error(`error start interval : ${ex}`);
|
||||
});
|
||||
}, 5900);
|
||||
}
|
||||
@@ -71,7 +93,7 @@ class WebSocketClient {
|
||||
open = () => {
|
||||
try {
|
||||
if (this.ws == null) {
|
||||
this.ws = new WebSocket(url, [], options);
|
||||
this.ws = new WebSocket(urlSever_1, [], options);
|
||||
|
||||
this.ws.on("open", this.onOpen);
|
||||
this.ws.on("close", this.onClose);
|
||||
@@ -90,8 +112,8 @@ class WebSocketClient {
|
||||
this.ws.close();
|
||||
// console.log('WebSocket Close');
|
||||
|
||||
// log info
|
||||
winston.logger.info(`websocket close`);
|
||||
// log warn
|
||||
winston.logger.warn(`websocket close`);
|
||||
};
|
||||
|
||||
// Open event
|
||||
@@ -102,8 +124,8 @@ class WebSocketClient {
|
||||
winston.logger.debug(`opening websocket`);
|
||||
|
||||
if (this.isOpened()) {
|
||||
// log info
|
||||
winston.logger.info(`websocket open successfully`);
|
||||
// log debug
|
||||
winston.logger.debug(`websocket open successfully`);
|
||||
|
||||
if (!this.clientAuthenticated) {
|
||||
this.clientAuth();
|
||||
@@ -117,8 +139,8 @@ class WebSocketClient {
|
||||
onClose = () => {
|
||||
// console.log("WebSocket Close");
|
||||
|
||||
// log info
|
||||
winston.logger.info(`websocket close`);
|
||||
// log warn
|
||||
winston.logger.warn(`websocket close`);
|
||||
|
||||
this.clientAuthenticated = false;
|
||||
this.ws = null;
|
||||
@@ -128,8 +150,8 @@ class WebSocketClient {
|
||||
onError = () => {
|
||||
// console.log("WebSocket Error");
|
||||
|
||||
// log info
|
||||
winston.logger.info(`websocket error`);
|
||||
// log error
|
||||
winston.logger.error(`websocket error`);
|
||||
|
||||
this.clientAuthenticated = false;
|
||||
};
|
||||
@@ -166,38 +188,11 @@ class WebSocketClient {
|
||||
authHead[0] = 0x93;
|
||||
authHead[1] = 0x9e;
|
||||
|
||||
// Set API key
|
||||
|
||||
var apiKeyBytes;
|
||||
var secretBytes;
|
||||
|
||||
if (process.env.HSM_SERVER == serverNutechPCI) {
|
||||
apiKeyBytes = Buffer.from("d54ff5c4-9709-3bac-9a6e-04b2f4deebae-0TC"); // Nutech Server Nutech Tetra
|
||||
// Secret setting
|
||||
//const secretBytes = Buffer.from('TdtSo/i5ZmbwPr82gt4fElK96lV9ClVo7votHKMIUuo='); // T4
|
||||
secretBytes = Buffer.from(
|
||||
"W8ZiN1o2tNkb1svNlj5Kl8PNohhujaTxeNaGEq2rOWY="
|
||||
); // Nutech Server Nutech Tetra
|
||||
} else if (process.env.HSM_SERVER == serverKCIPCI) {
|
||||
apiKeyBytes = "";
|
||||
secretBytes = "";
|
||||
} else if (process.env.HSM_SERVER == serverKCIHSM) {
|
||||
apiKeyBytes = "";
|
||||
secretBytes = "";
|
||||
} else if (process.env.HSM_SERVER == serverJepangHSM) {
|
||||
//const apiKeyBytes = Buffer.from('82002732-9148-34e5-843b-c639a0c88cc5-0TC') // T4
|
||||
apiKeyBytes = Buffer.from("4c6dd075-dbcb-375f-81f7-62990a5d7000-0TC"); // Nutech Server Jepang
|
||||
// // Secret setting
|
||||
// //const secretBytes = Buffer.from('TdtSo/i5ZmbwPr82gt4fElK96lV9ClVo7votHKMIUuo='); // T4
|
||||
secretBytes = Buffer.from(
|
||||
"U5xs7nVonhtbQ+XiYATRSg8Nk5sPu1IpVx7X40KyWiw="
|
||||
); // Nutech Server Jepang
|
||||
} else {
|
||||
// create log
|
||||
winston.logger.error(`PLEASE SET HSM SERVER ON THE ENVIRONMENT!`);
|
||||
}
|
||||
|
||||
const authData = Buffer.concat([authHead, apiKeyBytes, secretBytes]);
|
||||
const authData = Buffer.concat([
|
||||
authHead,
|
||||
apiKeyBytesServer_1,
|
||||
secretBytesServer_1,
|
||||
]);
|
||||
|
||||
let transactionId = Buffer.from([0x00, 0x00]);
|
||||
let apiId = Buffer.from([0x00]);
|
||||
@@ -269,7 +264,7 @@ setInterval(function () {
|
||||
client.clientAuth();
|
||||
}
|
||||
// }
|
||||
}, 53000);
|
||||
}, 59000);
|
||||
|
||||
module.exports = {
|
||||
client,
|
||||
|
||||
@@ -11,15 +11,18 @@ const hsmRoute = require("./application/routes/hsm.routes");
|
||||
const historyRoute = require("./application/routes/history.routes");
|
||||
const paymentReconRoute = require("./application/routes/paymentrecon.routes");
|
||||
const invoiceRoute = require("./application/routes/invoice.routes");
|
||||
const cron = require('node-cron');
|
||||
const moment = require('moment')
|
||||
const cron = require("node-cron");
|
||||
const moment = require("moment");
|
||||
require("dotenv").config();
|
||||
moment.locale("id");
|
||||
|
||||
const app = express();
|
||||
|
||||
var corsOptions = {
|
||||
origin: ["http://localhost:" + process.env.PORT || 8000, "http://localhost:3000"],
|
||||
origin: [
|
||||
"http://localhost:" + process.env.PORT || 3000,
|
||||
"http://localhost:3000",
|
||||
],
|
||||
};
|
||||
|
||||
// app.use(cors(corsOptions));
|
||||
@@ -52,40 +55,63 @@ app.use("/api/", reservationRoute);
|
||||
app.use("/api/", invoiceRoute);
|
||||
|
||||
// set port, listen for requests
|
||||
const PORT = process.env.PORT || 8000;
|
||||
const PORT = process.env.PORT || 3000;
|
||||
app.listen(PORT, () => {
|
||||
winston.logger.info(`Server is running on environment: ${process.env.NODE_ENV.toUpperCase()} port: ${PORT}`);
|
||||
winston.logger.info(
|
||||
`Server is running on environment: ${process.env.NODE_ENV.toUpperCase()} port: ${PORT}`
|
||||
);
|
||||
});
|
||||
|
||||
// winston.logger.info(`Response : ${response()}`);
|
||||
// ============================== SAP SCHEDULLER =============================
|
||||
|
||||
// SCHEDULER FOR GENERATE INVOICE
|
||||
const {_generateInvoice, _postingInvoice } = require("./application/modules/invoice/invoice.controller");
|
||||
cron.schedule('*/10 * * * *', async () => {
|
||||
try {
|
||||
let ivoiceDate = moment().add(1, 'days').format("YYYY-MM-DD");
|
||||
let uniqueCode = helper.getUniqueCode()
|
||||
winston.logger.info(`STARTING SCHEDULER-FB70 GENERATE INVOICE ${ivoiceDate} `);
|
||||
const generate = await _generateInvoice(ivoiceDate, uniqueCode, false)
|
||||
winston.logger.info(`END SCHEDULER-FB70 GENERATE INVOICE ${ivoiceDate} : ${JSON.stringify(generate)}`);
|
||||
} catch (error) {
|
||||
// create log
|
||||
winston.logger.error(
|
||||
`500 internal server error - backend server | ${error.message}`
|
||||
);
|
||||
}
|
||||
});
|
||||
if (process.env.NODE_ENV.toUpperCase() != "PRODUCTION") {
|
||||
// SCHEDULER FOR GENERATE INVOICE
|
||||
const {
|
||||
_generateInvoice,
|
||||
_postingInvoice,
|
||||
} = require("./application/modules/invoice/invoice.controller");
|
||||
|
||||
cron.schedule('*/15 * * * *', async () => {
|
||||
try {
|
||||
let uniqueCode = helper.getUniqueCode()
|
||||
winston.logger.info(`STARTING SCHEDULER-FB70 POSTING INVOICE`);
|
||||
const posting = await _postingInvoice(uniqueCode)
|
||||
winston.logger.info(`END SCHEDULER-FB70 POSTING INVOICE : ${JSON.stringify(posting)}`);
|
||||
} catch (error) {
|
||||
// create log
|
||||
winston.logger.error(
|
||||
`500 internal server error - backend server | ${error.message}`
|
||||
);
|
||||
}
|
||||
});
|
||||
// every 10 minutes
|
||||
// cron.schedule('*/10 * * * *', async () => {
|
||||
// every at 01:00
|
||||
cron.schedule("0 1 * * *", async () => {
|
||||
try {
|
||||
// let ivoiceDate = moment().add(1, 'days').format("YYYY-MM-DD");
|
||||
let ivoiceDate = moment().format("YYYY-MM-DD");
|
||||
let uniqueCode = helper.getUniqueCode();
|
||||
winston.logger.debug(
|
||||
`STARTING SCHEDULER-FB70 GENERATE INVOICE ${ivoiceDate} `
|
||||
);
|
||||
const generate = await _generateInvoice(ivoiceDate, uniqueCode, false);
|
||||
winston.logger.debug(
|
||||
`END SCHEDULER-FB70 GENERATE INVOICE ${ivoiceDate} : ${JSON.stringify(
|
||||
generate
|
||||
)}`
|
||||
);
|
||||
} catch (error) {
|
||||
// create log
|
||||
winston.logger.error(
|
||||
`500 internal server error - backend server | ${error.message}`
|
||||
);
|
||||
}
|
||||
});
|
||||
|
||||
// every 15 minutes
|
||||
// cron.schedule('*/15 * * * *', async () => {
|
||||
// every 2 hour
|
||||
cron.schedule("0 */2 * * *", async () => {
|
||||
try {
|
||||
let uniqueCode = helper.getUniqueCode();
|
||||
winston.logger.debug(`STARTING SCHEDULER-FB70 POSTING INVOICE`);
|
||||
const posting = await _postingInvoice(uniqueCode);
|
||||
winston.logger.debug(
|
||||
`END SCHEDULER-FB70 POSTING INVOICE : ${JSON.stringify(posting)}`
|
||||
);
|
||||
} catch (error) {
|
||||
// create log
|
||||
winston.logger.error(
|
||||
`500 internal server error - backend server | ${error.message}`
|
||||
);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user