Giter Site home page Giter Site logo

Comments (5)

JoHuang avatar JoHuang commented on June 15, 2024 1

@JaniAnttonen I added close method for manually send the remaining log data after receiving signals.
Now you can call logger.close() or logger.end() to trigger LokiTransport's close method.

const gracefullyShutdown = () => {
    Log.info(`SIGTERM / SIGINT signal received.`);
    Log.info('Closing http server.');
    server.close(() => {
        Log.info('The final log.');
        Log.close();
        // wait for few secs to let transport send data to remote server
        setTimeout(()=> {
            process.exist(0);
        }, 5000);
    });
};

from winston-loki.

JaniAnttonen avatar JaniAnttonen commented on June 15, 2024

Thanks again for your contribution! I might've done a whoopsie (albeit not direct) with this. As of my latest knowledge, this library may now shut down gracefully, but only by itself. This means that it only waits for its own internal state (any unsent batches or unfinished requests) to finish. I don't have a fast answer for this but to make a patch to disable graceful shutdown with a configuration flag.

from winston-loki.

JaniAnttonen avatar JaniAnttonen commented on June 15, 2024

And you're right, there's a dependency that is used to handle the graceful shutdown. It's called async-exit-hook

from winston-loki.

JaniAnttonen avatar JaniAnttonen commented on June 15, 2024

Then again, it only does this:

exitHook(callback => {
      this.sendBatchToLoki()
        .then(() => callback())
        .catch(() => callback())
    })

That shouldn't trigger exit by itself on first glance, since the promised behavior is "Run some code when the process exits" but there's a part in async-exit-hook that does something with process.exit that might be the culprit:

function doExit() {
	if (doExitDone) {
		return;
	}
	doExitDone = true;

	if (exit === true) {
		// All handlers should be called even if the exit-hook handler was registered first
		process.nextTick(process.exit.bind(null, code));
	}
}

from winston-loki.

JaniAnttonen avatar JaniAnttonen commented on June 15, 2024

@JoHuang, I published a new version, 5.1.1 on npm that has a hotfix described here: https://github.com/JaniAnttonen/winston-loki/releases/tag/v5.1.1

from winston-loki.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.