logger

package
v0.0.14 Latest Latest
Warning

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

Go to latest
Published: Feb 24, 2023 License: MIT Imports: 7 Imported by: 1

Documentation

Index

Constants

View Source
const (
	Reset       = "\033[0m"
	Gray        = "\033[1;30m"
	Red         = "\033[31m"
	Green       = "\033[32m"
	Yellow      = "\033[33m"
	Blue        = "\033[34m"
	Magenta     = "\033[35m"
	Cyan        = "\033[36m"
	White       = "\033[37m"
	BlueBold    = "\033[34;1m"
	MagentaBold = "\033[35;1m"
	RedBold     = "\033[31;1m"
	YellowBold  = "\033[33;1m"
	WhiteBold   = "\033[37;1m"
	CyanBold    = "\033[36;1m"
	Purple      = "\u001b[38;5;200m"
)

Variables

This section is empty.

Functions

This section is empty.

Types

type Entry

type Entry struct {
	Timestamp time.Time              `json:"timestamp,omitempty"`
	Message   string                 `json:"message"`
	Severity  string                 `json:"severity,omitempty"`
	Trace     string                 `json:"logging.googleapis.com/trace,omitempty"`
	Metadata  map[string]interface{} `json:"metadata,omitempty"`
	// Logs Explorer allows filtering and display of this as `jsonPayload.component`.
	Component string `json:"component,omitempty"`
}

Entry defines a log entry https://github.com/GoogleCloudPlatform/golang-samples/blob/08bc985b4973901c09344eabbe9d7d5add7dc656/run/logging-manual/main.go

func (Entry) String

func (e Entry) String() string

String renders an entry structure to the JSON format expected by Cloud Logging.

type Logger

type Logger interface {
	// With will return a new logger using metadata as the base context
	With(metadata map[string]interface{}) Logger
	// WithPrefix will return a new logger with a prefix prepended to the message
	WithPrefix(prefix string) Logger
	// WithSink returns a Logger which will also delegate logs to the provided sink
	WithSink(sink Sink) Logger
	// Trace level logging
	Trace(msg string, args ...interface{})
	// Debug level logging
	Debug(msg string, args ...interface{})
	// Info level logging
	Info(msg string, args ...interface{})
	// Warning level logging
	Warn(msg string, args ...interface{})
	// Error level logging
	Error(msg string, args ...interface{})
}

Logger is an interface for logging

func NewConsoleLogger

func NewConsoleLogger() Logger

NewConsoleLogger returns a new Logger instance which will log to the console

func NewGCloudLogger

func NewGCloudLogger() Logger

NewGCloudLogger returns a new Logger instance which can be used for structured google cloud logging

func NewGCloudLoggerWithSink added in v0.0.11

func NewGCloudLoggerWithSink(sink Sink) Logger

NewGCloudLoggerWithSink returns a new Logger instance using a sink and suppressing the console logging

type Sink added in v0.0.10

type Sink interface {
	// Write will receive the log output as a slice of bytes
	Write([]byte) error
}

type TestLogEntry

type TestLogEntry struct {
	Severity  string
	Message   string
	Arguments []interface{}
}

type TestLogger

type TestLogger struct {
	Logs []TestLogEntry
	// contains filtered or unexported fields
}

func NewTestLogger

func NewTestLogger() *TestLogger

NewTestLogger returns a new Logger instance useful for testing

func (*TestLogger) Debug

func (c *TestLogger) Debug(msg string, args ...interface{})

func (*TestLogger) Error

func (c *TestLogger) Error(msg string, args ...interface{})

func (*TestLogger) Info

func (c *TestLogger) Info(msg string, args ...interface{})

func (*TestLogger) Log

func (c *TestLogger) Log(level string, msg string, args ...interface{})

func (*TestLogger) Trace

func (c *TestLogger) Trace(msg string, args ...interface{})

func (*TestLogger) Warn

func (c *TestLogger) Warn(msg string, args ...interface{})

func (*TestLogger) With

func (c *TestLogger) With(metadata map[string]interface{}) Logger

func (*TestLogger) WithPrefix added in v0.0.13

func (c *TestLogger) WithPrefix(prefix string) Logger

WithPrefix will return a new logger with a prefix prepended to the message

func (*TestLogger) WithSink added in v0.0.10

func (c *TestLogger) WithSink(sink Sink) Logger

Jump to

Keyboard shortcuts

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