Open nenadfilipovic opened 2 years ago
It's very hard to help you given that we cannot run the code. Could you create an example that is just calling an http endpoint to simulate slack?
Ok. lets try
Transport
import build from 'pino-abstract-transport';
export default async function (options) {
return build(async (source) => {
for await (let obj of source) {
console.log(obj);
}
});
}
Logger
export const logger = pino(
pino.transport({
target: './slackTransport.js',
}),
);
Server
import http from 'http';
import express from "express";
import { logger } from './logger.js';
import gracefulShutdown from 'http-graceful-shutdown'
const app = express();
const server = http.createServer(app);
server.listen(3002, () => {
console.log('start');
})
const preShutdown = async () => {
logger.info(`Stopping server...`);
};
const shutdown = gracefulShutdown(server, {
preShutdown,
forceExit: false,
finally: () => {
logger.info(`Server stopped!`);
},
});
Graceful shutdown package will handle SIGINT, SIGTERM signals. Without transport pino will log after ctrl+c and with transport it will exit silently.
@mcollina any chance to look at this?
Unfortunately not yet, it's in the queue after Fastify v4.
things to verify, in this order:
Thanks, I was banging my head so much with inconsistencies with console.log.
@nenadfilipovic Did you manage to resolve this?
Can I get some guidelines how to handle this situation. I need to report errors to my Slack channel and results are very inconsistent. Startup logs works fine but when I hit ctrl+c I dont get any output when using custom transport even if I just console.log
obj
in code example below. For graceful shutdown I am using https://www.npmjs.com/package/http-graceful-shutdown and transport is simpleWhat I need to do to be able to catch logs before my servers exits? Thanks.