Skip to content

Do not colorize log outputs when sent to something not a terminal #299

@abailly

Description

@abailly

When one redirects logs to a file like

amaru daemon .... 2> amaru.log

the content of the file contains ANSI escape characters for colorisation:

ESC[2m2025-06-24T07:11:53.161122ZESC[0m ESC[32m INFOESC[0m ESC[2mamaru::stages::consensus::forward_chainESC[0mESC[2m:ESC[0m forwarded ESC[3mheaderESC[0mESC[2m=ESC[0m284c0f05165db1d4c44fa8390e5366ab9d0ccf53f7e6e4c10d81bdf541d17906 ESC[3mparentESC[0mESC[2m=ESC[0mSome(Hash<32>("379d848be3fa4fc8d6a4293d0554bc1396abd4bbf0d39739488f3de316c28a4e"))
ESC[2m2025-06-24T07:11:53.161660ZESC[0m ESC[32m INFOESC[0m ESC[2mamaru::stages::consensus::forward_chainESC[0mESC[2m:ESC[0m forwarded ESC[3mheaderESC[0mESC[2m=ESC[0m6e0193f2ddb5ac1c22d09ad34a6d57ef09d42368f8cb8b65eb9799039a5ac4a2 ESC[3mparentESC[0mESC[2m=ESC[0mSome(Hash<32>("284c0f05165db1d4c44fa8390e5366ab9d0ccf53f7e6e4c10d81bdf541d17906"))
ESC[2m2025-06-24T07:11:53.162009ZESC[0m ESC[32m INFOESC[0m ESC[2mamaru::stages::consensus::forward_chainESC[0mESC[2m:ESC[0m forwarded ESC[3mheaderESC[0mESC[2m=ESC[0m300dc720dedc0e8b3e6b21d1637c04dc90aa0f57f42fedc4a35c98b5c817b8df ESC[3mparentESC[0mESC[2m=ESC[0mSome(Hash<32>("6e0193f2ddb5ac1c22d09ad34a6d57ef09d42368f8cb8b65eb9799039a5ac4a2"))
ESC[2m2025-06-24T07:11:53.162550ZESC[0m ESC[31mERRORESC[0m ESC[2mamaru::stages::ledgerESC[0mESC[2m:ESC[0m error receiving message ESC[3merrorESC[0mESC[2m=ESC[0merror receiving work unit through input port
ESC[2m2025-06-24T07:11:53.162560ZESC[0m ESC[32m INFOESC[0m ESC[2mamaru::stages::consensus::forward_chainESC[0mESC[2m:ESC[0m forwarded ESC[3mheaderESC[0mESC[2m=ESC[0me35e85c294b5004a969859b8116ce1050c2f440eca178aa4b4941de075999934 ESC[3mparentESC[0mESC[2m=ESC[0mSome(Hash<32>("300dc720dedc0e8b3e6b21d1637c04dc90aa0f57f42fedc4a35c98b5c817b8df"))
ESC[2m2025-06-24T07:11:53.162579ZESC[0m ESC[31mERRORESC[0m ESC[2mgasket::runtimeESC[0mESC[2m:ESC[0m error receiving message ESC[3mretryESC[0mESC[2m=ESC[0mRetry(None)
ESC[2m2025-06-24T07:11:53.162647ZESC[0m ESC[31mERRORESC[0m ESC[2mgasket::frameworkESC[0mESC[2m:ESC[0m ESC[3mxESC[0mESC[2m=ESC[0merror receiving work unit through input port
ESC[2m2025-06-24T07:11:53.162657ZESC[0m ESC[31mERRORESC[0m ESC[2mgasket::runtimeESC[0mESC[2m:ESC[0m stage should stop ESC[3mretryESC[0mESC[2m=ESC[0mRetry(None)
ESC[2m2025-06-24T07:15:44.207783ZESC[0m ESC[33m WARNESC[0m ESC[2mamaru::exitESC[0mESC[2m:ESC[0m SIGINT detected

The logging system should detect the output is not a terminal and remove colours in this case.

Metadata

Metadata

Assignees

Type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions