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

Close logger #73

Closed
gagle opened this issue Feb 14, 2013 · 4 comments
Closed

Close logger #73

gagle opened this issue Feb 14, 2013 · 4 comments

Comments

@gagle
Copy link

gagle commented Feb 14, 2013

To close all the loggers with a callback completion (similar to the commented one):

Logger.prototype.close = function (cb){
    if (this._closed) return cb ();

    var me = this;
    var remaining = this.streams.length;
    if (!remaining) return cb ();

    this.streams.forEach (function (s){
        s.stream.stream.on ("close", function (){
            if (!--remaining && cb) cb ();
        });
        s.stream.stream.end ();
    });

    this._closed = true;
};

EDIT: this code only works when the file type is "rotation-file". If it's the normal file then s.stream.end() and s.stream.on("close") should be used.

Not tested with childs. Sorry for all the posted issues but this module needs to be revisited.

@chakrit
Copy link
Contributor

chakrit commented Aug 20, 2013

I can't get this to work with a logger with 2 streams (process.stdout and rotating-file).

Is there any reliable way to close or unref all bunyan streams? Need this to properly cleanup tests and make the test runner exit :(

@chakrit
Copy link
Contributor

chakrit commented Aug 20, 2013

Seems rotating-file stream is the cause, if i just leave it to process.stdout, then my test process exits cleanly.

glenn-murray-bse pushed a commit to ascom-au/node-bunyan that referenced this issue Mar 4, 2014
Will fail if any timers or callbacks remain registered when
instantiating a logger with a rotating file.
@trentm
Copy link
Owner

trentm commented Jun 1, 2014

Should be fixed by the above PR. This will be in bunyan 0.23.1.

@trentm trentm closed this as completed Jun 1, 2014
@trentm
Copy link
Owner

trentm commented Jun 1, 2014

Hrm, the unref addition in the PR only fixes this for node 0.10. Node 0.8.x doesn't have unref on setTimeout results.

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

3 participants