Added file logging support.

Ylian Saint-Hilaire committed Nov 16, 2019 at 12:13 UTC 7209a2296998c976b1d5d301eb41522543d3c8e5
2 files changed +16 -1
meshcentral.js
+15
@@ -1833,6 +1833,21 @@ function CreateMeshCentralServer(config, args) {
1833 // Send event to console
1834 if ((obj.debugSources != null) && ((obj.debugSources == '*') || (obj.debugSources.indexOf(source) >= 0))) { console.log(source.toUpperCase() + ':', ...args); }
1835
1836 + // Send event to log file
1837 + if (obj.config.settings && obj.config.settings.log) {
1838 + if (typeof obj.config.settings.log == 'string') { obj.config.settings.log = obj.config.settings.log.split(','); }
1839 + if (obj.config.settings.log.indexOf(source) >= 0) {
1840 + const d = new Date();
1841 + if (obj.xxLogFile == null) { try { obj.xxLogFile = obj.fs.openSync(obj.getConfigFilePath('log.txt'), 'a+', 666); } catch (ex) { } }
1842 + if (obj.xxLogFile != null) {
1843 + try {
1844 + if (obj.xxLogDateStr != d.toLocaleDateString()) { obj.xxLogDateStr = d.toLocaleDateString(); obj.fs.writeSync(obj.xxLogFile, '---- ' + d.toLocaleDateString() + ' ----\r\n'); }
1845 + obj.fs.writeSync(obj.xxLogFile, new Date().toLocaleTimeString() + ' - ' + source + ': ' + Array.prototype.slice.call(...args).join('') + '\r\n');
1846 + } catch (ex) { }
1847 + }
1848 + }
1849 + }
1850 +
1851 // Send the event to logged in administrators
1852 if ((obj.debugRemoteSources != null) && ((obj.debugRemoteSources == '*') || (obj.debugRemoteSources.indexOf(source) >= 0))) {
1853 var sendcount = 0;
package.json
+1 -1
@@ -1,6 +1,6 @@
1 {
2 "name": "meshcentral",
3 - "version": "0.4.4-f",
3 + "version": "0.4.4-g",
4 "keywords": [
5 "Remote Management",
6 "Intel AMT",