In Winston logger for node js, is it possible to log the shut down of a node application? For example, if a node app is run in a docker, and the docker container is killed, is it possible to log that with winston? Or do I need to log it through docker?
相关问题
- Docker task in Azure devops won't accept "$(pw
- Unable to run mariadb when mount volume
- I want to trace logs using a Macro multi parameter
- Unspecified error (0x80004005) while running a Doc
- Error message 'No handlers could be found for
You can capture signal events in node.js and run any code on that signal, in your case the logging.
SIGTERM - a graceful shutdown in nodejs
A
docker stop
will send aSIGTERM
signal, and that's the standard 'close all your files and connections and stop the program' signal that is sent to a *nix process. You probably want to handle aSIGINT
in the same way too (a ctrl-c sends this).SIGKILL - not so graceful kill
A
docker kill
or a timeout ondocker stop
will send aSIGKILL
. You can't capture aSIGKILL
from node.js as this is the kernels "kill it and don't ask questions" last resort to get rid of a process. To capture some logs for a kill you would need look at dockers logs, or some other external monitoring/logging as kills can come from anywhere (For example akill -9
command or the Out Of Memory manager in the kernel).Combining application and Docker logs
You can combine your docker logs with your application logs by using a docker logging driver that matches your Winston transport if they are both logging to a central location. Syslog, Graylog(gelf) and Fluentd are open source log collectors and can be used from both.