Skip to content
Extraits de code Groupes Projets
Vérifiée Valider a1c7ed5c rédigé par Kubat's avatar Kubat
Parcourir les fichiers

Add basic log window

parent 7dbcd676
Aucune branche associée trouvée
Aucune étiquette associée trouvée
1 requête de fusion!13Dev kubat: More work done on the instance
......@@ -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}`;
})
),
});
......
......@@ -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>
......@@ -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 = () => {};
......@@ -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`);
......
0% Chargement en cours ou .
You are about to add 0 people to the discussion. Proceed with caution.
Veuillez vous inscrire ou vous pour commenter