Mayil-AI-Sandbox / loguru-Jan2023

MIT License
0 stars 0 forks source link

Log output is not coloured in GitHub Actions (hashtag604) #107

Closed vikramsubramanian closed 2 months ago

vikramsubramanian commented 2 months ago

I have found that log output is coloured when running locally but not when running through GitHub Actions. Is there something I need to do to get colour in GitHub Actions?

I noticed in a comment here: that "humanfriendly.terminal.terminal_supports_colors actually returns False on the github runner (ubuntu-latest)". Could that be the problem?

GitHub Actions does support colour eg. from another logger:

![screenshot-github com-2022 02 24-17_15_46](

vikramsubramanian commented 2 months ago

By default, Loguru tries to automatically detect whether or not the terminal supports colors. Maybe this is a false-negative case.

You can force colored output by adding you sink with colorize=True. Does it work better?

vikramsubramanian commented 2 months ago

Thank you, that worked eg. see [this](

You could fix the false-negative case by detecting the environment variable: GITHUB_ACTIONS Always set to true when GitHub Actions is running the workflow. You can use this variable to differentiate when tests are being run locally or by GitHub Actions. (from [here](

vikramsubramanian commented 2 months ago

Great, I will do that, thanks. :+1:

Why are some logs not colored in the Github Actions output you shared, though? Is it due to InterceptHandler or something?

vikramsubramanian commented 2 months ago

That script is using the standard logger and then imports another library of mine where the InterceptHandler is set up so I guess it is because of that.

vikramsubramanian commented 2 months ago

I guess it would go here:

        if any(x in os.environ for x in ("PYCHARM_HOSTED", "GITHUB_ACTIONS")):
            return True
vikramsubramanian commented 2 months ago

Fixed on master branch. :+1: