Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Logs added to the file is not displayed on Windows #197

Open
teid opened this issue Mar 6, 2020 · 4 comments
Open

Logs added to the file is not displayed on Windows #197

teid opened this issue Mar 6, 2020 · 4 comments

Comments

@teid
Copy link

teid commented Mar 6, 2020

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

@teid
Copy link
Author

teid commented 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

@mthenw
Copy link
Owner

mthenw commented Mar 14, 2020

Hey,

Can you create a PR for that?

@teid
Copy link
Author

teid commented 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 ?

@mthenw
Copy link
Owner

mthenw commented Mar 16, 2020

I think it makes sense to enable that only on windows

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants