在heroku中记录多行消息 [英] Logging multiline messages in heroku

查看:56
本文介绍了在heroku中记录多行消息的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用NodeJS开发应用程序,并将其部署在Heroku中.

I'm developing an application using NodeJS and deployed in Heroku.

我需要记录多行消息(例如,堆栈跟踪和其他多行信息),但希望将它们分别保留为一条日志消息.

I need to log multi-line messages (eg. stacktraces and other multiline information) but would like to retain them as one log message each.

问题是当使用 console.log (或使用 console.log / stdout 的任何框架)时,它带有多行消息被Heroku解释为多条消息(原始消息中的每一行一条消息).

The problem is that when using console.log (or any framework that uses console.log/stdout) with a multiline message it's interpreted like multiple messages by Heroku (one message per each line in the original message).

我认为问题在于Heroku从进程的 stdout 中读取消息,并且无法区分换行符( LF / CR )一条消息或该行输入多条消息,从而每行创建一条消息.

I think the problem lies in that Heroku reads the messages from the process' stdout and cannot distinguish between the line feeds (LF/CR) in one message or the line feeds in multiple messages and thus creates one message per line.

我尝试将消息直接发送到syslog(使用 ain2 ),而不是发送到stdout和它适用于多行消息,但仅适用于我的本地环境.

I've tried to send the messages directly to syslog (using ain2) instead of to stdout and it works with multiline messages but only on my local environment.

我想在Heroku中使用logplex/syslog做同样的事情吗?但是在使用带有默认参数(本地主机,UDP,端口514)的syslog时无法记录我的消息.

I'd like to do the same thing in Heroku which uses logplex/syslog? but haven't been able to get my messages logged when using syslog with default params (localhost, UDP, port 514).

还有其他方法可以在Heroku中记录多行消息吗?这是平台的不足吗?

Is there any other way to log multiline messages in Heroku that works? Is this a shortfall in the platform?

推荐答案

我什至不确定您使用堆栈跟踪的成功程度如何,因为最终这是基于 syslog 的,并且Heroku可能对单个 syslog 行的长度有限制.但是,不确定,当然也不知道该限制.

I am not even sure how successful you'll be with stack traces, since eventually this is syslog-based, and Heroku might have a limit on the length of a single syslog line. Not sure, though, and certainly wouldn't know about the limit.

您可以做的是将每个 \ n 替换为 \ n>>> (即:以">>>"开头的每个续行),然后在您的日志处理代码中对此进行解析.

What you can do is replace every \n with \n>>> (that is: start every continuation line with ">>>"), and then parse this accordingly in your log-processing code.

这篇关于在heroku中记录多行消息的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆