Documentation
¶
Index ¶
- Variables
- func Configure(cfg *Config)
- func ConfigureLogger(logger *logrus.Logger, cfg *Config)
- func CtxWithFields(ctx context.Context, fields logrus.Fields) (context.Context, *logrus.Entry)
- func EscapeInput(input string) string
- func FormatTypeNames() []string
- func FromCtx(ctx context.Context) *logrus.Entry
- func Log() *logrus.Logger
- func NewCtx(ctx context.Context, logger *logrus.Entry) (context.Context, *logrus.Entry)
- func PrefixedLog(prefix string) *logrus.Entry
- func SetPrefix(logger *logrus.Entry, prefix string) *logrus.Entry
- func Silence()
- func WithIndent(log *logrus.Entry, prefix string, callback func(*logrus.Entry))
- func WithPrefix(logger *logrus.Entry, prefix string) *logrus.Entry
- func WrapCtx(ctx context.Context, wrap func(*logrus.Entry) *logrus.Entry) (context.Context, *logrus.Entry)
- type Config
- type FormatType
- func (x *FormatType) AppendText(b []byte) ([]byte, error)
- func (FormatType) EnumDescriptions() map[string]string
- func (FormatType) EnumValues() []string
- func (x FormatType) IsValid() bool
- func (x FormatType) MarshalText() ([]byte, error)
- func (x FormatType) String() string
- func (x *FormatType) UnmarshalText(text []byte) error
- type MockLoggerHook
Constants ¶
This section is empty.
Variables ¶
var ErrInvalidFormatType = fmt.Errorf("not a valid FormatType, try [%s]", strings.Join(_FormatTypeNames, ", "))
Functions ¶
func ConfigureLogger ¶
Configure applies configuration to the given logger.
func CtxWithFields ¶
func FormatTypeNames ¶
func FormatTypeNames() []string
FormatTypeNames returns a list of possible string values of FormatType.
func PrefixedLog ¶
PrefixedLog return the global logger with prefix
func SetPrefix ¶ added in v0.33.0
SetPrefix sets prefix as the logger's prefix, replacing any prefix it already carries. Use this to give each resolver its own prefix without accumulating the prefixes of resolvers earlier in the chain. Contrast with WithPrefix, which appends to build a dotted chain (a.b.c).
func WithPrefix ¶
WithPrefix adds the given prefix to the logger.
func WrapCtx ¶
func WrapCtx(ctx context.Context, wrap func(*logrus.Entry) *logrus.Entry) (context.Context, *logrus.Entry)
WrapCtx derives a new context logger by applying `wrap` to the context-stored entry.
`wrap` MUST return a new entry (e.g. via WithField/WithFields) and MUST NOT mutate the entry it is given in place: the base entry is passed without copying (the wrapped result is a fresh entry and NewCtx re-stamps its Context), so an in-place mutation would corrupt the shared context-stored logger.
Types ¶
type Config ¶
type Config struct {
Level logrus.Level `default:"info" yaml:"level"`
Format FormatType `default:"text" yaml:"format"`
Privacy bool `default:"false" yaml:"privacy"`
Timestamp bool `default:"true" yaml:"timestamp"`
}
Config defines all logging configurations
func DefaultConfig ¶
func DefaultConfig() *Config
DefaultConfig returns a new Config initialized with default values.
type FormatType ¶
type FormatType int
FormatType format for logging ENUM( text // Human-readable text. json // Structured JSON. )
const ( // FormatTypeText is a FormatType of type Text. // Human-readable text. FormatTypeText FormatType = iota // FormatTypeJson is a FormatType of type Json. // Structured JSON. FormatTypeJson )
func ParseFormatType ¶
func ParseFormatType(name string) (FormatType, error)
ParseFormatType attempts to convert a string to a FormatType.
func (*FormatType) AppendText ¶ added in v0.28.0
func (x *FormatType) AppendText(b []byte) ([]byte, error)
AppendText appends the textual representation of itself to the end of b (allocating a larger slice if necessary) and returns the updated slice.
Implementations must not retain b, nor mutate any bytes within b[:len(b)].
func (FormatType) EnumDescriptions ¶ added in v0.31.0
func (FormatType) EnumDescriptions() map[string]string
EnumDescriptions returns each enum value's description, taken from the `// comment` in the ENUM(...) declaration. Generated; do not edit.
func (FormatType) EnumValues ¶ added in v0.31.0
func (FormatType) EnumValues() []string
EnumValues returns the enum's accepted string values, used to build the JSON schema enum constraint. Generated; do not edit.
func (FormatType) IsValid ¶
func (x FormatType) IsValid() bool
IsValid provides a quick way to determine if the typed value is part of the allowed enumerated values
func (FormatType) MarshalText ¶
func (x FormatType) MarshalText() ([]byte, error)
MarshalText implements the text marshaller method.
func (FormatType) String ¶
func (x FormatType) String() string
String implements the Stringer interface.
func (*FormatType) UnmarshalText ¶
func (x *FormatType) UnmarshalText(text []byte) error
UnmarshalText implements the text unmarshaller method.
type MockLoggerHook ¶
type MockLoggerHook struct {
mock.Mock
Messages []string
// contains filtered or unexported fields
}
func NewMockEntry ¶
func NewMockEntry() (*logrus.Entry, *MockLoggerHook)
func (*MockLoggerHook) Fire ¶
func (h *MockLoggerHook) Fire(entry *logrus.Entry) error
Fire implements `logrus.Hook`.
func (*MockLoggerHook) Levels ¶
func (h *MockLoggerHook) Levels() []logrus.Level
Levels implements `logrus.Hook`.
func (*MockLoggerHook) Reset ¶ added in v0.28.0
func (h *MockLoggerHook) Reset()
Reset clears the Messages slice, removing all logged messages. It is safe to call concurrently with other methods on MockLoggerHook, as all access to Messages is protected by a mutex.