35 lines
836 B
TypeScript
35 lines
836 B
TypeScript
import pino from 'pino';
|
|
import path from 'path';
|
|
|
|
const fileTransport = pino.transport({
|
|
target: 'pino/file',
|
|
options: { destination: path.join(process.cwd(), 'app.log') },
|
|
});
|
|
|
|
const consoleTransport = pino.transport({
|
|
target: 'pino-pretty',
|
|
options: {
|
|
colorize: true,
|
|
ignore: 'pid,hostname',
|
|
destination: 1,
|
|
},
|
|
});
|
|
|
|
export const logger = pino(
|
|
{
|
|
level: process.env.PINO_LOG_LEVEL || 'info',
|
|
formatters: {
|
|
level: (label) => {
|
|
return { level: label.toUpperCase() };
|
|
},
|
|
},
|
|
timestamp: pino.stdTimeFunctions.isoTime,
|
|
},
|
|
pino.multistream([
|
|
{ stream: fileTransport, level: 'info' },
|
|
{ stream: consoleTransport, level: 'info' },
|
|
])
|
|
);
|
|
|
|
export default logger;
|