From 1e876268a069009afd1e61e9d5afbd3eb5e91af7 Mon Sep 17 00:00:00 2001 From: Thibault Patois Date: Fri, 17 Aug 2018 15:19:47 +0200 Subject: [PATCH 1/2] Replace dynamic requires with readFileSync --- FileStreamRotator.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/FileStreamRotator.js b/FileStreamRotator.js index f1b9208..9564283 100644 --- a/FileStreamRotator.js +++ b/FileStreamRotator.js @@ -200,10 +200,10 @@ FileStreamRotator.setAuditLog = function (max_logs, audit_file, log_file){ try{ if(audit_file){ var full_path = path.resolve(audit_file); - _rtn = require(full_path); + _rtn = fs.readFileSync(full_path, { encoding: 'utf-8' }); }else{ var full_path = path.resolve(baseLog + "/" + ".audit.json") - _rtn = require(full_path); + _rtn = fs.readFileSync(full_path, { encoding: 'utf-8' }); } }catch(e){ if(e.code !== "MODULE_NOT_FOUND"){ From e1670ce3bfa475b6d501c8059098e119587b9402 Mon Sep 17 00:00:00 2001 From: Thibault Patois Date: Fri, 17 Aug 2018 16:52:12 +0200 Subject: [PATCH 2/2] Add json parsing --- FileStreamRotator.js | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/FileStreamRotator.js b/FileStreamRotator.js index 9564283..4744ba8 100644 --- a/FileStreamRotator.js +++ b/FileStreamRotator.js @@ -196,17 +196,16 @@ FileStreamRotator.setAuditLog = function (max_logs, audit_file, log_file){ if(Number(_num[1]) > 0) { var baseLog = path.dirname(log_file.replace(/%DATE%.+/,"_filename")); - try{ if(audit_file){ var full_path = path.resolve(audit_file); - _rtn = fs.readFileSync(full_path, { encoding: 'utf-8' }); + _rtn = JSON.parse(fs.readFileSync(full_path, { encoding: 'utf-8' })); }else{ var full_path = path.resolve(baseLog + "/" + ".audit.json") - _rtn = fs.readFileSync(full_path, { encoding: 'utf-8' }); + _rtn = JSON.parse(fs.readFileSync(full_path, { encoding: 'utf-8' })); } }catch(e){ - if(e.code !== "MODULE_NOT_FOUND"){ + if(e.code !== "ENOENT"){ return null; } _rtn = {