From bff8643c56e8e8ca8d509c46c7d858b2c1642f27 Mon Sep 17 00:00:00 2001 From: chin Date: Wed, 2 Mar 2022 21:56:31 +0800 Subject: [PATCH] feat: add logger in FHIRAPI and refactor resFunc - extract resFunc to global variable - add warn logger --- api/FHIRApiService/condition-delete.js | 10 ++- api/FHIRApiService/create.js | 105 ++++++++++++++++--------- api/FHIRApiService/delete.js | 70 +++++++++++------ api/FHIRApiService/history.js | 9 ++- api/FHIRApiService/read.js | 9 ++- api/FHIRApiService/search.js | 12 ++- api/FHIRApiService/update.js | 10 ++- api/FHIRApiService/vread.js | 5 ++ config/log4js.json | 21 ++++- 9 files changed, 176 insertions(+), 75 deletions(-) diff --git a/api/FHIRApiService/condition-delete.js b/api/FHIRApiService/condition-delete.js index 594bf3ba..d9ee41fa 100644 --- a/api/FHIRApiService/condition-delete.js +++ b/api/FHIRApiService/condition-delete.js @@ -6,6 +6,9 @@ const { const FHIR = require('../../models/FHIR/fhir/fhir').Fhir; const { isRealObject } = require('../apiService'); const user = require('../APIservices/user.service'); +const { logger } = require('../../utils/log'); +const path = require('path'); +const PWD_FILENAME = path.relative(process.cwd(), __filename); /** * @@ -16,6 +19,7 @@ const user = require('../APIservices/user.service'); * @returns */ module.exports = async function(req, res, resourceType, paramsSearch) { + logger.info(`[Info: do condition-delete] [Resource Type: ${resourceType}] [From-File: ${PWD_FILENAME}] [Content-Type: ${res.getHeader("content-type")}] [Url-SearchParam: ${req.url}] `); let doRes = function (code , item) { if (res.getHeader("content-type").includes("xml")) { let fhir = new FHIR(); @@ -25,6 +29,7 @@ module.exports = async function(req, res, resourceType, paramsSearch) { return res.status(code).send(item); }; if (!await user.checkTokenPermission(req, resourceType, "delete")) { + logger.warn(`[Warn: Request token doesn't have permission with this API] [From-File: ${PWD_FILENAME}] [From-IP: ${req.socket.remoteAddress}]`); return doRes(403,handleError.forbidden("Your token doesn't have permission with this API")); } let queryParameter = _.cloneDeep(req.query); @@ -45,7 +50,7 @@ module.exports = async function(req, res, resourceType, paramsSearch) { paramsSearch[key](queryParameter); } catch (e) { if (key != "$and") { - console.error(e); + logger.error(`[Error: Unknown search parameter ${key} or value ${queryParameter[key]}] [Resource Type: ${resourceType}] [From-File: ${PWD_FILENAME}] [${e}]`); return doRes(400 , handleError.processing(`Unknown search parameter ${key} or value ${queryParameter[key]}`)); } } @@ -59,7 +64,8 @@ module.exports = async function(req, res, resourceType, paramsSearch) { let info = handleError.informational(`delete successfully, deleted count : ${deletion.deletedCount}`); return doRes(200 , info); } catch (e) { - console.log(`api ${process.env.FHIRSERVER_APIPATH}/${resourceType}/ has error, `, e); + let errorStr = JSON.stringify(e, Object.getOwnPropertyNames(e)); + logger.error(`[Error: ${errorStr}] [Resource Type: ${resourceType}] [From-File: ${PWD_FILENAME}]`); let operationOutcomeError = handleError.exception(e); return doRes(500 , operationOutcomeError); } diff --git a/api/FHIRApiService/create.js b/api/FHIRApiService/create.js index 0281e54b..4a171dc7 100644 --- a/api/FHIRApiService/create.js +++ b/api/FHIRApiService/create.js @@ -8,7 +8,64 @@ const { checkReference, getNotExistReferenceList } = require('../apiService'); const FHIR = require('../../models/FHIR/fhir/fhir').Fhir; const user = require('../APIservices/user.service'); const validateContained = require('./validateContained'); +const { logger } = require('../../utils/log'); +const path = require('path'); +const PWD_FILENAME = path.relative(process.cwd(), __filename); +const responseFunc = { + /** + * + * @param {Object} doc + * @param {import('express').Request} req express request + * @param {import('express').Response} res express response + * @param {string} resourceType resource type + * @param {function} doResCallback callback function + * @returns + */ + "true": (doc, req, res, resourceType, doResCallback) => { + let reqBaseUrl = `${req.protocol}://${req.get('host')}/`; + let fullAbsoluteUrl = new URL(req.originalUrl, reqBaseUrl).href; + res.set("Location", fullAbsoluteUrl); + res.append("Last-Modified", (new Date()).toUTCString()); + logger.info(`[Info: create id: ${doc.id} successfully] [Resource Type: ${resourceType}] [From-file: ${PWD_FILENAME}]`); + return doResCallback(201 , doc); + }, + /** + * + * @param {Object} err + * @param {import('express').Request} req express request + * @param {import('express').Response} res express response + * @param {string} resourceType resource type + * @param {function} doResCallback callback function + * @returns + */ + "false": (err, req, res, resourceType, doResCallback) => { + let operationOutcomeMessage; + if (err.message.code == 11000) { + operationOutcomeMessage = { + code : 409 , + msg : handleError.duplicate(err.message) + }; + } else if (err.stack.includes("ValidationError")) { + operationOutcomeMessage = { + code : 400 , + msg : handleError.processing(err.message) + }; + } else if (err.stack.includes("stored by resource")) { + operationOutcomeMessage = { + code : 400 , + msg : handleError.processing(err.message) + }; + } else { + operationOutcomeMessage = { + code : 500 , + msg : handleError.exception(err.message) + }; + } + logger.error(`[Error: ${JSON.stringify(operationOutcomeMessage)}] [Resource Type: ${resourceType}] [From-File: ${PWD_FILENAME}]`); + return doResCallback(operationOutcomeMessage.code , operationOutcomeMessage.msg); + } +}; /** * @param {import("express").Request} req * @param {import("express").Response} res @@ -16,6 +73,7 @@ const validateContained = require('./validateContained'); * @returns */ module.exports = async function(req, res , resourceType) { + logger.info(`[Info: do create] [Resource Type: ${resourceType}] [From-File: ${PWD_FILENAME}] [Content-Type: ${res.getHeader("content-type")}]`); let doRes = function (code , item) { if (res.getHeader("content-type").includes("xml")) { let fhir = new FHIR(); @@ -25,45 +83,10 @@ module.exports = async function(req, res , resourceType) { return res.status(code).send(item); }; if (!await user.checkTokenPermission(req, resourceType, "create")) { + logger.warn(`[Warn: Request token doesn't have permission with this API] [From-File: ${PWD_FILENAME}] [From-IP: ${req.socket.remoteAddress}]`); return doRes(403,handleError.forbidden("Your token doesn't have permission with this API")); } - console.log(`doPost-create ${resourceType}`); try { - let resFunc = { - "true": (doc) => { - let reqBaseUrl = `${req.protocol}://${req.get('host')}/`; - let fullAbsoluteUrl = new URL(req.originalUrl, reqBaseUrl).href; - res.set("Location", fullAbsoluteUrl); - res.append("Last-Modified", (new Date()).toUTCString()); - console.log(`create ${resourceType} id: ${doc.id} successfully`); - return doRes(201 , doc); - }, - "false": (err) => { - let operationOutcomeMessage; - if (err.message.code == 11000) { - operationOutcomeMessage = { - code : 409 , - msg : handleError.duplicate(err.message) - }; - } else if (err.stack.includes("ValidationError")) { - operationOutcomeMessage = { - code : 400 , - msg : handleError.processing(err.message) - }; - } else if (err.stack.includes("stored by resource")) { - operationOutcomeMessage = { - code : 400 , - msg : handleError.processing(err.message) - }; - } else { - operationOutcomeMessage = { - code : 500 , - msg : handleError.exception(err.message) - }; - } - return doRes(operationOutcomeMessage.code , operationOutcomeMessage.msg); - } - }; let insertData = req.body; if (_.get(insertData, "contained")) { let containedResources = _.get(insertData, "contained"); @@ -72,6 +95,7 @@ module.exports = async function(req, res , resourceType) { let validation = await validateContained(resource, index); if (!validation.status) { let operationOutcomeError = handleError.processing(`The resource in contained error. ${validation.message}`); + logger.error(`[Error: ${JSON.stringify(operationOutcomeError)}] [Resource Type: ${resourceType}] [From-File: ${PWD_FILENAME}]`); return doRes(400, operationOutcomeError); } } @@ -82,13 +106,15 @@ module.exports = async function(req, res , resourceType) { let notExistReferenceList = getNotExistReferenceList(checkReferenceRes); let operationOutcomeError = handleError.processing(`The reference not found : ${_.map(notExistReferenceList , "value").join(",")}`); _.set(operationOutcomeError , "issue.0.location" , _.map(notExistReferenceList , "path")); + logger.error(`[Error: ${JSON.stringify(operationOutcomeError)}] [Resource Type: ${resourceType}] [From-File: ${PWD_FILENAME}]`); return doRes(400, operationOutcomeError); } } let [status, doc] = await doInsertData(insertData, resourceType); - return resFunc[status](doc); + return responseFunc[status](doc, req, res, resourceType, doRes); } catch (e) { - console.error(e); + let errorStr = JSON.stringify(e, Object.getOwnPropertyNames(e)); + logger.error(`[Error: ${errorStr})}] [Resource Type: ${resourceType}] [From-File: ${PWD_FILENAME}]`); let operationOutcomeError = handleError.exception(e); return doRes(500 , operationOutcomeError); } @@ -103,7 +129,8 @@ async function doInsertData(insertData , resourceType) { let doc = await insertDataObject.save(); return [true, doc.getFHIRField()]; } catch (e) { - console.error(e); + let errorStr = JSON.stringify(e, Object.getOwnPropertyNames(e)); + logger.error(`[Error: ${errorStr}] [Resource Type: ${resourceType}] [From-File: ${PWD_FILENAME}]`); return [false , e]; } } \ No newline at end of file diff --git a/api/FHIRApiService/delete.js b/api/FHIRApiService/delete.js index 05e4a83f..c9b53fe3 100644 --- a/api/FHIRApiService/delete.js +++ b/api/FHIRApiService/delete.js @@ -6,6 +6,47 @@ const { const _ = require('lodash'); const FHIR = require('../../models/FHIR/fhir/fhir').Fhir; const user = require('../APIservices/user.service'); +const { logger } = require('../../utils/log'); +const path = require('path'); +const PWD_FILENAME = path.relative(process.cwd(), __filename); + +const responseFunc = { + /** + * + * @param {Object} doc + * @param {import('express').Request} req express request + * @param {import('express').Response} res express response + * @param {string} resourceType resource type + * @param {function} doResCallback callback function + * @returns + */ + "true": (doc, req, res, resourceType, doCallback) => { + if (!doc) { + let errorMessage = `not found ${resourceType}/${req.params.id}`; + logger.warn(`[Warn: ${errorMessage}] [Resource-Type: ${resourceType}]`); + return doCallback(404, handleError["not-found"](errorMessage)); + } + return doCallback(200, getDeleteMessage(resourceType, req.params.id)); + }, + /** + * + * @param {Object} err + * @param {import('express').Request} req express request + * @param {import('express').Response} res express response + * @param {string} resourceType resource type + * @param {function} doResCallback callback function + * @returns + */ + "false": (err, req, res, resourceType, doCallback) => { + if (_.isString(err)) { + if (err.includes("not found")) { + return doCallback(404, handleError['not-found'](err)); + } + return doCallback(500, handleError.exception(err)); + } + return doCallback(500, handleError.exception(err.message)); + } +}; /** * @param {import("express").Request} req @@ -13,8 +54,9 @@ const user = require('../APIservices/user.service'); * @param {String} resourceType * @returns */ -module.exports = async function(req, res, resourceType) { - let doRes = function (code , item) { +module.exports = async function (req, res, resourceType) { + logger.info(`[Info: do delete by id, id: ${req.params.id}] [Resource Type: ${resourceType}] [From-File: ${PWD_FILENAME}] [Content-Type: ${res.getHeader("content-type")}]`); + let doRes = function (code, item) { if (res.getHeader("content-type").includes("xml")) { let fhir = new FHIR(); let xmlItem = fhir.objToXml(item); @@ -23,28 +65,11 @@ module.exports = async function(req, res, resourceType) { return res.status(code).send(item); }; if (!await user.checkTokenPermission(req, resourceType, "delete")) { + logger.warn(`[Warn: Request token doesn't have permission with this API] [From-File: ${PWD_FILENAME}] [From-IP: ${req.socket.remoteAddress}]`); return doRes(403,handleError.forbidden("Your token doesn't have permission with this API")); } - let resFunc = { - "true": (doc) => { - if (!doc) { - let errorMessage = `not found ${resourceType}/${req.params.id}`; - return doRes(404,handleError["not-found"](errorMessage)); - } - return doRes(200,getDeleteMessage(resourceType, req.params.id)); - }, - "false": (err) => { - if (_.isString(err)) { - if (err.includes("not found")) { - return doRes(404, handleError['not-found'](err)); - } - return doRes(500,handleError.exception(err)); - } - return doRes(500,handleError.exception(err.message)); - } - }; let [status, doc] = await doDeleteData(req, resourceType); - return resFunc[status.toString()](doc); + return responseFunc[status.toString()](doc, req, res, resourceType, doRes); }; async function doDeleteData(req, resourceType) { @@ -54,7 +79,8 @@ async function doDeleteData(req, resourceType) { id: id }, (err, doc) => { if (err) { - console.error(err); + let errorStr = JSON.stringify(err, Object.getOwnPropertyNames(err)); + logger.error(`[Error ${errorStr}] [Resource Type: ${resourceType}] [From-File: ${PWD_FILENAME}]`); return resolve([false, err]); } return resolve([true, doc]); diff --git a/api/FHIRApiService/history.js b/api/FHIRApiService/history.js index 71480deb..40864eb9 100644 --- a/api/FHIRApiService/history.js +++ b/api/FHIRApiService/history.js @@ -6,6 +6,9 @@ const { const FHIR = require('../../models/FHIR/fhir/fhir').Fhir; const { handleError } = require('../../models/FHIR/httpMessage'); const user = require('../APIservices/user.service'); +const { logger } = require('../../utils/log'); +const path = require('path'); +const PWD_FILENAME = path.relative(process.cwd(), __filename); /** * @param {import("express").Request} req @@ -14,6 +17,7 @@ const user = require('../APIservices/user.service'); * @returns */ module.exports = async function(req, res, resourceType) { + logger.info(`[Info: do history-instance by id, id: ${req.params.id}] [Resource Type: ${resourceType}] [From-File: ${PWD_FILENAME}] [Content-Type: ${res.getHeader("content-type")}] [Url-SearchParam: ${req.url}] `); let doRes = function (code , item) { if (res.getHeader("content-type").includes("xml")) { let fhir = new FHIR(); @@ -23,6 +27,7 @@ module.exports = async function(req, res, resourceType) { return res.status(code).send(item); }; if (!await user.checkTokenPermission(req, resourceType, "history")) { + logger.warn(`[Warn: Request token doesn't have permission with this API] [From-File: ${PWD_FILENAME}] [From-IP: ${req.socket.remoteAddress}]`); return doRes(403,handleError.forbidden("Your token doesn't have permission with this API")); } let queryParameter = _.cloneDeep(req.query); @@ -31,7 +36,6 @@ module.exports = async function(req, res, resourceType) { let paginationLimit = queryParameter['_count'] == undefined ? 100 : queryParameter['_count']; _.set(req.query, "_offset", paginationSkip); _.set(req.query, "_count", paginationLimit); - let realLimit = paginationLimit + paginationSkip; delete queryParameter['_count']; delete queryParameter['_offset']; try { @@ -60,7 +64,8 @@ module.exports = async function(req, res, resourceType) { res.header('Last-Modified', new Date().toUTCString()); return doRes(200, bundle); } catch (e) { - console.log(`api ${process.env.FHIRSERVER_APIPATH}/${resourceType}/:id/history has error, `, e); + let errorStr = JSON.stringify(e, Object.getOwnPropertyNames(e)); + logger.error(`[Error: ${errorStr})}] [Resource Type: ${resourceType}] [From-File: ${PWD_FILENAME}]`); let operationOutcomeError = handleError.exception(e); return doRes(500, operationOutcomeError); } diff --git a/api/FHIRApiService/read.js b/api/FHIRApiService/read.js index 2bd4b316..c12c0d2b 100644 --- a/api/FHIRApiService/read.js +++ b/api/FHIRApiService/read.js @@ -4,6 +4,9 @@ const { } = require('../../models/FHIR/httpMessage'); const FHIR = require('../../models/FHIR/fhir/fhir').Fhir; const user = require('../APIservices/user.service'); +const { logger } = require('../../utils/log'); +const path = require('path'); +const PWD_FILENAME = path.relative(process.cwd(), __filename); /** * @param {import("express").Request} req @@ -12,6 +15,7 @@ const user = require('../APIservices/user.service'); * @returns */ module.exports = async function (req , res , resourceType) { + logger.info(`[Info: do create] [Resource Type: ${resourceType}] [From-File: ${PWD_FILENAME}] [Content-Type: ${res.getHeader("content-type")}]`); let doRes = function (code, item) { if (res.getHeader("content-type").includes("xml")) { let fhir = new FHIR(); @@ -21,6 +25,7 @@ module.exports = async function (req , res , resourceType) { return res.status(code).send(item); }; if (!await user.checkTokenPermission(req, resourceType, "read")) { + logger.warn(`[Warn: Request token doesn't have permission with this API] [From-File: ${PWD_FILENAME}] [From-IP: ${req.socket.remoteAddress}]`); return doRes(403,handleError.forbidden("Your token doesn't have permission with this API")); } let id = req.params.id; @@ -34,10 +39,12 @@ module.exports = async function (req , res , resourceType) { return doRes(200, responseDoc); } let errorMessage = `not found ${resourceType}/${id}`; + logger.warn(`[Warn: ${errorMessage}] [Resource-Type: ${resourceType}]`); let operationOutcomeError = handleError.exception(errorMessage); return doRes(404, operationOutcomeError); } catch (e) { - console.log(`api ${process.env.FHIRSERVER_APIPATH}/${resourceType}/:id has error, `, e); + let errorStr = JSON.stringify(e, Object.getOwnPropertyNames(e)); + logger.error(`[Error: ${errorStr}] [Resource Type: ${resourceType}] [From-File: ${PWD_FILENAME}]`); let operationOutcomeError = handleError.exception(e); return doRes(500, operationOutcomeError); } diff --git a/api/FHIRApiService/search.js b/api/FHIRApiService/search.js index 1221a1f8..f08dccc9 100644 --- a/api/FHIRApiService/search.js +++ b/api/FHIRApiService/search.js @@ -11,6 +11,9 @@ const { const FHIR = require('../../models/FHIR/fhir/fhir').Fhir; const { isRealObject } = require('../apiService'); const user = require('../APIservices/user.service'); +const { logger } = require('../../utils/log'); +const path = require('path'); +const PWD_FILENAME = path.relative(process.cwd(), __filename); /** * @@ -21,6 +24,7 @@ const user = require('../APIservices/user.service'); * @returns */ module.exports = async function(req, res, resourceType, paramsSearch) { + logger.info(`[Info: do search] [Resource Type: ${resourceType}] [From-File: ${PWD_FILENAME}] [Content-Type: ${res.getHeader("content-type")}] [Url-SearchParam: ${req.url}]`); let doRes = function (code , item) { if (res.getHeader("content-type").includes("xml")) { let fhir = new FHIR(); @@ -30,7 +34,8 @@ module.exports = async function(req, res, resourceType, paramsSearch) { return res.status(code).send(item); }; if (!await user.checkTokenPermission(req, resourceType, "search-type")) { - return doRes(403,handleError.forbidden("Your token doesn't have permission with this API")); + logger.warn(`[Warn: Request token doesn't have permission with this API] [From-File: ${PWD_FILENAME}] [From-IP: ${req.socket.remoteAddress}]`); + return doRes(403,handleError.forbidden("token doesn't have permission with this API")); } let queryParameter = _.cloneDeep(req.query); let paginationSkip = queryParameter['_offset'] == undefined ? 0 : queryParameter['_offset']; @@ -50,7 +55,7 @@ module.exports = async function(req, res, resourceType, paramsSearch) { paramsSearch[key](queryParameter); } catch (e) { if (key != "$and") { - console.error(e); + logger.error(`[Error: Unknown search parameter ${key} or value ${queryParameter[key]}] [Resource Type: ${resourceType}] [From-File: ${PWD_FILENAME}] [${e}]`); return doRes(400 , handleError.processing(`Unknown search parameter ${key} or value ${queryParameter[key]}`)); } } @@ -83,7 +88,8 @@ module.exports = async function(req, res, resourceType, paramsSearch) { bundle.entry = _.uniqBy(bundle.entry, "fullUrl"); return doRes(200 , bundle); } catch (e) { - console.error(`api ${process.env.FHIRSERVER_APIPATH}/${resourceType}/ has error, `, e); + let errorStr = JSON.stringify(e, Object.getOwnPropertyNames(e)); + logger.error(`[Error: ${errorStr}] [Resource Type: ${resourceType}] [From-File: ${PWD_FILENAME}]`); if (_.get(e, "code")) { return doRes(e.code , e.operationOutcome); } diff --git a/api/FHIRApiService/update.js b/api/FHIRApiService/update.js index f77a8aea..d135f6d7 100644 --- a/api/FHIRApiService/update.js +++ b/api/FHIRApiService/update.js @@ -7,6 +7,9 @@ const user = require('../APIservices/user.service'); const FHIR = require('../../models/FHIR/fhir').Fhir; const validateContained = require('./validateContained'); const { checkReference, getNotExistReferenceList } = require('../apiService'); +const { logger } = require('../../utils/log'); +const path = require('path'); +const PWD_FILENAME = path.relative(process.cwd(), __filename); /** * @param {import("express").Request} req @@ -15,6 +18,7 @@ const { checkReference, getNotExistReferenceList } = require('../apiService'); * @returns */ module.exports = async function (req, res, resourceType) { + logger.info(`[Info: do create] [Resource Type: ${resourceType}] [From-File: ${PWD_FILENAME}] [Content-Type: ${res.getHeader("content-type")}]`); let doRes = function (code, item) { if (res.getHeader("content-type").includes("xml")) { let fhir = new FHIR(); @@ -24,6 +28,7 @@ module.exports = async function (req, res, resourceType) { return res.status(code).send(item); }; if (!await user.checkTokenPermission(req, resourceType, "update")) { + logger.warn(`[Warn: Request token doesn't have permission with this API] [From-File: ${PWD_FILENAME}] [From-IP: ${req.socket.remoteAddress}]`); return doRes(403,handleError.forbidden("Your token doesn't have permission with this API")); } let resFunc = { @@ -85,12 +90,11 @@ module.exports = async function (req, res, resourceType) { } let dataExist = await isDocExist(req.params.id, resourceType); if (dataExist.status == 0) { + let errorStr = JSON.stringify(dataExist.error, Object.getOwnPropertyNames(dataExist.error)); + logger.error(`[Error: ${errorStr})}] [Resource Type: ${resourceType}] [From-File: ${PWD_FILENAME}]`); return doRes(500, handleError.exception(dataExist.error)); } let dataFuncAfterCheckExist = { - 0: (req,resourceType) => { - return ["false", ""]; - }, 1: doUpdateData, 2: doInsertData }; diff --git a/api/FHIRApiService/vread.js b/api/FHIRApiService/vread.js index 5478339d..46a044e0 100644 --- a/api/FHIRApiService/vread.js +++ b/api/FHIRApiService/vread.js @@ -4,6 +4,9 @@ const { } = require('../../models/FHIR/httpMessage'); const FHIR = require('../../models/FHIR/fhir/fhir').Fhir; const user = require('../APIservices/user.service'); +const { logger } = require('../../utils/log'); +const path = require('path'); +const PWD_FILENAME = path.relative(process.cwd(), __filename); /** * @param {import("express").Request} req @@ -12,6 +15,7 @@ const user = require('../APIservices/user.service'); * @returns */ module.exports = async function(req, res, resourceType) { + logger.info(`[Info: do vread] [Resource Type: ${resourceType}] [From-File: ${PWD_FILENAME}] [Content-Type: ${res.getHeader("content-type")}]`); let doRes = function (code , item) { if (res.getHeader("content-type").includes("xml")) { let fhir = new FHIR(); @@ -21,6 +25,7 @@ module.exports = async function(req, res, resourceType) { return res.status(code).send(item); }; if (!await user.checkTokenPermission(req, resourceType, "vread")) { + logger.warn(`[Warn: Request token doesn't have permission with this API] [From-File: ${PWD_FILENAME}] [From-IP: ${req.socket.remoteAddress}]`); return doRes(403,handleError.forbidden("Your token doesn't have permission with this API")); } let id = req.params.id; diff --git a/config/log4js.json b/config/log4js.json index 27f5c176..5f713e2d 100644 --- a/config/log4js.json +++ b/config/log4js.json @@ -3,12 +3,20 @@ "burni-info": { "type": "file", "filename": "log/burni-info.log", - "maxLogSize": 10485760, - "numBackups": 3 + "maxLogSize": 104857600, + "backups": 3 }, "burni-error": { "type": "file", - "filename": "log/errors.log" + "filename": "log/errors.log", + "maxLogSize": 104857600, + "backups": 3 + }, + "burni-warning": { + "type": "file", + "filename": "log/warn.log", + "maxLogSize": 104857600, + "backups": 3 }, "errors": { "type": "logLevelFilter", @@ -21,6 +29,12 @@ "maxLevel": "INFO", "appender": "burni-info" }, + "warns": { + "type": "logLevelFilter", + "level": "WARN", + "maxLevel": "WARN", + "appender": "burni-warning" + }, "console": { "type": "console" } @@ -29,6 +43,7 @@ "default": { "appenders": [ "infos", + "warns", "errors", "console" ],