-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Right now developer can use fluent-interface API to log message with fields, for example: ```go log.With("key1","value"). With("key2","value"). Info(ctx, "message") ``` For some such design is not intuitive. They prefer to pass fields directly as an Info method parameter. Preferably a map. For example: ```go log.InfoFields(ctx, "message", logger.Fields{ "key1": "value", "key2": "value", }) ``` Also, the performance of fluent-interface design is not very high. Each With method call creates a new instance of logger with additional field which costs 1 allocation (for normal logger) and 2 allocations (for global one). Most of the time, such logger will be discarded soon (in the very same method), so allocation could be avoided. The proposed new logger methods can simplify the use of logger and improve the performance. Here are the changes: * new logger.Fields type which is a just a map[string]interface{} * both loggers (logger.Logger and logger.Global) have new methods for directly passing fields: * DebugFields(ctx context.Context, msg string, fields Fields) * InfoFields(ctx context.Context, msg string, fields Fields) * WarnFields(ctx context.Context, msg string, fields Fields) * ErrorFields(ctx context.Context, msg string, fields Fields) * both loggers have new methods for passing an error too: * ErrorCause(ctx context.Context, msg string, cause error) * ErrorCauseFields(ctx context.Context, msg string, cause error, fields Fields) * both loggers have new methods for creating a child logger with multiple fields at once: * WithFields(Fields) * logger.Entry has a new method WithFields(Fields) **All the changes are backwards compatible.**
- Loading branch information
Showing
19 changed files
with
675 additions
and
155 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.