logger

package
v0.0.4 Latest Latest
Warning

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

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

Documentation

Index

Constants

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

Variables

View Source
var (
	DEBUG zapcore.Level = zapcore.DebugLevel
	INFO  zapcore.Level = zapcore.InfoLevel
	WARN  zapcore.Level = zapcore.WarnLevel
	ERROR zapcore.Level = zapcore.ErrorLevel

	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
)
View Source
var (
	ZapString  = zap.String
	ZapInt     = zap.Int
	ZapFloat64 = zap.Float64
	ZapBool    = zap.Bool
	ZapError   = zap.Error
	ZapAny     = zap.Any
)

Common field constructors

Functions

func DebugPrint

func DebugPrint(msg string)

func GetLastLines

func GetLastLines(n int) []string

func GetProfileFilePath

func GetProfileFilePath() string

func InitLoggerOutputs

func InitLoggerOutputs()

func InitProduction

func InitProduction()

func InitTest

func InitTest(tb zaptest.TestingT)

InitTest initializes the global logger for testing, respecting LOG_LEVEL.

func LogAzureAPIStart

func LogAzureAPIStart(operation string)

LogAzureAPIStart logs the start of an Azure API operation

func LogInitialization

func LogInitialization(msg string)

func LogPanic

func LogPanic(rec interface{})

LogPanic logs the panic message and stack trace

func RecoverAndLog

func RecoverAndLog(f func())

RecoverAndLog wraps a function with panic recovery and logging

func SetGlobalLogger

func SetGlobalLogger(logger *Logger)

SetGlobalLogger sets the global logger instance

func SetLevel

func SetLevel(level zapcore.Level)

SetLevel sets the logging level for the global logger

func SetLogLevel

func SetLogLevel(level string)

SetLogLevel changes the global log level

func SetOutputFormat

func SetOutputFormat(format string)

SetOutputFormat sets the output format for the logger

func WriteProfileInfo

func WriteProfileInfo(info string)

func WriteToDebugLog

func WriteToDebugLog(message string)

Types

type Field

type Field = zap.Field

Fields is a type alias for zap.Field for convenience

type LevelEnablerFunc

type LevelEnablerFunc func(zapcore.Level) bool

LevelEnablerFunc is a wrapper to implement zapcore.LevelEnabler

func (LevelEnablerFunc) Enabled

func (f LevelEnablerFunc) Enabled(level zapcore.Level) bool

Enabled implements zapcore.LevelEnabler interface

type Logger

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

Logger is a wrapper around zap.Logger

func Get

func Get() *Logger

Get returns the global logger instance

func NewNopLogger

func NewNopLogger() *Logger

NewNopLogger returns a no-op Logger

func NewTestLogger

func NewTestLogger(tb zaptest.TestingT) *Logger

NewTestLogger creates a new Logger instance for testing

func (*Logger) Debug

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

func (*Logger) Debugf

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

func (*Logger) Error

func (l *Logger) Error(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, fields ...zap.Field)

func (*Logger) Fatalf

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

func (*Logger) Info

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

func (*Logger) Infof

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

func (*Logger) SetVerbose

func (l *Logger) SetVerbose(verbose bool)

func (*Logger) Sync

func (l *Logger) Sync() error

Sync flushes any buffered log entries

func (*Logger) Warn

func (l *Logger) Warn(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) *Logger

With creates a child logger and adds structured context to it

Jump to

Keyboard shortcuts

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