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

quote value in ConsoleRender like LogfmtRenderer for special chars #647

Closed
trim21 opened this issue Sep 13, 2024 · 5 comments
Closed

quote value in ConsoleRender like LogfmtRenderer for special chars #647

trim21 opened this issue Sep 13, 2024 · 5 comments

Comments

@trim21
Copy link
Contributor

trim21 commented Sep 13, 2024

logger.info("hello", a="1 b=2") will be logged as hello1 a=1 b=2 and may cause some problem, maybe we should quote value when it contain any space

for example:

class _ConsoleRender(structlog.dev.ConsoleRenderer):

    def _repr(self, val: Any) -> str:
        v = str(val)
        if " " in v or '\n' in v:
            return repr(v)

        return v

or just return repr(val)

@trim21 trim21 changed the title quote value in ConsoleRender quote value in ConsoleRender like LogfmtRenderer for special chars Sep 13, 2024
@hynek
Copy link
Owner

hynek commented Sep 14, 2024

Would you mind opening a PR?

@trim21
Copy link
Contributor Author

trim21 commented Sep 14, 2024

Would you mind opening a PR?

I can open a PR, but I'm not sure which solution you prefer. simple repr or only quote str with spaces?

@trim21
Copy link
Contributor Author

trim21 commented Sep 14, 2024

I prefer simple repr(val) for all values.

@trim21
Copy link
Contributor Author

trim21 commented Sep 17, 2024

OK, did't notice there is already repr_native_str option exists, I'll send a PR to quote str when it contains some chars.

@hynek
Copy link
Owner

hynek commented Sep 18, 2024

fixed by #649

@hynek hynek closed this as completed Sep 18, 2024
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

No branches or pull requests

2 participants