Documentation
¶
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Logger ¶
type Logger struct {
// contains filtered or unexported fields
}
Logger is like strings.Builder, but with maximum length. If the caller tries to add data beyond the capacity, they will be dropped, and Logger.String() will append "(truncated)" at the end.
TODO: Consider renaming to Builder or Buffer since this type's behavior is analogous to those.
func NewLogger ¶
func NewLogger(maxLen int, opts ...LoggerOption) *Logger
NewLogger creates a new Logger object with the given capacity.
type LoggerOption ¶ added in v0.0.11
type LoggerOption func(*Logger)
LoggerOption is passed to NewLogger to configure a Logger.
func LogIfTruncatingMaxMultiple ¶ added in v0.0.11
func LogIfTruncatingMaxMultiple(m float64) LoggerOption
LogIfTruncatingMaxMultiple controls informative logging about how much data passed to Write has been truncated.
If zero, this logging is disabled. Otherwise, if the sum of len(data) passed to prior Write calls is greater than LogIfTruncatingMaxMultiple * maxLen (passed to NewLogger), a log message is written in the next call to String(). After logging, LogIfTruncatingMaxMultiple is set to zero to avoid repeating the same message.
This can be a useful diagnostic for both CPU and memory usage if a huge amount of data is written and only a tiny fraction is used. For example, if a caller writes to the log with fmt.Fprint(logger, ...) they may not realize that fmt.Fprint* actually buffers the *entire* formatted string in memory first, then writes it to logger. TODO: Consider serving the fmt use case better for e.g. bigslice.
Note that the log message is written to log.Error, not the Logger itself (it's not part of String's return).