logger

package
v1.1.1 Latest Latest
Warning

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

Go to latest
Published: Feb 14, 2022 License: MIT Imports: 27 Imported by: 46

Documentation

Index

Constants

View Source
const (
	HeadTracker = "head_tracker"
	FluxMonitor = "fluxmonitor"
	Keeper      = "keeper"
)

Constants for service names for package specific logging configuration

View Source
const SentryFlushDeadline = 5 * time.Second

Variables

This section is empty.

Functions

func Error

func Error(args ...interface{})

Error logs an error message. Deprecated

func Errorf

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

Errorf logs a message at the error level using Sprintf. Deprecated

func Errorw

func Errorw(msg string, keysAndValues ...interface{})

Errorw logs an error message, any additional given information, and includes stack trace. Deprecated

func Fatalf

func Fatalf(format string, values ...interface{})

Fatalf logs a message at the fatal level using Sprintf. Deprecated

func GetLogServices added in v0.10.6

func GetLogServices() []string

func InitColor added in v1.1.0

func InitColor(c bool)

InitColor explicitly sets the global color.NoColor option. Not safe for concurrent use. Only to be called from init().

func InitLogger added in v1.1.0

func InitLogger(newLogger Logger)

InitLogger sets the helper Logger to newLogger. Not safe for concurrent use, so must be called from init() or the main goroutine during initialization.

You probably don't want to use this. Loggers should be injected instead. Deprecated

func NewOCRWrapper added in v1.1.0

func NewOCRWrapper(l Logger, trace bool, saveError func(string)) ocrtypes.Logger

func NewORM added in v0.10.6

func NewORM(db *sqlx.DB, lggr Logger) *orm

NewORM initializes a new ORM

func Warn

func Warn(args ...interface{})

Warn logs a message at the warn level. Deprecated

func Warnf

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

Warnf formats and then logs the message as Warn. Deprecated

func Warnw

func Warnw(msg string, keysAndValues ...interface{})

Warnw logs a debug message and any additional given information. Deprecated

Types

type Config added in v1.1.0

type Config interface {
	RootDir() string
	JSONConsole() bool
	LogToDisk() bool
	LogLevel() zapcore.Level
	LogUnixTimestamps() bool
}

type Fields added in v1.1.0

type Fields map[string]interface{}

func (Fields) Merge added in v1.1.0

func (f Fields) Merge(f2 Fields) Fields

func (Fields) Slice added in v1.1.0

func (f Fields) Slice() []interface{}

func (Fields) With added in v1.1.0

func (f Fields) With(xs ...interface{}) Fields

type LogConfig added in v0.10.6

type LogConfig struct {
	ID          int64
	ServiceName string
	LogLevel    string
	CreatedAt   time.Time
	UpdatedAt   time.Time
}

LogConfig stores key value pairs for configuring package specific logging

type Logger

type Logger interface {
	// With creates a new Logger with the given arguments
	With(args ...interface{}) Logger
	// Named creates a new Logger sub-scoped with name.
	// Names are inherited and dot-separated.
	//   a := l.Named("a") // logger=a
	//   b := a.Named("b") // logger=a.b
	Named(name string) Logger

	// NewRootLogger creates a new root Logger with an independent log level
	// unaffected by upstream calls to SetLogLevel.
	NewRootLogger(lvl zapcore.Level) (Logger, error)

	// SetLogLevel changes the log level for this and all connected Loggers.
	SetLogLevel(zapcore.Level)

	Trace(args ...interface{})
	Debug(args ...interface{})
	Info(args ...interface{})
	Warn(args ...interface{})
	Error(args ...interface{})
	Critical(args ...interface{})
	Panic(args ...interface{})
	Fatal(args ...interface{})

	Tracef(format string, values ...interface{})
	Debugf(format string, values ...interface{})
	Infof(format string, values ...interface{})
	Warnf(format string, values ...interface{})
	Errorf(format string, values ...interface{})
	Criticalf(format string, values ...interface{})
	Panicf(format string, values ...interface{})
	Fatalf(format string, values ...interface{})

	Tracew(msg string, keysAndValues ...interface{})
	Debugw(msg string, keysAndValues ...interface{})
	Infow(msg string, keysAndValues ...interface{})
	Warnw(msg string, keysAndValues ...interface{})
	Errorw(msg string, keysAndValues ...interface{})
	CriticalW(msg string, keysAndValues ...interface{})
	Panicw(msg string, keysAndValues ...interface{})
	Fatalw(msg string, keysAndValues ...interface{})

	// ErrorIf logs the error if present.
	ErrorIf(err error, msg string)

	// ErrorIfClosing calls c.Close() and logs any returned error along with name.
	ErrorIfClosing(c io.Closer, name string)

	// Sync flushes any buffered log entries.
	// Some insignificant errors are suppressed.
	Sync() error

	// Helper creates a new logger with the number of callers skipped by caller annotation increased by skip.
	// This allows wrappers and helpers to point higher up the stack (like testing.T.Helper()).
	Helper(skip int) Logger
}
var NullLogger Logger

func NewLogger added in v1.1.0

func NewLogger(c Config) Logger

NewLogger returns a new Logger configured by c with pretty printing to stdout. If LogToDisk is false, the Logger will only log to stdout. Tests should use TestLogger instead.

func NewNullLogger added in v1.1.0

func NewNullLogger() Logger

func TestLogger added in v1.1.0

func TestLogger(t T) Logger

TestLogger creates a logger that directs output to PrettyConsole configured for test output, and to the buffer testMemoryLog. t is optional. Log level is derived from the LOG_LEVEL env var.

type MemorySink added in v0.8.15

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

MemorySink implements zap.Sink by writing all messages to a buffer.

func MemoryLogTestingOnly added in v0.8.15

func MemoryLogTestingOnly() *MemorySink

func (*MemorySink) Close added in v0.8.15

func (s *MemorySink) Close() error

Close is a dummy method to satisfy the zap.Sink interface

func (*MemorySink) Reset added in v1.1.0

func (s *MemorySink) Reset()

func (*MemorySink) String added in v0.8.15

func (s *MemorySink) String() string

String returns the full log contents, as a string

func (*MemorySink) Sync added in v0.8.15

func (s *MemorySink) Sync() error

Sync is a dummy method to satisfy the zap.Sink interface

func (*MemorySink) Write added in v0.8.15

func (s *MemorySink) Write(p []byte) (n int, err error)

type ORM added in v0.10.6

type ORM interface {
	GetServiceLogLevel(serviceName string) (level string, ok bool)
	SetServiceLogLevel(ctx context.Context, serviceName string, level string) error
}

type PrettyConsole

type PrettyConsole struct {
	zap.Sink
}

PrettyConsole wraps a Sink (Writer, Syncer, Closer), usually stdout, and formats the incoming json bytes with colors and white space for readability before passing on to the underlying Writer in Sink.

func (PrettyConsole) Write

func (pc PrettyConsole) Write(b []byte) (int, error)

Write reformats the incoming json bytes with colors, newlines and whitespace for better readability in console.

type T added in v1.1.0

type T interface {
	Name() string
	Fatal(...interface{})
}

Jump to

Keyboard shortcuts

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