From 7209a2296998c976b1d5d301eb41522543d3c8e5 Mon Sep 17 00:00:00 2001 From: Ylian Saint-Hilaire Date: Sat, 16 Nov 2019 12:13:04 -0800 Subject: [PATCH] Added file logging support. --- meshcentral.js | 15 +++++++++++++++ package.json | 2 +- 2 files changed, 16 insertions(+), 1 deletion(-) diff --git a/meshcentral.js b/meshcentral.js index 342afdd1..18d00a15 100644 --- a/meshcentral.js +++ b/meshcentral.js @@ -1833,6 +1833,21 @@ function CreateMeshCentralServer(config, args) { // Send event to console if ((obj.debugSources != null) && ((obj.debugSources == '*') || (obj.debugSources.indexOf(source) >= 0))) { console.log(source.toUpperCase() + ':', ...args); } + // Send event to log file + if (obj.config.settings && obj.config.settings.log) { + if (typeof obj.config.settings.log == 'string') { obj.config.settings.log = obj.config.settings.log.split(','); } + if (obj.config.settings.log.indexOf(source) >= 0) { + const d = new Date(); + if (obj.xxLogFile == null) { try { obj.xxLogFile = obj.fs.openSync(obj.getConfigFilePath('log.txt'), 'a+', 666); } catch (ex) { } } + if (obj.xxLogFile != null) { + try { + if (obj.xxLogDateStr != d.toLocaleDateString()) { obj.xxLogDateStr = d.toLocaleDateString(); obj.fs.writeSync(obj.xxLogFile, '---- ' + d.toLocaleDateString() + ' ----\r\n'); } + obj.fs.writeSync(obj.xxLogFile, new Date().toLocaleTimeString() + ' - ' + source + ': ' + Array.prototype.slice.call(...args).join('') + '\r\n'); + } catch (ex) { } + } + } + } + // Send the event to logged in administrators if ((obj.debugRemoteSources != null) && ((obj.debugRemoteSources == '*') || (obj.debugRemoteSources.indexOf(source) >= 0))) { var sendcount = 0; diff --git a/package.json b/package.json index 197bee6b..91a39ee1 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "meshcentral", - "version": "0.4.4-f", + "version": "0.4.4-g", "keywords": [ "Remote Management", "Intel AMT",