I am using this library in python using this library https://coloredlogs.readthedocs.io/en/latest/index.html
import coloredlogs, logging
logger = logging.getLogger(__name__)
coloredlogs.install(level='DEBUG', logger=logger)
logger.debug("test")
The above code works as expected on my local and test
is printed out in green.
However, when I run this on a github runner like this
jobs:
deploy:
runs-on: ubuntu-latest
steps:
- name: Create workflow
run: |
python scripts/my-logging-file.py
The generated output on the runner doesn't have any color. Is there any specific env. variable that needs to set or any other change?
Downgrading to
coloredlogs==12.0
works around the issue described below as per kosta's comment.coloredlogs
uses auto detection by default, which, on linux, only enables colored output iff the output is a TTY. According to the documentation it should work to passisatty = True
via**kw
tocoloredlogs.install
to force colored output.But documentation and code are inconsistent, it looks like the code has a bug and forcing colored output doesn't work. See https://github.com/xolox/python-coloredlogs/issues/84.
https://coloredlogs.readthedocs.io/en/latest/api.html?highlight=isatty#coloredlogs.install
terminal_supports_colors
is fromhumanfriendly
and returns true iff the passed stream is a TTY. In a GitHub Actions runner the output is redirected.https://humanfriendly.readthedocs.io/en/latest/api.html#humanfriendly.terminal.terminal_supports_colors
Source code
https://github.com/xolox/python-humanfriendly/blob/05d02d4f6ef317edf97aca679411ec6514685243/humanfriendly/terminal/init.py#L702
https://github.com/xolox/python-humanfriendly/blob/05d02d4f6ef317edf97aca679411ec6514685243/humanfriendly/terminal/init.py#L402