dbhowell / pino-cloudwatch

AWS CloudWatch Logs transport for pino
MIT License
38 stars 13 forks source link

[q] Force flush. #20

Open SkeLLLa opened 5 years ago

SkeLLLa commented 5 years ago

Hi, First of all thanks for such pino module.

Does it support force flush method? E.g. in order to be sure that all logs have been delivered in case of process exit or graceful shutdown. Or does it support pino's .flushSync() or .final()?

dbhowell commented 5 years ago

Correct me if I'm wrong please, but the way I understand the transport should be used as a separate process, so pino's .flushSync() or .final() does not affect the transport. It just ensures that the last logs get out to the transport prior to exit.

So then your first question is a good one. The pino-cloudwatch stream should flush on graceful shutdown or process exit. But I don't have any tests around that at the moment so I can't guarantee it.

SkeLLLa commented 5 years ago

I don't know exactly, just thought that pino might send some special keyword that could tell transport that parent process is about to finish and it's time to send data if it's buffered in transport.

Also cloudwatch transport may be used in lambdas, where there is no possibility to run transport like outside the main app. So it's needed to be used inside app, like in example of WritableStream https://github.com/dbhowell/pino-cloudwatch#writable-stream.

So I think to make sure that this transport will not eat last logs from app, it should provide some .flush (which could be called when using this transport inside main application) method and listen to exit signals as well and call that method when it receives them.