[GH-ISSUE #197] Logs added to the file is not displayed on Windows #130

Open
opened 2026-03-03 16:04:40 +03:00 by kerem · 4 comments
Owner

Originally created by @teid on GitHub (Mar 6, 2020).
Original GitHub issue: https://github.com/mthenw/frontail/issues/197

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

Originally created by @teid on GitHub (Mar 6, 2020). Original GitHub issue: https://github.com/mthenw/frontail/issues/197 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
Author
Owner

@teid commented on GitHub (Mar 11, 2020):

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

<!-- gh-comment-id:597735278 --> @teid commented on GitHub (Mar 11, 2020): I modified frontail to use [node-tail](https://github.com/lucagrulla//node-tail) instead of [fs-tail-stream](https://github.com/eugeneware/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): ```js /* 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
Author
Owner

@mthenw commented on GitHub (Mar 14, 2020):

Hey,

Can you create a PR for that?

<!-- gh-comment-id:599132584 --> @mthenw commented on GitHub (Mar 14, 2020): Hey, Can you create a PR for that?
Author
Owner

@teid commented on GitHub (Mar 15, 2020):

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 ?

<!-- gh-comment-id:599193175 --> @teid commented on GitHub (Mar 15, 2020): Sure I can do that. When `useWatchFile` is set to true, [fs.watchFile](https://nodejs.org/api/fs.html#fs_fs_watchfile_filename_options_listener) will be used instead of [fs.watch](https://nodejs.org/api/fs.html#fs_fs_watch_filename_options_listener) `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 ?
Author
Owner

@mthenw commented on GitHub (Mar 16, 2020):

I think it makes sense to enable that only on windows

<!-- gh-comment-id:599585994 --> @mthenw commented on GitHub (Mar 16, 2020): I think it makes sense to enable that only on windows
Sign in to join this conversation.
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
starred/frontail#130
No description provided.