Skip to content

Add CLI flag to force coloured log output #3527

@Sajjon

Description

@Sajjon

Description

I'm setting up Lighthouse to start as a background service on macOS using LaunchAgents. The LaunchAgent is a background running service which starts lighthouse by running a bash script I've written, let's call it start_lighthouse_bn.sh. Due to how LaunchAgents work on macOS I need to source my ENV variables first, which my script depends on, allowing me for neat start lighthouse command.

I want to tail -f my Lighthouse log in my terminal (iTerm3) with colors! But I have not managed to get this working. I use the same setup with geth (starting geth in a start_geth.sh script I've written, see below.), and it works for geth - works meaning the log contains the ANSI color codes explicitly written out, which means that when I tail -f my geth.log I see colors!

My start_lighthouse_bn.sh script looks something like this, and this fails to keep ANSI colors intact, as in the $LIGHTHOUSE_BN_LOG log file are stripped of ANSI color codes => no color with tail

#!/bin/zsh
source /Users/sajjon/Desktop/Services/Scripts/set_env.sh
source "lighthouse --network mainnet beacon_node --logfile $LIGHTHOUSE_BN_LOG"

I've also tried this, which gives same (bad) result, i.e. no colors.

#!/bin/zsh
source /Users/sajjon/Desktop/Services/Scripts/set_env.sh
cmd="lighthouse --network mainnet beacon_node"
script -Fq $LIGHTHOUSE_BN_LOG /bin/zsh -c "$cmd"

However, the analogous script I use for starting geth works and results in $GETH_LOG contain ANSI color codes => colors with tail.

#!/bin/zsh
source /Users/sajjon/Desktop/Services/Scripts/set_env.sh
cmd="geth"
script -Fq $GETH_LOG /bin/zsh -c "$cmd"

Ofc Lighthouse is written in Rust and Geth in Go, so not strange that they two different underlying loggers work differently, but I was hoping that I'm just doing something wronge - OR COMPLETELY OVERENGINEERING THINGS 😛 Do you have any quick fix for me?

Or is a code change in how Lighthouse loggers work needed?

An important note is that when I ~/.lighthouse/mainnet/beacon/logs/beacon.log I get no colors either, and when I open them, they lack ASNI color codes. And when I open the geth log I produce with script -Fq ... above, it looks like this:

Screenshot 2022-08-30 at 11 51 56

Another important note - which is obvious but I'm stating it anyway - when I start lighthouse directly in my terminal I get colors! It is just when the log is written to logfile that I do not. So it should be possible to get the ANSI color codes written to the log file too right?

Version

3.0.0

Present Behaviour

Unable to output logs with ANSI color codes intact to a log file.

Expected Behaviour

I expect log files to not be stripped of coloring, which DRASTICALLY increases readability of them! I'm very color...centric, seeing green makes me happy, and I instantly react to the red in logs, or yellow, so it is very important for me to be able to see this in log files.

Steps to resolve

Dunno, minor change in underlying logger? Or in config to logger? On these lines the format is configured, maybe that can be changed? Which might require a new possible value to the log-format arg

Metadata

Metadata

Assignees

No one assigned

    Labels

    backlogPR is not currently prioritizedenhancementNew feature or requestgood first issueGood for newcomers

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions