Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Color Output on github actions #495

Closed
ecs-jnguyen opened this issue Mar 7, 2023 · 3 comments · Fixed by #503
Closed

Color Output on github actions #495

ecs-jnguyen opened this issue Mar 7, 2023 · 3 comments · Fixed by #503

Comments

@ecs-jnguyen
Copy link

Hello, I am trying to use structlog in a github action job and I noticed that there isn't any color output. Is there a setting that I'm missing to enable colors in github actions?

Here's my github actions job run:

https://github.com/ecs-jnguyen/test-actions-colors/actions/runs/4357219988/jobs/7616263866

Here is the python code that I'm using:

import structlog

if __name__ == "__main__":
    logger = structlog.get_logger()
    logger.info("hello", name="me", age=123)
    logger.warning("bye", name="me", age=123)
    logger.error("ohno", name="me", age=123)
@hynek
Copy link
Owner

hynek commented Mar 9, 2023

structlog checks if the terminal is a tty, which it probably isn't for GHA:

ConsoleRenderer(
colors=_has_colors
and sys.stdout is not None
and hasattr(sys.stdout, "isatty")
and sys.stdout.isatty()
),

You'll have to configure it by hand and explicitly pass colors=True.

@ecs-jnguyen
Copy link
Author

I've seen a lot of talks about the use of the environment variable FORCE_COLOR=1 or FORCE_COLOR=true to get colors in CI tools like github actions. Could we do the same with structlog so that users don't have to configure the default list of processors for this one setting?

References:

@hynek
Copy link
Owner

hynek commented Mar 11, 2023

This is an interesting question and transition period. structlog has exploded for use-cases that I never anticipated. CLI output used to be just a perk for development. I guess we [cs]ould accept the new role and make it nicer out of the box…

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants