docker-compose logs 查看实时日志(日志最后的N行、某刻后日志) 实践笔记

2021-12-07 15:24:50 浏览数 (1)

docker-compose logs 查看实时日志(日志最后的N行、某刻后日志) 实践笔记

  • 1.参数说明
  • 2.我以rabbitmq为例
    • 2.1.全屏滚到底部结束
    • 2.2.全屏滚到底部并继续持续输出日志
    • 2.3.全屏滚到底部并继续持续输出日志并显示时间戳
    • 2.4.全屏滚到底部显示最后N行并继续持续输出日志并显示时间戳
  • 3.总结对比一下

1.参数说明

代码语言:javascript复制
View output from containers.

Usage: logs [options] [SERVICE...]

Options:
    --no-color          Produce monochrome output.
    -f, --follow        Follow log output.  实时输出日志,最后一行为当前时间戳的日志
    -t, --timestamps    Show timestamps. 显示时间戳
    --tail="all"        Number of lines to show from the end of the logs for each container.    
    						显示最后多少行日志, 默认是all (如: -tail=10 : 查看最后的 10 行日志。)

2.我以rabbitmq为例

2.1.全屏滚到底部结束

#docker-compose logs 全屏滚到底部结束

代码语言:javascript复制
docker-compose logs

2.2.全屏滚到底部并继续持续输出日志

#docker-compose logs -f 全屏滚到底部并继续持续输出日志

代码语言:javascript复制
docker-compose logs -f

2.3.全屏滚到底部并继续持续输出日志并显示时间戳

2.4.全屏滚到底部显示最后N行并继续持续输出日志并显示时间戳

代码语言:javascript复制
docker-compose logs -f -t --tail=10

3.总结对比一下

docker-compose logs

rabbitmq | 2021-01-08 06:33:09.091 [error] <0.1007.2> Channel error on connection <0.25180.0> rabbitmq | operation basic.ack caused a channel exception precondition_failed: unknown delivery tag

docker-compose logs -f

rabbitmq | 2021-01-08 06:33:09.091 [error] <0.1007.2> Channel error on connection <0.25180.0> rabbitmq | operation basic.ack caused a channel exception precondition_failed: unknown delivery tag

docker-compose logs -f -t

rabbitmq | 2021-01-08T06:33:09.092091217Z 2021-01-08 06:33:09.091 [error] <0.1007.2> Channel rabbitmq | 2021-01-08T06:33:09.092109187Z operation basic.ack caused a channel exception

docker-compose logs -f -t --tail=10

rabbitmq | 2021-01-08T06:33:09.092091217Z 2021-01-08 06:33:09.091 [error] <0.1007.2> Channel rabbitmq | 2021-01-08T06:33:09.092109187Z operation basic.ack caused a channel exception

0 人点赞