winston postgresql 自定义 sql/ tableName 不工作

winston postgresql custom sql/ tableName not working

const logger = new (winston.Logger)({
  transports : [
    new winston.transports.PostgreSQL({
      connString :   'xxxxxxxxxxx',
      schema : 'public',
      //tableName : 'logEntry',
      customSql:'INSERT INTO public."logEntry"(logLevel, msg, meta) VALUES (, , );',
    })
  ];
});

数据未插入 table,我在控制台中收到警告:

Unhandled promise rejections are deprecated. In the future, promise rejections that are not handled will terminate the Node.js process with a non-zero exit code.

谁能告诉我这段代码有什么问题?

您需要定义一个错误处理程序来克服此错误消息,

logger.transports.PostgreSQL.on('error', err => 
    console.log('Error while inserting data')
); 

希望对您有所帮助!

我使用启用了时间戳的 sequelize 创建了 table,这里手动插入数据意味着它不会添加 createdAt 列,这会导致问题。 更换 customSql:'INSERT INTO public."logEntry"(logLevel, msg, meta) VALUES (, , );', 和 customSql: 'INSERT INTO public."logEntry"("logLevel", msg, meta,"createdAt") VALUES (, , ,CURRENT_TIMESTAMP);', 解决了这个问题。 谢谢