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

Fix: End logger after ensuring flushing file transport is done #25737 #25851

Open
wants to merge 1 commit into
base: dev
Choose a base branch
from

Conversation

manuelkue
Copy link

@manuelkue manuelkue commented Jan 16, 2025

I've seen that the logger is not ended anymore after #25737
If that behavior is fine this PR can be closed, otherwise I'd like to contribute a fix :)

By moving the this.logger.end() after the await, it is ensured that the Promise resolves before ending the logger.
This way the fileTransport's finish event has to happen before the end() is executed.
If there's no active fileTransport the logger can be ended immediately.

@manuelkue manuelkue changed the base branch from master to dev January 16, 2025 15:51
@manuelkue manuelkue force-pushed the fix/end-logger-after-flushing-file-transport branch from a27321c to b30c452 Compare January 16, 2025 15:54
@Koenkk
Copy link
Owner

Koenkk commented Jan 17, 2025

This has been done on purpose, otherwise Z2M crashes with Error: write after end when something is logged after the logger is ended (this happens when zigbee-herdsman stop unexpectedly)

@manuelkue
Copy link
Author

manuelkue commented Jan 17, 2025

Yes, I had guessed that this error appeared because the logger was previously closed but the fileTransport was not finished yet. So during or at the end of the fileTransport some log would be written, but the logger has been closed already.

My PR solves this issue by moving the this.logger.end() after the finished fileTransport / after its await.
My thought was that the error appeared before #25737, because the ending happened at the start and not at the end of public async end() when the Promise is finally resolved :)

So if you think that the logger should be closed indeed at some time I'd think this fix would do it.
If the logger doesn't have to be ended at all it's probably fine to just let it be as it is and close this PR.

@Koenkk
Copy link
Owner

Koenkk commented Jan 19, 2025

Can you check if this works now?

async exit(code: number, restart = false): Promise<void> {
    console.log('Call logger.end()');
    await logger.end();
    console.log('Before log after end');
    logger.info('LOG AFTER END');
    console.log('After log after end');
    return await this.exitCallback(code, restart);
}

(from #25737)

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

Successfully merging this pull request may close these issues.

2 participants