diff --git a/common/logger.js b/common/logger.js index fdd93b79ad7f65dbcc042aaf5f01c07ffa56b015..de288aa5035e789a37d77005e137818cfeea15e5 100644 --- a/common/logger.js +++ b/common/logger.js @@ -21,13 +21,6 @@ const __loggerCustomLevels = { warning: 1, error: 0, }, - colors: { - debug: 'blue', - info: 'green', - warn: 'yellow', - warning: 'yellow', - error: 'red', - }, }; const __logFile = `${require('os').tmpdir()}/amadeus.log`; @@ -51,10 +44,10 @@ var __logger = winston.createLogger({ format: winston.format.combine( winston.format.timestamp({ format: 'YYYY-MM-DD HH:mm:ss' }), winston.format.label(), - winston.format.colorize({ all: true }), winston.format.simple(), + winston.format.align(), winston.format.printf(({ level, message, label, timestamp }) => { - return `[${timestamp}] ${message}`; + return `[${timestamp}] ${level} ${message}`; }) ), }); diff --git a/instance/log.ejs b/instance/log.ejs index e3068e57a609f2db7b4170a26b5f2144a8f148ff..c01129c582099b768404806de32aec3719bee600 100644 --- a/instance/log.ejs +++ b/instance/log.ejs @@ -10,12 +10,25 @@ </script> <script src="../style/bootstrap-4.5.2-dist/js/bootstrap.min.js"></script> <link rel="stylesheet" href="../style/bootstrap-4.5.2-dist/css/bootstrap.min.css" /> - <link rel="stylesheet" href="../style/css/instance.css" /> <link rel="stylesheet" href="../style/fontawesome-free-5.15.1-web/css/all.min.css" /> <script src="./log.js"></script> <script></script> </head> - <body id="body"> + <body style='overflow-y: scroll; height: 100%;'> + <div style='border-color: #abb6c2; border-style: solid; border-top: none; height: 100%;'> + <table class='table table-sm' style='margin: 0px;'> + <thead class='thead-light' + style='position: sticky; position: -webkit-sticky; top: 0; z-index: 999;'> + <tr> + <th style='border: 0px; position: sticky; position: -webkit-sticky; top: 0; z-index: 999;'>Timestamp</th> + <th style='border: 0px; position: sticky; position: -webkit-sticky; top: 0; z-index: 999;'>Label</th> + <th style='border: 0px; position: sticky; position: -webkit-sticky; top: 0; z-index: 999;'>Message</th> + </tr> + </thead> + <tbody id='body'> + </tbody> + </table> + </div> </body> </html> diff --git a/instance/log.js b/instance/log.js index cdfe2799c74cf9a2e0ae06fd9fbd4956e5a50ae8..5dba3f87303237f25f013e8dd3d5fabcaaf1469a 100644 --- a/instance/log.js +++ b/instance/log.js @@ -5,13 +5,29 @@ const { ipcRenderer } = require('electron'), ejs = require('ejs'), e = require('express'), fs = require('fs'), - readline = require('readline'); + readline = require('readline'), + Tail = require('tail').Tail; -const file = readline.createInterface({ - input: fs.createReadStream(config.file), - terminal: false, -}); +var file = new Tail(logger.logfile, { fromBeginning: false, follow: true, nLines: 100 }); file.on('line', line => { - console.log(line); + const regexp = /^\[[^ ]+([^\]]+)\] ([^ ]+) +([^ ]+) +\| +(.*)$/; + const match = line.match(regexp).slice(1); + $('#body').append( + `<tr ${ + match[1] === 'error' + ? 'class="table-danger"' + : match[1] === 'warn' + ? 'class="table-warning"' + : match[1] === 'info' + ? 'class="table-info"' + : '' + }> + <td>${match[0]}</td> + <td>${match[2]}</td> + <td>${match[3]}</td> + </tr>` + ); }); + +window.onload = () => {}; diff --git a/main.js b/main.js index 0007559775c0404a383c7ff2a8b86d58eaf17e90..d9f486a01f1b89e864143d913f02f326e504e35a 100644 --- a/main.js +++ b/main.js @@ -14,7 +14,7 @@ logger.debug('main', 'Package config is ' + JSON.stringify(packageConfig)); var config = require('./common/config.js'); var db = require.main.require('./common/db.js'); -var tail = require('tail').Tail; +var Tail = require('tail').Tail; var client; /* Sub process for the express server */ @@ -75,7 +75,7 @@ var win = null; /* The main window */ **********************/ fs.truncate(logger.logfile, 0, () => {}); -var tail = new tail(logger.logfile); +var tail = new Tail(logger.logfile); tail.on('line', function (data) { console.log(data); }); @@ -91,7 +91,7 @@ function defaultWindowOptions(title) { height: 360, hasShadow: false, frame: true, - menuBarVisible: true, + menuBarVisible: false, webPreferences: { nodeIntegration: true, worldSafeExecuteJavaScript: true, @@ -130,6 +130,7 @@ function createLogWindow() { /* Log window */ const opt = defaultWindowOptions('Amadeus - Log window'); opt.parent = win; + opt.frame = false; opt.webPreferences.contextIsolation = false; /* XXX: Otherwise 'require' is not defined in instance/index.html */ const logwindow = new BrowserWindow(opt); logwindow.loadURL(`file://${__dirname}/instance/log.ejs`);