node.js - winston postgresql 自定义 sql/tableName 不工作

标签 node.js postgresql winston

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 ($1, $2, $3);',
    })
  ];
});

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

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')
); 

希望这对您有所帮助!

关于node.js - winston postgresql 自定义 sql/tableName 不工作,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46940176/

相关文章:

node.js - 如何使用 Node.js postgres 测试 CRUD 操作

node.js - npm install 未获取软件包的最新次要版本

sql - 从全名获取名字的逻辑和查询

node.js - HPE_INVALID_EOF_STATE 是什么意思

node.js - NodeJS/Forever 归档日志

node.js - 错误 : connect ECONNREFUSED 127. 0.0.1:465 nodemailer

node.js - 如何从 Node 模块导出异步函数

sql - PostgreSQL : getting group count

php - Doctrine 注册自定义 DQL 函数

javascript - 如何使用 Winston 库在 Node.js 中每天将日志分离到单独的文件中