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

[bug] it does not create the file again when it's writing #92

Open
rnavarroz opened this issue Jun 28, 2023 · 1 comment
Open

[bug] it does not create the file again when it's writing #92

rnavarroz opened this issue Jun 28, 2023 · 1 comment

Comments

@rnavarroz
Copy link

I am wondering if it would be possible to recreate the file if for some reason was deleted by an external operation after you have created the stream, for example, if you run the following code, once created the directory and the file you delete manually the file leaving empty the directory, then in theory the stream should continue writing into the file which it means it should create the file again if it does not exist.

const path = require('path');
const { createStream } = require('rotating-file-stream');

const dir = 'test-logs';

const options = {
  interval: '1m',
  path: path.resolve(process.cwd(), dir),
  immutable: true
};

const stream = createStream('test.log', options);

setTimeout(() => {}, 600000);

let count = 0;

function write() {
  stream.write(`write ${++count}\n`);
  setTimeout(write, Math.random() * 10).unref();
}

write();

Current Result:
The file is not created again therefore nothing is recorded when stream.write is called.

Expected Result:
It should create the file in case it does not exist if stream.write is being called

@iccicci
Copy link
Owner

iccicci commented Jun 28, 2023

Yes.

Currently the package emulates the native fs.createWriteStream which has the same behaviour as the one reported.

Anyway I understand this could be a nice enhancment to the package. I'll rework this

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