log

package
v0.1.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Oct 11, 2022 License: Apache-2.0 Imports: 16 Imported by: 1

Documentation

Overview

Copyright 2020 New Relic Corporation. All rights reserved. SPDX-License-Identifier: Apache-2.0 agent domain features

Copyright 2020 New Relic Corporation. All rights reserved. SPDX-License-Identifier: Apache-2.0 package log is our own log package, basically a wrapper for logrus with some improvements like: - lazy evaluation of WithFields funcs - shrinked logrus API (no Fatal, Panic...) - added agent domain API helpers like CustomIntegration/... this file was based on logrus/exported.go

Copyright 2020 New Relic Corporation. All rights reserved. SPDX-License-Identifier: Apache-2.0 package log provides a log wrapper to be used within the agent. It implements a Functional Logger Facade on top of Logrus. It aims at keeping conciseness without losing performance when composite loggers are built (WithError, WithFields...), making the related methods to be invoked lazily, avoiding to consume CPU resources if those are not going to be used (e.g. we won't generate a WithFields(...) logger entry if it is for debugging and the log level is Info.

Copyright 2020 New Relic Corporation. All rights reserved. SPDX-License-Identifier: Apache-2.0

Copyright 2020 New Relic Corporation. All rights reserved. SPDX-License-Identifier: Apache-2.0

Index

Constants

View Source
const DefaultVerboseMin = 5

DefaultVerboseMin default verbose time range in minutes.

Variables

View Source
var ErrFileNotOpened = errors.New("cannot perform operation, file is not opened")

ErrFileNotOpened is returned when an operation cannot be performed because the file is not opened.

Functions

func AddHook

func AddHook(hook logrus.Hook)

AddHook adds a hook to the singleton logger used in the codebase

func Debug

func Debug(args ...interface{})

Debug logs a message at level Debug on the standard logger.

func Debugf

func Debugf(format string, args ...interface{})

Debugf logs a message at level Debug on the standard logger.

func EnableSmartVerboseMode

func EnableSmartVerboseMode(cachedEntryLimit int)

func EnableTemporaryVerbose

func EnableTemporaryVerbose()

EnableTemporaryVerbose enables verbose logging for a given amount of minutes.

func Error

func Error(args ...interface{})

Error logs a message at level Error on the standard logger.

func Errorf

func Errorf(format string, args ...interface{})

Errorf logs a message at level Error on the standard logger.

func GetFormatter

func GetFormatter() logrus.Formatter

GetFormatter return the logger formatter.

func GetLevel

func GetLevel() logrus.Level

GetLevel returns the standard logger level.

func Info

func Info(args ...interface{})

Info logs a message at level Info on the standard logger.

func Infof

func Infof(format string, args ...interface{})

Infof logs a message at level Info on the standard logger.

func Instrument

func Instrument(m instrumentation.Measure)

func IsLevelEnabled

func IsLevelEnabled(level logrus.Level) bool

IsLevelEnabled checks if the log level of the standard logger is greater than the level param

func NewStdoutTeeLogger

func NewStdoutTeeLogger(writer io.Writer, stdout bool) io.Writer

NewStdoutTeeLogger return an io.Writer that can redirect to stdout if needed.

func ParseLevel

func ParseLevel(lvl string) (logrus.Level, error)

ParseLevel takes a string level and returns the Logrus log level constant. Same implementation as logrus adding custom "smart" level mapping to debug.

func SetFormatter

func SetFormatter(formatter logrus.Formatter)

SetFormatter sets the standard logger formatter.

func SetLevel

func SetLevel(level logrus.Level)

SetLevel sets the standard logger level.

func SetOutput

func SetOutput(out io.Writer)

SetOutput sets the standard logger output.

func Trace

func Trace(args ...interface{})

Trace logs a message at level Trace on the standard logger.

func Tracef

func Tracef(format string, args ...interface{})

Tracef logs a message at level Trace on the standard logger.

func Warn

func Warn(args ...interface{})

Warn logs a message at level Warn on the standard logger.

func Warnf

func Warnf(format string, args ...interface{})

Warnf logs a message at level Warn on the standard logger.

func Warning

func Warning(args ...interface{})

Warning logs a message at level Warn on the standard logger.

Types

type Entry

type Entry func() *logrus.Entry

Entry is a functional wrapper for the logrus.Entry type

func WithComponent

func WithComponent(name string) Entry

WithComponent decorates log context with integration name

func WithError

func WithError(err error) Entry

func WithField

func WithField(key string, value interface{}) Entry

func WithFields

func WithFields(f logrus.Fields) Entry

func WithFieldsF

func WithFieldsF(lff func() logrus.Fields) Entry

func WithIntegration

func WithIntegration(name string) Entry

WithIntegration decorates log context with integration name

func WithPlugin

func WithPlugin(name string) Entry

WithPlugin decorates log context with plugin name

func WithTraceField

func WithTraceField(key string, value interface{}) Entry

func WithTraceFields

func WithTraceFields(f logrus.Fields) Entry

func WithTraceFieldsF

func WithTraceFieldsF(lff func() logrus.Fields) Entry

func (Entry) Debug

func (e Entry) Debug(msg string)

func (Entry) Debugf

func (e Entry) Debugf(format string, args ...interface{})

func (Entry) Error

func (e Entry) Error(msg string)

func (Entry) Errorf

func (e Entry) Errorf(format string, args ...interface{})

func (Entry) Fields

func (e Entry) Fields() logrus.Fields

func (Entry) Info

func (e Entry) Info(msg string)

func (Entry) Infof

func (e Entry) Infof(format string, args ...interface{})

func (Entry) IsDebugEnabled

func (e Entry) IsDebugEnabled() bool

func (Entry) IsWarnEnabled

func (e Entry) IsWarnEnabled() bool

func (Entry) Trace

func (e Entry) Trace(msg string)

func (Entry) Tracef

func (e Entry) Tracef(format string, args ...interface{})

func (Entry) Warn

func (e Entry) Warn(msg string)

func (Entry) Warnf

func (e Entry) Warnf(format string, args ...interface{})

func (Entry) WithComponent

func (e Entry) WithComponent(name string) Entry

WithComponent decorates entry context with integration name

func (Entry) WithError

func (e Entry) WithError(err error) Entry

func (Entry) WithField

func (e Entry) WithField(key string, value interface{}) Entry

func (Entry) WithFields

func (e Entry) WithFields(f logrus.Fields) Entry

func (Entry) WithFieldsF

func (e Entry) WithFieldsF(lff func() logrus.Fields) Entry

func (Entry) WithIntegration

func (e Entry) WithIntegration(name string) Entry

WithIntegration decorates entry context with integration name

func (Entry) WithPlugin

func (e Entry) WithPlugin(name string) Entry

WithPlugin decorates entry context with plugin name

func (Entry) WithTraceField

func (e Entry) WithTraceField(key string, value interface{}) Entry

func (Entry) WithTraceFields

func (e Entry) WithTraceFields(f logrus.Fields) Entry

Fields will be only added if TraceLevel is enabled

func (Entry) WithTraceFieldsF

func (e Entry) WithTraceFieldsF(lff func() logrus.Fields) Entry

type FileWithRotation

type FileWithRotation struct {
	sync.Mutex
	// contains filtered or unexported fields
}

FileWithRotation decorates a file with rotation mechanism. The current file will be rotated before Write(ing) new content if that will cause exceeding the configured max bytes. The rotated file will get the name from the provided pattern in the configuration. If rotation fails, we will continue to write to the current log file to avoid losing data.

Global logger should not be called within the synchronous methods of FileWithRotation since it can lead to a deadlock. Global logger can be called from Asynchronous code.

func NewFileWithRotation

func NewFileWithRotation(cfg FileWithRotationConfig) *FileWithRotation

NewFileWithRotation creates a new FileWithRotation.

func (*FileWithRotation) Close

func (f *FileWithRotation) Close() error

Close the file.

func (*FileWithRotation) Open

func (f *FileWithRotation) Open() (*FileWithRotation, error)

Open the file to write in. If the file doesn't exist, a new file will be created.

func (*FileWithRotation) Write

func (f *FileWithRotation) Write(content []byte) (int, error)

Write will check if the new content can be written into the file. If not, the file will be automatically rotated.

type FileWithRotationConfig

type FileWithRotationConfig struct {
	File            string
	FileNamePattern string
	MaxSizeInBytes  int64
	Compress        bool
	MaxFiles        int
}

FileWithRotationConfig keeps the configuration for a new FileWithRotation.

type MemLogger

type MemLogger struct {
	// contains filtered or unexported fields
}

func NewMemLogger

func NewMemLogger(writer io.Writer) *MemLogger

func (*MemLogger) Write

func (mem *MemLogger) Write(b []byte) (n int, err error)

func (*MemLogger) WriteBuffer

func (mem *MemLogger) WriteBuffer(writer io.Writer) (n int, err error)

Directories

Path Synopsis

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL