logger

package
v2.3.6 Latest Latest
Warning

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

Go to latest
Published: Oct 12, 2022 License: AGPL-3.0 Imports: 18 Imported by: 0

Documentation

Overview

Package logger provides logging capabilities. It is a wrapper around zerolog for logging and lumberjack for log rotation. Logs are written to the specified log file. Logging on the console is provided to print initialization info, errors and warnings. The package provides a request logger to log the HTTP requests for REST API too. The request logger uses chi.middleware.RequestLogger, chi.middleware.LogFormatter and chi.middleware.LogEntry to build a structured logger using zerolog

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func CommandLog

func CommandLog(command, path, target, user, fileMode, connectionID, protocol string, uid, gid int, atime, mtime,
	sshCommand string, size int64, localAddr, remoteAddr string)

CommandLog logs an SFTP/SCP/SSH command

func ConnectionFailedLog

func ConnectionFailedLog(user, ip, loginType, protocol, errorString string)

ConnectionFailedLog logs failed attempts to initialize a connection. A connection can fail for an authentication error or other errors such as a client abort or a time out if the login does not happen in two minutes. These logs are useful for better integration with Fail2ban and similar tools.

func Debug

func Debug(sender, connectionID, format string, v ...any)

Debug logs at debug level for the specified sender

func DebugToConsole

func DebugToConsole(format string, v ...any)

DebugToConsole logs at debug level to stdout

func DisableLogger

func DisableLogger()

DisableLogger disable the main logger. ConsoleLogger will not be affected

func EnableConsoleLogger

func EnableConsoleLogger(level zerolog.Level)

EnableConsoleLogger enables the console logger

func Error

func Error(sender, connectionID, format string, v ...any)

Error logs at error level for the specified sender

func ErrorToConsole

func ErrorToConsole(format string, v ...any)

ErrorToConsole logs at error level to stdout

func GetLogger

func GetLogger() *zerolog.Logger

GetLogger get the configured logger instance

func Info

func Info(sender, connectionID, format string, v ...any)

Info logs at info level for the specified sender

func InfoToConsole

func InfoToConsole(format string, v ...any)

InfoToConsole logs at info level to stdout

func InitJournalDLogger

func InitJournalDLogger(level zerolog.Level)

InitJournalDLogger configures the logger to write to journald

func InitLogger

func InitLogger(logFilePath string, logMaxSize int, logMaxBackups int, logMaxAge int, logCompress, logUTCTime bool,
	level zerolog.Level,
)

InitLogger configures the logger using the given parameters

func InitStdErrLogger

func InitStdErrLogger(level zerolog.Level)

InitStdErrLogger configures the logger to write to stderr

func Log

func Log(level LogLevel, sender string, connectionID string, format string, v ...any)

Log logs at the specified level for the specified sender

func NewStructuredLogger

func NewStructuredLogger(logger *zerolog.Logger) func(next http.Handler) http.Handler

NewStructuredLogger returns a chi.middleware.RequestLogger using our StructuredLogger. This structured logger is called by the chi.middleware.Logger handler to log each HTTP request

func RotateLogFile

func RotateLogFile() error

RotateLogFile closes the existing log file and immediately create a new one

func SetLogTime

func SetLogTime(utc bool)

SetLogTime sets logging time related setting

func TransferLog

func TransferLog(operation, path string, elapsed int64, size int64, user, connectionID, protocol, localAddr,
	remoteAddr, ftpMode string,
)

TransferLog logs uploads or downloads

func Warn

func Warn(sender, connectionID, format string, v ...any)

Warn logs at warn level for the specified sender

func WarnToConsole

func WarnToConsole(format string, v ...any)

WarnToConsole logs at info level to stdout

Types

type HCLogAdapter

type HCLogAdapter struct {
	hclog.Logger
}

HCLogAdapter is an adapter for hclog.Logger

func (*HCLogAdapter) Debug

func (l *HCLogAdapter) Debug(msg string, args ...any)

Debug emits a message and key/value pairs at the DEBUG level

func (*HCLogAdapter) Error

func (l *HCLogAdapter) Error(msg string, args ...any)

Error emits a message and key/value pairs at the ERROR level

func (*HCLogAdapter) Info

func (l *HCLogAdapter) Info(msg string, args ...any)

Info emits a message and key/value pairs at the INFO level

func (*HCLogAdapter) Log

func (l *HCLogAdapter) Log(level hclog.Level, msg string, args ...any)

Log emits a message and key/value pairs at a provided log level

func (*HCLogAdapter) Named

func (l *HCLogAdapter) Named(name string) hclog.Logger

Named creates a logger that will prepend the name string on the front of all messages

func (*HCLogAdapter) StandardLogger

func (l *HCLogAdapter) StandardLogger(opts *hclog.StandardLoggerOptions) *log.Logger

StandardLogger returns a value that conforms to the stdlib log.Logger interface

func (*HCLogAdapter) StandardWriter

func (l *HCLogAdapter) StandardWriter(opts *hclog.StandardLoggerOptions) io.Writer

StandardWriter returns a value that conforms to io.Writer, which can be passed into log.SetOutput()

func (*HCLogAdapter) Trace

func (l *HCLogAdapter) Trace(msg string, args ...any)

Trace emits a message and key/value pairs at the TRACE level

func (*HCLogAdapter) Warn

func (l *HCLogAdapter) Warn(msg string, args ...any)

Warn emits a message and key/value pairs at the WARN level

func (*HCLogAdapter) With

func (l *HCLogAdapter) With(args ...any) hclog.Logger

With creates a sub-logger

type LegoAdapter added in v2.3.0

type LegoAdapter struct {
	LogToConsole bool
}

LegoAdapter is an adapter for lego.StdLogger

func (*LegoAdapter) Fatal added in v2.3.0

func (l *LegoAdapter) Fatal(args ...any)

Fatal emits a log at Error level

func (*LegoAdapter) Fatalf added in v2.3.0

func (l *LegoAdapter) Fatalf(format string, args ...any)

Fatalf emits a log at Error level

func (*LegoAdapter) Fatalln added in v2.3.0

func (l *LegoAdapter) Fatalln(args ...any)

Fatalln is the same as Fatal

func (*LegoAdapter) Print added in v2.3.0

func (l *LegoAdapter) Print(args ...any)

Print emits a log at Info level

func (*LegoAdapter) Printf added in v2.3.0

func (l *LegoAdapter) Printf(format string, args ...any)

Printf emits a log at Info level

func (*LegoAdapter) Println added in v2.3.0

func (l *LegoAdapter) Println(args ...any)

Println is the same as Print

type LeveledLogger

type LeveledLogger struct {
	Sender string
	// contains filtered or unexported fields
}

LeveledLogger is a logger that accepts a message string and a variadic number of key-value pairs

func (*LeveledLogger) Debug

func (l *LeveledLogger) Debug(msg string, keysAndValues ...any)

Debug logs at debug level for the specified sender

func (*LeveledLogger) Error

func (l *LeveledLogger) Error(msg string, keysAndValues ...any)

Error logs at error level for the specified sender

func (*LeveledLogger) Info

func (l *LeveledLogger) Info(msg string, keysAndValues ...any)

Info logs at info level for the specified sender

func (*LeveledLogger) Panic added in v2.2.3

func (l *LeveledLogger) Panic(msg string, keysAndValues ...any)

Panic logs the panic at error level for the specified sender

func (*LeveledLogger) Warn

func (l *LeveledLogger) Warn(msg string, keysAndValues ...any)

Warn logs at warn level for the specified sender

func (*LeveledLogger) With

func (l *LeveledLogger) With(keysAndValues ...any) ftpserverlog.Logger

With returns a LeveledLogger with additional context specific keyvals

type LogLevel

type LogLevel uint8

LogLevel defines log levels.

const (
	LevelDebug LogLevel = iota
	LevelInfo
	LevelWarn
	LevelError
)

defines our own log levels, just in case we'll change logger in future

type StdLoggerWrapper

type StdLoggerWrapper struct {
	Sender string
}

StdLoggerWrapper is a wrapper for standard logger compatibility

func (*StdLoggerWrapper) Write

func (l *StdLoggerWrapper) Write(p []byte) (n int, err error)

Write implements the io.Writer interface. This is useful to set as a writer for the standard library log.

type StructuredLogger

type StructuredLogger struct {
	Logger *zerolog.Logger
}

StructuredLogger defines a simple wrapper around zerolog logger. It implements chi.middleware.LogFormatter interface

func (*StructuredLogger) NewLogEntry

func (l *StructuredLogger) NewLogEntry(r *http.Request) middleware.LogEntry

NewLogEntry creates a new log entry for an HTTP request

type StructuredLoggerEntry

type StructuredLoggerEntry struct {
	// The zerolog logger
	Logger *zerolog.Logger
	// contains filtered or unexported fields
}

StructuredLoggerEntry defines a log entry. It implements chi.middleware.LogEntry interface

func (*StructuredLoggerEntry) Panic

func (l *StructuredLoggerEntry) Panic(v any, stack []byte)

Panic logs panics

func (*StructuredLoggerEntry) Write

func (l *StructuredLoggerEntry) Write(status, bytes int, header http.Header, elapsed time.Duration, extra any)

Write logs a new entry at the end of the HTTP request

Jump to

Keyboard shortcuts

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