Skip to content

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

2 participants