其實方案三和方案二日志采集套路一樣,但是還是有點差別。
差別就在於日志格式如下:
為了方便對比吧日志貼上來
Nov 16 10:51:58 localhost 939fe968a91d[4721]: 2018-11-16 02:51:58.892 INFO [demo1,fa9d2f274c9d3c59,fa9d2f274c9d3c59,
false] 1 --- [hystrix-test1-1] demo1.demo1.TestRest : 我收到了其他服務調用
Nov 16 10:51:58 localhost 939fe968a91d[4721]: 2018-11-16 02:51:58.892 INFO [demo1,fa9d2f274c9d3c59,fa9d2f274c9d3c59, false] 1 --- [hystrix-test1-1] demo1.demo1.TestRest : 我收到了其他服務調用
Nov 16 10:51:58 localhost 939fe968a91d[4721]: 2018-11-16 02:51:58.892 INFO [demo1,fa9d2f274c9d3c59,fa9d2f274c9d3c59, false] 1 --- [hystrix-test1-1] demo1.demo1.TestRest : 我收到了其他服務調用
Nov 16 10:51:58 localhost 939fe968a91d[4721]: 2018-11-16 02:51:58.892 INFO [demo1,fa9d2f274c9d3c59,fa9d2f274c9d3c59, false] 1 --- [hystrix-test1-1] demo1.demo1.TestRest : 我收到了其他服務調用
Nov 16 10:51:58 localhost 939fe968a91d[4721]: 2018-11-16 02:51:58.892 INFO [demo1,fa9d2f274c9d3c59,fa9d2f274c9d3c59, false] 1 --- [hystrix-test1-1] demo1.demo1.TestRest : 我收到了其他服務調用
Nov 16 10:51:58 localhost 939fe968a91d[4721]: 2018-11-16 02:51:58.892 INFO [demo1,fa9d2f274c9d3c59,fa9d2f274c9d3c59, false] 1 --- [hystrix-test1-1] demo1.demo1.TestRest : 我收到了其他服務調用
Nov 16 10:51:58 localhost 939fe968a91d[4721]: 2018-11-16 02:51:58.892 INFO [demo1,fa9d2f274c9d3c59,fa9d2f274c9d3c59, false] 1 --- [hystrix-test1-1] demo1.demo1.TestRest : 我收到了其他服務調用
Nov 16 10:51:58 localhost 939fe968a91d[4721]: 2018-11-16 02:51:58.892 INFO [demo1,fa9d2f274c9d3c59,fa9d2f274c9d3c59, false] 1 --- [hystrix-test1-1] demo1.demo1.TestRest : 我收到了其他服務調用
Nov 16 10:51:58 localhost 939fe968a91d[4721]: 2018-11-16 02:51:58.892 INFO [demo1,fa9d2f274c9d3c59,fa9d2f274c9d3c59, false] 1 --- [hystrix-test1-1] demo1.demo1.TestRest : 我收到了其他服務調用
Nov 16 10:51:58 localhost 939fe968a91d[4721]: 2018-11-16 02:51:58.892 INFO [demo1,fa9d2f274c9d3c59,fa9d2f274c9d3c59, false] 1 --- [hystrix-test1-1] demo1.demo1.TestRest : 我收到了其他服務調用
Nov 16 10:51:58 localhost 939fe968a91d[4721]: 2018-11-16 02:51:58.892 INFO [demo1,fa9d2f274c9d3c59,fa9d2f274c9d3c59, false] 1 --- [hystrix-test1-1] demo1.demo1.TestRest : 我收到了其他服務調用
Nov 16 10:51:58 localhost 939fe968a91d[4721]: 2018-11-16 02:51:58.892 INFO [demo1,fa9d2f274c9d3c59,fa9d2f274c9d3c59, false] 1 --- [hystrix-test1-1] demo1.demo1.TestRest : 我收到了其他服務調用
Nov 16 10:51:58 localhost 939fe968a91d[4721]: 2018-11-16 02:51:58.892 INFO [demo1,fa9d2f274c9d3c59,fa9d2f274c9d3c59, false] 1 --- [hystrix-test1-1] demo1.demo1.TestRest : 我收到了其他服務調用
Nov 16 10:51:58 localhost 939fe968a91d[4721]: 2018-11-16 02:51:58.892 INFO [demo1,fa9d2f274c9d3c59,fa9d2f274c9d3c59, false] 1 --- [hystrix-test1-1] demo1.demo1.TestRest : 我收到了其他服務調用
Nov 16 10:51:58 localhost 939fe968a91d[4721]: 2018-11-16 02:51:58.892 INFO [demo1,fa9d2f274c9d3c59,fa9d2f274c9d3c59, false] 1 --- [hystrix-test1-1] demo1.demo1.TestRest : 我收到了其他服務調用
------------------上面是使用syslog本地打日志-----下面是使用journald打日志----------------------------------------------------------------
Nov 16 11:20:30 localhost b268cf551812: 2018-11-16 03:20:30.515 INFO [demo1,31c664ed12d6265e,31c664ed12d6265e, false] 1 --- [ystrix-test1-10] demo1.demo1.TestRest : 我收到了其他服務調用
Nov 16 11:20:30 localhost b268cf551812: 2018-11-16 03:20:30.515 INFO [demo1,31c664ed12d6265e,31c664ed12d6265e, false] 1 --- [ystrix-test1-10] demo1.demo1.TestRest : 我收到了其他服務調用
Nov 16 11:20:30 localhost b268cf551812: 2018-11-16 03:20:30.515 INFO [demo1,31c664ed12d6265e,31c664ed12d6265e, false] 1 --- [ystrix-test1-10] demo1.demo1.TestRest : 我收到了其他服務調用
Nov 16 11:20:30 localhost b268cf551812: 2018-11-16 03:20:30.515 INFO [demo1,31c664ed12d6265e,31c664ed12d6265e, false] 1 --- [ystrix-test1-10] demo1.demo1.TestRest : 我收到了其他服務調用
Nov 16 11:20:30 localhost b268cf551812: 2018-11-16 03:20:30.515 INFO [demo1,31c664ed12d6265e,31c664ed12d6265e, false] 1 --- [ystrix-test1-10] demo1.demo1.TestRest : 我收到了其他服務調用
Nov 16 11:20:30 localhost b268cf551812: 2018-11-16 03:20:30.515 INFO [demo1,31c664ed12d6265e,31c664ed12d6265e, false] 1 --- [ystrix-test1-10] demo1.demo1.TestRest : 我收到了其他服務調用
Nov 16 11:20:30 localhost b268cf551812: 2018-11-16 03:20:30.515 INFO [demo1,31c664ed12d6265e,31c664ed12d6265e, false] 1 --- [ystrix-test1-10] demo1.demo1.TestRest : 我收到了其他服務調用
Nov 16 11:20:30 localhost b268cf551812: 2018-11-16 03:20:30.515 INFO [demo1,31c664ed12d6265e,31c664ed12d6265e, false] 1 --- [ystrix-test1-10] demo1.demo1.TestRest : 我收到了其他服務調用
Nov 16 10:51:58 localhost 939fe968a91d[4721]: 2018-11-16 02:51:58.892 INFO [demo1,fa9d2f274c9d3c59,fa9d2f274c9d3c59, false] 1 --- [hystrix-test1-1] demo1.demo1.TestRest : 我收到了其他服務調用
Nov 16 10:51:58 localhost 939fe968a91d[4721]: 2018-11-16 02:51:58.892 INFO [demo1,fa9d2f274c9d3c59,fa9d2f274c9d3c59, false] 1 --- [hystrix-test1-1] demo1.demo1.TestRest : 我收到了其他服務調用
Nov 16 10:51:58 localhost 939fe968a91d[4721]: 2018-11-16 02:51:58.892 INFO [demo1,fa9d2f274c9d3c59,fa9d2f274c9d3c59, false] 1 --- [hystrix-test1-1] demo1.demo1.TestRest : 我收到了其他服務調用
Nov 16 10:51:58 localhost 939fe968a91d[4721]: 2018-11-16 02:51:58.892 INFO [demo1,fa9d2f274c9d3c59,fa9d2f274c9d3c59, false] 1 --- [hystrix-test1-1] demo1.demo1.TestRest : 我收到了其他服務調用
Nov 16 10:51:58 localhost 939fe968a91d[4721]: 2018-11-16 02:51:58.892 INFO [demo1,fa9d2f274c9d3c59,fa9d2f274c9d3c59, false] 1 --- [hystrix-test1-1] demo1.demo1.TestRest : 我收到了其他服務調用
Nov 16 10:51:58 localhost 939fe968a91d[4721]: 2018-11-16 02:51:58.892 INFO [demo1,fa9d2f274c9d3c59,fa9d2f274c9d3c59, false] 1 --- [hystrix-test1-1] demo1.demo1.TestRest : 我收到了其他服務調用
Nov 16 10:51:58 localhost 939fe968a91d[4721]: 2018-11-16 02:51:58.892 INFO [demo1,fa9d2f274c9d3c59,fa9d2f274c9d3c59, false] 1 --- [hystrix-test1-1] demo1.demo1.TestRest : 我收到了其他服務調用
Nov 16 10:51:58 localhost 939fe968a91d[4721]: 2018-11-16 02:51:58.892 INFO [demo1,fa9d2f274c9d3c59,fa9d2f274c9d3c59, false] 1 --- [hystrix-test1-1] demo1.demo1.TestRest : 我收到了其他服務調用
Nov 16 10:51:58 localhost 939fe968a91d[4721]: 2018-11-16 02:51:58.892 INFO [demo1,fa9d2f274c9d3c59,fa9d2f274c9d3c59, false] 1 --- [hystrix-test1-1] demo1.demo1.TestRest : 我收到了其他服務調用
Nov 16 10:51:58 localhost 939fe968a91d[4721]: 2018-11-16 02:51:58.892 INFO [demo1,fa9d2f274c9d3c59,fa9d2f274c9d3c59, false] 1 --- [hystrix-test1-1] demo1.demo1.TestRest : 我收到了其他服務調用
Nov 16 10:51:58 localhost 939fe968a91d[4721]: 2018-11-16 02:51:58.892 INFO [demo1,fa9d2f274c9d3c59,fa9d2f274c9d3c59, false] 1 --- [hystrix-test1-1] demo1.demo1.TestRest : 我收到了其他服務調用
Nov 16 10:51:58 localhost 939fe968a91d[4721]: 2018-11-16 02:51:58.892 INFO [demo1,fa9d2f274c9d3c59,fa9d2f274c9d3c59, false] 1 --- [hystrix-test1-1] demo1.demo1.TestRest : 我收到了其他服務調用
Nov 16 10:51:58 localhost 939fe968a91d[4721]: 2018-11-16 02:51:58.892 INFO [demo1,fa9d2f274c9d3c59,fa9d2f274c9d3c59, false] 1 --- [hystrix-test1-1] demo1.demo1.TestRest : 我收到了其他服務調用
Nov 16 10:51:58 localhost 939fe968a91d[4721]: 2018-11-16 02:51:58.892 INFO [demo1,fa9d2f274c9d3c59,fa9d2f274c9d3c59, false] 1 --- [hystrix-test1-1] demo1.demo1.TestRest : 我收到了其他服務調用
------------------上面是使用syslog本地打日志-----下面是使用journald打日志----------------------------------------------------------------
Nov 16 11:20:30 localhost b268cf551812: 2018-11-16 03:20:30.515 INFO [demo1,31c664ed12d6265e,31c664ed12d6265e, false] 1 --- [ystrix-test1-10] demo1.demo1.TestRest : 我收到了其他服務調用
Nov 16 11:20:30 localhost b268cf551812: 2018-11-16 03:20:30.515 INFO [demo1,31c664ed12d6265e,31c664ed12d6265e, false] 1 --- [ystrix-test1-10] demo1.demo1.TestRest : 我收到了其他服務調用
Nov 16 11:20:30 localhost b268cf551812: 2018-11-16 03:20:30.515 INFO [demo1,31c664ed12d6265e,31c664ed12d6265e, false] 1 --- [ystrix-test1-10] demo1.demo1.TestRest : 我收到了其他服務調用
Nov 16 11:20:30 localhost b268cf551812: 2018-11-16 03:20:30.515 INFO [demo1,31c664ed12d6265e,31c664ed12d6265e, false] 1 --- [ystrix-test1-10] demo1.demo1.TestRest : 我收到了其他服務調用
Nov 16 11:20:30 localhost b268cf551812: 2018-11-16 03:20:30.515 INFO [demo1,31c664ed12d6265e,31c664ed12d6265e, false] 1 --- [ystrix-test1-10] demo1.demo1.TestRest : 我收到了其他服務調用
Nov 16 11:20:30 localhost b268cf551812: 2018-11-16 03:20:30.515 INFO [demo1,31c664ed12d6265e,31c664ed12d6265e, false] 1 --- [ystrix-test1-10] demo1.demo1.TestRest : 我收到了其他服務調用
Nov 16 11:20:30 localhost b268cf551812: 2018-11-16 03:20:30.515 INFO [demo1,31c664ed12d6265e,31c664ed12d6265e, false] 1 --- [ystrix-test1-10] demo1.demo1.TestRest : 我收到了其他服務調用
Nov 16 11:20:30 localhost b268cf551812: 2018-11-16 03:20:30.515 INFO [demo1,31c664ed12d6265e,31c664ed12d6265e, false] 1 --- [ystrix-test1-10] demo1.demo1.TestRest : 我收到了其他服務調用

使用 journald方式與syslog不同的地方在於可以使用命令對日志進行篩選
如我們更新容器日志方式如下:
sudo docker service update --log-driver journald --log-opt tag="{{.Name}}" pbblyrmsof5t

我們打印出來的日志如下
我們可以用如下命令進行篩選打印
sudo journalctl CONTAINER_NAME=mytestdemo.1.7l7qn86kzkjkxnawxslmzin9r -f

問題和方案二是一樣的不多說,可以去找方案二查看。