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

Avoid unnecessary string copy when no log level is specified #10

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

hnw
Copy link

@hnw hnw commented Nov 8, 2021

I'm using hashicorp/logutils with a library that requires log.Logger. I think it is very useful because we can use it as a library logger. Thank you very much!

However, I noticed a problem when using hashicorp/logutils with the library. If no log level is specified in the library log output, the log level will be considered a huge string and a huge string copy may occur. For example, this can be a problem when logging JSON like {"blocks": [...]}

So I introduced a maximum length of log level string to avoid huge string copy. I think this fix never cause any functional or performance issues with existing use cases.

In addition, this fix makes it easier to treat logs without a log level as log level "". This is a bit tricky, but it's useful if we use hashicorp/logutils to handle both our own logs and library logs.

@hashicorp-cla
Copy link

hashicorp-cla commented Nov 8, 2021

CLA assistant check
All committers have signed the CLA.

@hnw hnw changed the title Avoid unnecessary string copy when no log label is specified Avoid unnecessary string copy when no log level is specified Dec 15, 2021
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 this pull request may close these issues.

2 participants