logger

package
v1.2.2 Latest Latest
Warning

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

Go to latest
Published: Nov 18, 2020 License: GPL-3.0 Imports: 13 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)

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 string, connectionID string, format string, v ...interface{})

Debug logs at debug level for the specified sender

func DebugToConsole

func DebugToConsole(format string, v ...interface{})

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 string, connectionID string, format string, v ...interface{})

Error logs at error level for the specified sender

func ErrorToConsole

func ErrorToConsole(format string, v ...interface{})

ErrorToConsole logs at error level to stdout

func GetLogger

func GetLogger() *zerolog.Logger

GetLogger get the configured logger instance

func Info

func Info(sender string, connectionID string, format string, v ...interface{})

Info logs at info level for the specified sender

func InfoToConsole

func InfoToConsole(format string, v ...interface{})

InfoToConsole logs at info level to stdout

func InitJournalDLogger added in v1.2.0

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 bool, level zerolog.Level)

InitLogger configures the logger using the given parameters

func InitStdErrLogger added in v1.2.0

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 ...interface{})

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 TransferLog

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

TransferLog logs an SFTP/SCP upload or download

func Warn

func Warn(sender string, connectionID string, format string, v ...interface{})

Warn logs at warn level for the specified sender

func WarnToConsole

func WarnToConsole(format string, v ...interface{})

WarnToConsole logs at info level to stdout

Types

type LogLevel

type LogLevel uint8

LogLevel defines log levels.

const (
	LevelDebug LogLevel = iota
	LevelInfo
	LevelWarn
	LevelError
)

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

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 interface{}, stack []byte)

Panic logs panics

func (*StructuredLoggerEntry) Write

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

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