Logs added to the file is not displayed on Windows
teid opened this issue · 4 comments
Hi :)
First I wanted to thank you for this project. I've used it on Linux and it's a great tool !
Recently, I tried to use it on Windows Server 2016 with a Java application and log4j.
When the application adds some lines in the log file, I don't see the update in frontail.
Even if I reload the browser.
But, when I open the log file on the server with another program like Notepad++, the logs are instantly loaded in frontail.
This looks like the behavior described here:
https://docs.microsoft.com/en-us/archive/blogs/asiasupp/file-date-modified-property-are-not-updating-while-modifying-a-file-without-closing-it
They suggest to open and close a handle on the log file.
Would you accept to do this in frontail ?
Regards,
Timothée
I modified frontail to use node-tail instead of fs-tail-stream
I changed the file lib/tail.js
(it's a rough implementation, I did not take the time to report every features like stdin, initial number of lines and native tail):
/* eslint no-underscore-dangle: off */
'use strict';
const events = require('events');
const childProcess = require('child_process');
const TailLib = require('tail').Tail;
const util = require('util');
const CBuffer = require('CBuffer');
const byline = require('byline');
const commandExistsSync = require('command-exists').sync;
function Tail(path, opts) {
events.EventEmitter.call(this);
const options = opts || {
buffer: 0
};
this._buffer = new CBuffer(options.buffer);
let tail = new TailLib(path.join(), {
encoding: 'utf-8',
follow: true,
useWatchFile: true,
flushAtEOF: true
});
tail.on("line", (line) => {
const str = line.toString();
this._buffer.push(str);
this.emit('line', str);
});
}
util.inherits(Tail, events.EventEmitter);
Tail.prototype.getBuffer = function getBuffer() {
return this._buffer.toArray();
};
module.exports = (path, options) => new Tail(path, options);
It's the option useWatchFile: true
of the lib node-tail that made it work on Windows
Hey,
Can you create a PR for that?
Sure I can do that.
When useWatchFile
is set to true, fs.watchFile will be used instead of fs.watch
fs.watchFile
is less efficient that fs.watch
, maybe we can enable it only on Windows ? Or do you want it to be an option ?
I think it makes sense to enable that only on windows