docker日志文件对错误堆栈信息分行组成了一条条的json,有没办法设置将其合并在一条json?


docker日志文件对错误堆栈信息分行组成了一条条的json,有没办法设置将其合并在一条json?
{"log":"ERROR  com.shuyun.motor.configuration.ConfigurationManager: Failed to load properties for application id: blog-service and environment: null. This is ok, if you do not have application level properties.\n","stream":"stdout","time":"2015-08-05T06:24:32.184401674Z"}
{"log":"! java.io.IOException: Cannot locate blog-service.properties as a classpath resource.\n","stream":"stdout","time":"2015-08-05T06:24:32.184419419Z"}
{"log":"! at com.netflix.config.ConfigurationManager.loadCascadedProperties(ConfigurationManager.java:286) ~\n","stream":"stdout","time":"2015-08-05T06:24:32.184425207Z"}
{"log":"! at com.netflix.config.ConfigurationManager.loadCascadedPropertiesFromResources(ConfigurationManager.java:268) ~\n","stream":"stdout","time":"2015-08-05T06:24:32.184429683Z"}
{"log":"! at com.shuyun.motor.configuration.ConfigurationManager.loadProperties(ConfigurationManager.java:28) \n","stream":"stdout","time":"2015-08-05T06:24:32.184434169Z"}
{"log":"! at com.shuyun.motor.configuration.ConfigurationManager.loadProperties(ConfigurationManager.java:19) \n","stream":"stdout","time":"2015-08-05T06:24:32.184438175Z"}
{"log":"! at com.shuyun.motor.configuration.ConfigurationManager.initialize(ConfigurationManager.java:47) \n","stream":"stdout","time":"2015-08-05T06:24:32.184442472Z"}
{"log":"! at com.shuyun.motor.dropwizard.MotorApplication$1.lifeCycleStarting(MotorApplication.java:246) \n","stream":"stdout","time":"2015-08-05T06:24:32.184446553Z"}
{"log":"! at org.eclipse.jetty.util.component.AbstractLifeCycle.setStarting(AbstractLifeCycle.java:188) \n","stream":"stdout","time":"2015-08-05T06:24:32.184450874Z"}
{"log":"! at org.eclipse.jetty.util.component.AbstractLifeCycle.start(AbstractLifeCycle.java:67) \n","stream":"stdout","time":"2015-08-05T06:24:32.184454779Z"}
{"log":"! at io.dropwizard.cli.ServerCommand.run(ServerCommand.java:43) \n","stream":"stdout","time":"2015-08-05T06:24:32.184459156Z"}
{"log":"! at io.dropwizard.cli.EnvironmentCommand.run(EnvironmentCommand.java:43) \n","stream":"stdout","time":"2015-08-05T06:24:32.184463336Z"}
{"log":"! at io.dropwizard.cli.ConfiguredCommand.run(ConfiguredCommand.java:76) \n","stream":"stdout","time":"2015-08-05T06:24:32.18446745Z"}
{"log":"! at io.dropwizard.cli.Cli.run(Cli.java:70) \n","stream":"stdout","time":"2015-08-05T06:24:32.184471447Z"}
{"log":"! at io.dropwizard.Application.run(Application.java:73) \n","stream":"stdout","time":"2015-08-05T06:24:32.184475655Z"}
{"log":"! at com.shuyun.soa.blog.Application.main(Application.java:14) \n","stream":"stdout","time":"2015-08-05T06:24:32.184492821Z"}


实际的错误是
ERROR  com.shuyun.motor.configuration.ConfigurationManager: Failed to load properties for application id: blog-service and environment: null. This is ok, if you do not have application level properties.
! java.io.IOException: Cannot locate blog-service.properties as a classpath resource.
! at com.netflix.config.ConfigurationManager.loadCascadedProperties(ConfigurationManager.java:286) ~
! at com.netflix.config.ConfigurationManager.loadCascadedPropertiesFromResources(ConfigurationManager.java:268) ~
! at com.shuyun.motor.configuration.ConfigurationManager.loadProperties(ConfigurationManager.java:28) 
! at com.shuyun.motor.configuration.ConfigurationManager.loadProperties(ConfigurationManager.java:19) 
! at com.shuyun.motor.configuration.ConfigurationManager.initialize(ConfigurationManager.java:47) 
! at com.shuyun.motor.dropwizard.MotorApplication$1.lifeCycleStarting(MotorApplication.java:246) 
! at org.eclipse.jetty.util.component.AbstractLifeCycle.setStarting(AbstractLifeCycle.java:188) 
! at org.eclipse.jetty.util.component.AbstractLifeCycle.start(AbstractLifeCycle.java:67) 
! at io.dropwizard.cli.ServerCommand.run(ServerCommand.java:43) 
! at io.dropwizard.cli.EnvironmentCommand.run(EnvironmentCommand.java:43) 
! at io.dropwizard.cli.ConfiguredCommand.run(ConfiguredCommand.java:76) 
! at io.dropwizard.cli.Cli.run(Cli.java:70) 
! at io.dropwizard.Application.run(Application.java:73) 


意思是,我将用fluentd来收集docker 日志,发现有些错误堆栈是分行成一条条的json。收集日志后我会 发送到elk去处理,在后续跟踪查错误的时候没办法看到完整的错误堆栈。

有什么好的办法处理吗?
已邀请:

samung8888

赞同来自:


可以采用fluentd的多行收集插件 (https://github.com/tomohisaota ... tiline)

不过我还是想知道,如何在docker做设置来让这样的错误堆栈输出为一行json? 也不知道docker支持否。

徐新坤 - 京东商城-TIG-JDOS团队

赞同来自:


我想可以写个程序把docker的日志转储一下
或者你可以试试docker logs功能。
样例:
<pre>

docker logs 732 &>123.txt

</pre>
然后123.txt就是转储的日志。

samung8888

赞同来自:


> 我想可以写个程序把docker的日志转储一下

@xiaolunsanguo 我还是想知道docker本身是怎么把stdout的日志转换成json文件的。
还有就是为啥将错误堆栈也分行转换成json

徐新坤 - 京东商城-TIG-JDOS团队

赞同来自:


@samung8888 docker将stdout重定向,然后输出为json文件。具体你可以去看docker源码了解细节。错误堆栈应该是输出到了stdout了,也被docker捕获。这个错误堆栈为什么会输出到stdout,这个应该跟你的CMD进程有关。

要回复问题请先登录注册