logger

package
v0.0.0-...-024d10c Latest Latest
Warning

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

Go to latest
Published: Oct 28, 2021 License: GPL-3.0 Imports: 8 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 zerlog

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func CommandLog

func CommandLog(command string, path string, target string, user string, connectionID string, protocol string)

CommandLog logs an SFTP/SCP command

func Debug

func Debug(sender 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 Error

func Error(sender 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, 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 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 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 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, 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 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, v 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