【问题标题】:Preserve colors of heroku logs output when piping to other command (e.g. grep)管道传输到其他命令时保留 heroku 日志输出的颜色(例如 grep)
【发布时间】:2019-01-24 09:35:53
【问题描述】:

我正在使用 grep 来删除产生的大量日志噪音,例如由 NewRelic 提供。我使用以下命令这样做:

heroku logs --force-colors -t -a myApp -s app | grep --color=never web.1

不幸的是,日志的有用着色在某处丢失了,输出没有着色。

--force-colors 标志应该强制heroku logs 命令输出颜色,即使在其他地方输出时也是如此。 --color=never 标志应该强制 grep 不使用自己的配色方案。

我已经尝试了所有可能的组合与这两个颜色标志的缺失或存在,但无济于事。有人对如何解决这个问题有建议吗?

【问题讨论】:

    标签: colors console pipe


    【解决方案1】:

    我找到了解决方案here:

    script -q /dev/null heroku logs --force-colors -t -a myApp -s app | grep --color=never web.1
    

    颜色标志甚至没有必要,所以这也可以:

    script -q /dev/null heroku logs -t -a myApp -s app | grep web.1
    

    【讨论】:

    • 看起来用这个的人不多,但是对我们很有帮助。谢谢!
    • 我必须先使用script --flush --quiet --return /tmp/heroku-logs.txt --command "heroku logs -a app -t" > /dev/null 将其通过管道传输到具有保留颜色的文件:tail -f /tmp/heroku-logs.txt
    猜你喜欢
    • 2023-01-11
    • 2017-01-07
    • 2011-01-20
    • 2021-10-24
    • 2019-08-17
    • 1970-01-01
    • 2020-10-08
    • 2020-03-20
    • 2015-11-05
    相关资源
    最近更新 更多