Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

unable to determine transport target for "pino-pretty"

I am trying to use pino library but I am getting error

My code

I created a logger.js file and imported pino from node_module and added transport of pino-pretty.

logger.js

   import pino from "pino";
    const logger = pino({
      transport: {
        target: "pino-pretty",
        options: {
          colorize: true,
        },
      },
    });
    export default logger;

I created a database file and imported pino from logger file and used info function to display my error.

database.js

import mongoose from "mongoose";
import logger from "./logger";
const DB_CONNECTION_STRING =
  process.env.DB_CONNECTION_STRING ||
  "mongodb://localhost:27017/*******";
try {
    await mongoose.connect(DB_CONNECTION_STRING);
    logger.info("Connect to database");
  } catch (e) {
    logger.error(e, "Failed to connect to database. Goodbye");
    process.exit(1);
  }

enter image description here

like image 277
etranz Avatar asked Nov 29 '25 12:11

etranz


1 Answers

You can use it as a stream if it doesn't work with the transport option:

import pino from "pino";
import pretty from "pino-pretty";

const stream = pretty({
  levelFirst: true,
  colorize: true,
  ignore: "time,hostname,pid",
});

const logger = pino(
  {
    name: "MyLogger",
    level: process.env.NODE_ENV === "development" ? "debug" : "info",
  },
  stream
);

export default logger;

More details in the docs: https://github.com/pinojs/pino-pretty#usage-as-a-stream

like image 107
Durden Avatar answered Dec 01 '25 05:12

Durden