logger

package
v0.0.22 Latest Latest
Warning

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

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

Documentation

Index

Constants

View Source
const (
	LogFilePermissions     = 0600
	DebugFilePermissions   = 0600
	ProfileFilePermissions = 0600
	InfoLogLevel           = "info"
)

Constants

Variables

View Source
var (

	// Log levels
	DEBUG zapcore.Level = zapcore.DebugLevel
	INFO  zapcore.Level = zapcore.InfoLevel
	WARN  zapcore.Level = zapcore.WarnLevel
	ERROR zapcore.Level = zapcore.ErrorLevel

	// Global settings
	GlobalEnableConsoleLogger bool
	GlobalEnableFileLogger    bool
	GlobalEnableBufferLogger  bool
	GlobalLogPath             string = "/tmp/andaime.log"
	GlobalLogLevel            string = InfoLogLevel
	GlobalInstantSync         bool
	GlobalLoggedBuffer        strings.Builder
	GlobalLoggedBufferSize    int = 8192
	GlobalLogFile             *os.File
)

Global variables

Functions

func GetLastLines

func GetLastLines(n int) []string

GetLastLines gets the last n lines from the log

func InitLoggerOutputs

func InitLoggerOutputs()

Initialization functions

func InitProduction

func InitProduction()

func LogPanic

func LogPanic(rec interface{})

Panic handling

func RecoverAndLog

func RecoverAndLog(f func())

func SetGlobalLogger

func SetGlobalLogger(logger interface{})

Types

type LogBuffer added in v0.0.20

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

LogBuffer maintains a circular buffer of log messages

func NewLogBuffer added in v0.0.20

func NewLogBuffer(size int) *LogBuffer

NewLogBuffer creates a new log buffer with specified size

func (*LogBuffer) AddLine added in v0.0.20

func (lb *LogBuffer) AddLine(line string)

AddLine adds a line to the buffer, maintaining the circular buffer behavior

func (*LogBuffer) GetLastLines added in v0.0.20

func (lb *LogBuffer) GetLastLines(n int) []string

GetLastLines returns the last n lines from the buffer

type Logger

type Logger struct {
	*zap.Logger
	// contains filtered or unexported fields
}

Logger types

func Get

func Get() *Logger

Global functions

func NewNopLogger

func NewNopLogger() *Logger

func (*Logger) Debug

func (l *Logger) Debug(msg string)

func (*Logger) DebugWithFields added in v0.0.20

func (l *Logger) DebugWithFields(msg string, fields ...zap.Field)

Field logging methods

func (*Logger) Debugf

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

Formatted logging methods

func (*Logger) Error

func (l *Logger) Error(msg string)

func (*Logger) ErrorWithFields added in v0.0.20

func (l *Logger) ErrorWithFields(msg string, fields ...zap.Field)

func (*Logger) Errorf

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

func (*Logger) Fatal

func (l *Logger) Fatal(msg string)

func (*Logger) Fatalf

func (l *Logger) Fatalf(
	format string,
	args ...interface{},
)

func (*Logger) Info

func (l *Logger) Info(msg string)

func (*Logger) InfoWithFields added in v0.0.20

func (l *Logger) InfoWithFields(msg string, fields ...zap.Field)

func (*Logger) Infof

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

func (*Logger) PrintLogs added in v0.0.20

func (l *Logger) PrintLogs(t *testing.T)

PrintLogs prints all captured logs to the test output

func (*Logger) SetVerbose

func (l *Logger) SetVerbose(verbose bool)

Logger implementation

func (*Logger) Warn

func (l *Logger) Warn(msg string)

func (*Logger) WarnWithFields added in v0.0.20

func (l *Logger) WarnWithFields(msg string, fields ...zap.Field)

func (*Logger) Warnf

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

func (*Logger) With

func (l *Logger) With(fields ...zap.Field) Loggerer

Update Logger's With method

type Loggerer added in v0.0.20

type Loggerer interface {
	Debug(msg string)
	Info(msg string)
	Warn(msg string)
	Error(msg string)
	SetVerbose(bool)
	Debugf(format string, args ...interface{})
	Infof(format string, args ...interface{})
	Warnf(format string, args ...interface{})
	Errorf(format string, args ...interface{})
	PrintLogs(*testing.T)
	With(fields ...zap.Field) Loggerer
}

type TestLogger added in v0.0.20

type TestLogger struct {
	*Logger
	// contains filtered or unexported fields
}

func NewTestLogger

func NewTestLogger(tb zaptest.TestingT) *TestLogger

Create new loggers

func (*TestLogger) Debug added in v0.0.20

func (tl *TestLogger) Debug(msg string)

Test logger methods with capture

func (*TestLogger) Error added in v0.0.20

func (tl *TestLogger) Error(msg string)

func (*TestLogger) GetLastLines added in v0.0.20

func (tl *TestLogger) GetLastLines(n int) []string

Update test logger methods to use buffer

func (*TestLogger) GetLogs added in v0.0.20

func (tl *TestLogger) GetLogs() []string

TestLogger implementation

func (*TestLogger) Info added in v0.0.20

func (tl *TestLogger) Info(msg string)

func (*TestLogger) PrintLogs added in v0.0.20

func (tl *TestLogger) PrintLogs(t *testing.T)

PrintLogs prints all captured logs to the test output

func (*TestLogger) Warn added in v0.0.20

func (tl *TestLogger) Warn(msg string)

func (*TestLogger) With added in v0.0.20

func (tl *TestLogger) With(fields ...zap.Field) Loggerer

Update TestLogger's With method

Jump to

Keyboard shortcuts

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