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 ¶
- func CommandLog(command string, path string, target string, user string, connectionID string, ...)
- func Debug(sender string, format string, v ...interface{})
- func DebugToConsole(format string, v ...interface{})
- func Error(sender string, format string, v ...interface{})
- func ErrorToConsole(format string, v ...interface{})
- func GetLogger() *zerolog.Logger
- func Info(sender string, format string, v ...interface{})
- func InfoToConsole(format string, v ...interface{})
- func InitLogger(logFilePath string, logMaxSize int, logMaxBackups int, logMaxAge int, ...)
- func NewStructuredLogger(logger *zerolog.Logger) func(next http.Handler) http.Handler
- func TransferLog(operation string, path string, elapsed int64, size int64, user string, ...)
- func Warn(sender string, format string, v ...interface{})
- func WarnToConsole(format string, v ...interface{})
- type StructuredLogger
- type StructuredLoggerEntry
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 DebugToConsole ¶
func DebugToConsole(format string, v ...interface{})
DebugToConsole logs at debug level to stdout
func ErrorToConsole ¶
func ErrorToConsole(format string, v ...interface{})
ErrorToConsole logs at error level to stdout
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 ¶
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 WarnToConsole ¶
func WarnToConsole(format string, v ...interface{})
WarnToConsole logs at info level to stdout
Types ¶
type StructuredLogger ¶
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