logs

package module
v2.0.0 Latest Latest
Warning

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

Go to latest
Published: Aug 31, 2025 License: MIT Imports: 7 Imported by: 0

README

Logs

This is the logging package used by the Cyclops camera system.

These are plain old textual logs, with a logging level and a format string.

You can write your own custom log output object by implementing the LogWriter interface, and replacing the Output object on your Log. For example, if you want to store log messages in a buffer, then you can do this:


// LogStore is a log writer that stores log messages in a slice of strings before sending them out
type LogStore struct {
	Stored []string       // Stored logs
	Output logs.LogWriter // Original writer
}

func (s *LogStore) Flags() logs.LogWriterFlags {
	return s.Output.Flags()
}

func (s *LogStore) Write(level logs.Level, message string) {
	s.Stored = append(s.Stored, message)
	s.Output.Write(level, message)
}

func (s *LogStore) Close() {
	// TODO: Do something special with the stored messages, like send them up to a telemetry server
	s.Output.Close()
}

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Level

type Level int

Log level

const (
	LevelDebug    Level = iota // information that only a programmer will understand
	LevelInfo                  // information that a non-programmer might be interested in
	LevelWarn                  // speeds up tracking down issues, once you know about them
	LevelError                 // should not have happened
	LevelCritical              // wake somebody up
)

type Log

type Log struct {
	Output LogWriter
}

The log object that you use to write logs

func NewLog

func NewLog() (*Log, error)

Create a new logger

func NewTestingLog

func NewTestingLog(t *testing.T) *Log

Create new log for use during unit tests

func (*Log) Close

func (l *Log) Close()

func (*Log) Criticalf

func (l *Log) Criticalf(format string, a ...any)

func (*Log) Debugf

func (l *Log) Debugf(format string, a ...any)

func (*Log) Errorf

func (l *Log) Errorf(format string, a ...any)

func (*Log) Infof

func (l *Log) Infof(format string, a ...any)

func (*Log) Warnf

func (l *Log) Warnf(format string, a ...any)

type LogWriter

type LogWriter interface {
	Flags() LogWriterFlags
	Write(level Level, message string)
	Close()
}

LogWriter is the low level object that writes the logs

type LogWriterFlags

type LogWriterFlags int

Log writer flags

const (
	LogWriterFlagNeedNewline LogWriterFlags = 1 << iota // If you should end the message with a \n
	LogWriterFlagWantDate                               // If you should embed the date at the start of the message
	LogWriterFlagWantLevel                              // If you should embed the level at the start of the message
	LogWriterFlagWantColors                             // If you should embed color escape codes
)

type LogWriterGCP

type LogWriterGCP struct {
	Logger *logging.Logger
	Client *logging.Client
}

Write logs to Google Cloud

func (*LogWriterGCP) Close

func (w *LogWriterGCP) Close()

func (*LogWriterGCP) Flags

func (w *LogWriterGCP) Flags() LogWriterFlags

func (*LogWriterGCP) Write

func (w *LogWriterGCP) Write(level Level, message string)

type LogWriterStandard

type LogWriterStandard struct {
	Output       io.Writer
	EnableColors bool
}

Write logs to a standard file such as stdout

func (*LogWriterStandard) Close

func (w *LogWriterStandard) Close()

func (*LogWriterStandard) Flags

func (w *LogWriterStandard) Flags() LogWriterFlags

func (*LogWriterStandard) Write

func (w *LogWriterStandard) Write(level Level, message string)

type LogWriterTest

type LogWriterTest struct {
	T *testing.T
}

Write logs during unit tests

func (*LogWriterTest) Close

func (w *LogWriterTest) Close()

func (*LogWriterTest) Flags

func (w *LogWriterTest) Flags() LogWriterFlags

func (*LogWriterTest) Write

func (w *LogWriterTest) Write(level Level, message string)

type PrefixLogger

type PrefixLogger struct {
	Log    Log
	Prefix string
}

PrefixLogger writes to the underlying log, but all messages are prefixed with a string of your choice

func NewPrefixLogger

func NewPrefixLogger(log Log, prefix string) *PrefixLogger

Create a new PrefixLogger

func NewPrefixLoggerNoSpace

func NewPrefixLoggerNoSpace(log Log, prefix string) *PrefixLogger

Create a new PrefixLogger, but don't add a space onto 'prefix'

func (*PrefixLogger) Close

func (l *PrefixLogger) Close()

func (*PrefixLogger) Criticalf

func (l *PrefixLogger) Criticalf(format string, a ...any)

func (*PrefixLogger) Debugf

func (l *PrefixLogger) Debugf(format string, a ...any)

func (*PrefixLogger) Errorf

func (l *PrefixLogger) Errorf(format string, a ...any)

func (*PrefixLogger) Infof

func (l *PrefixLogger) Infof(format string, a ...any)

func (*PrefixLogger) Warnf

func (l *PrefixLogger) Warnf(format string, a ...any)

Jump to

Keyboard shortcuts

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