Logging multiline messages in heroku

☆樱花仙子☆ 提交于 2021-02-09 20:41:57

问题


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.

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).

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.

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.

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).

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


回答1:


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.

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.



来源:https://stackoverflow.com/questions/19492312/logging-multiline-messages-in-heroku

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!