I have successfully implemented logging to a log file using Pino. However, I am wondering if there is a way to also log to the console in order to manage the frequency of 'console.log()' calls.
- Node Version : 21.6.1
- Typescript Version : 5.3.3
- Pino Version : 8.18.0
- Pino Pretty Version : 10.3.1
import pino from 'pino';
import { getEnvConfig } from "config/env";
const envConfig = getEnvConfig();
const logdir: string = envConfig.log_dir;
const logfile: string = `${logdir}/appName-${new Date(Date.now()).toISOString().split('T')[0]}.log`;
export const logger = pino({
level: envConfig.log_level ?? "info",
formatters: {
bindings: (bindings) => {
return { pid: bindings.pid, host: bindings.hostname, node_version: process.version };
},
level: (label: string) => {
return { level: label.toUpperCase() };
},
},
timestamp: pino.stdTimeFunctions.isoTime,
transport: ({ target: 'pino/file', options: { destination: logdir, mkdir: true } }),
});