logger

package
v0.0.0-...-620b1b6 Latest Latest
Warning

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

Go to latest
Published: Jul 31, 2024 License: Apache-2.0 Imports: 12 Imported by: 0

Documentation

Overview

Package logger provides a client for integration with the support-logging service. The client can also be configured to write logs to a local file rather than sending them to a service.

Index

Constants

View Source
const (
	TraceLog = "TRACE"
	DebugLog = "DEBUG"
	InfoLog  = "INFO"
	WarnLog  = "WARN"
	ErrorLog = "ERROR"
)

These constants identify the log levels in order of increasing severity.

View Source
const (
	Reset       = "\033[0m"
	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"
)

Colors

View Source
const (
	LogPathEnvName  = "LOG_PATH"
	LogLevel        = "LOG_LEVEL"
	DefaultLogLevel = InfoLog
	DefaultLogPath  = ""
)

Variables

This section is empty.

Functions

func NewZapLogger

func NewZapLogger(atomLevel zap.AtomicLevel, logPath string) (zapLog *zap.Logger, err error)

Types

type LogEntry

type LogEntry struct {
	Level         string        `bson:"logLevel,omitempty" json:"logLevel"`
	Args          []interface{} `bson:"args,omitempty" json:"args"`
	OriginService string        `bson:"originService,omitempty" json:"originService"`
	Message       string        `bson:"message,omitempty" json:"message"`
	Created       int64         `bson:"created,omitempty" json:"created"`
	// contains filtered or unexported fields
}

func (*LogEntry) UnmarshalJSON

func (le *LogEntry) UnmarshalJSON(data []byte) error

UnmarshalJSON implements the Unmarshaler interface for the LogEntry type

func (LogEntry) Validate

func (le LogEntry) Validate() (bool, error)

Validate satisfies the Validator interface

type LogMessage

type LogMessage struct {
	Time        string        `json:"time"`
	ServiceName string        `json:"service_name"`
	Caller      string        `json:"caller"`
	Message     []interface{} `json:"message"`
}

type LoggingClient

type LoggingClient interface {
	// SetLogLevel sets minimum severity log level. If a logging method is called with a lower level of severity than
	// what is set, it will result in no output.
	SetLogLevel(logLevel string) error
	// LogLevel returns the current log level setting
	LogLevel() string
	// Debug logs a message at the DEBUG severity level
	Debug(msg string, args ...interface{})
	// Error logs a message at the ERROR severity level
	Error(msg string, args ...interface{})
	// Info logs a message at the INFO severity level
	Info(msg string, args ...interface{})
	// Trace logs a message at the TRACE severity level
	Trace(msg string, args ...interface{})
	// Warn logs a message at the WARN severity level
	Warn(msg string, args ...interface{})
	// Debugf logs a formatted message at the DEBUG severity level
	Debugf(msg string, args ...interface{})
	// Errorf logs a formatted message at the ERROR severity level
	Errorf(msg string, args ...interface{})
	// Infof logs a formatted message at the INFO severity level
	Infof(msg string, args ...interface{})
	// Tracef logs a formatted message at the TRACE severity level
	Tracef(msg string, args ...interface{})
	// Warnf logs a formatted message at the WARN severity level
	Warnf(msg string, args ...interface{})
}

LoggingClient defines the interface for logging operations.

func NewClient

func NewClient(owningServiceName string, logLevel, logPath string) LoggingClient

NewClient creates an instance of LoggingClient

func NewMockClient

func NewMockClient() LoggingClient

NewMockClient creates a mock instance of LoggingClient

type MockLogger

type MockLogger struct {
}

MockLogger is a type that can be used for mocking the LoggingClient interface during unit tests

func (MockLogger) Debug

func (lc MockLogger) Debug(_ string, _ ...interface{})

Debug simulates logging an entry at the DEBUG severity level

func (MockLogger) Debugf

func (lc MockLogger) Debugf(_ string, _ ...interface{})

Debugf simulates logging an formatted message at the DEBUG severity level

func (MockLogger) Error

func (lc MockLogger) Error(_ string, _ ...interface{})

Error simulates logging an entry at the ERROR severity level

func (MockLogger) Errorf

func (lc MockLogger) Errorf(_ string, _ ...interface{})

Errorf simulates logging an formatted message at the ERROR severity level

func (MockLogger) Info

func (lc MockLogger) Info(_ string, _ ...interface{})

Info simulates logging an entry at the INFO severity level

func (MockLogger) Infof

func (lc MockLogger) Infof(_ string, _ ...interface{})

Infof simulates logging an formatted message at the INFO severity level

func (MockLogger) LogLevel

func (lc MockLogger) LogLevel() string

LogLevel returns the current log level setting

func (MockLogger) SetLogLevel

func (lc MockLogger) SetLogLevel(_ string) error

SetLogLevel simulates setting a log severity level

func (MockLogger) Trace

func (lc MockLogger) Trace(_ string, _ ...interface{})

Trace simulates logging an entry at the TRACE severity level

func (MockLogger) Tracef

func (lc MockLogger) Tracef(_ string, _ ...interface{})

Tracef simulates logging an formatted message at the TRACE severity level

func (MockLogger) Warn

func (lc MockLogger) Warn(_ string, _ ...interface{})

Warn simulates logging an entry at the WARN severity level

func (MockLogger) Warnf

func (lc MockLogger) Warnf(_ string, _ ...interface{})

Warnf simulates logging an formatted message at the WARN severity level

Jump to

Keyboard shortcuts

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