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 ¶
- func CommandLog(command, path, target, user, fileMode, connectionID, protocol string, ...)
- func ConnectionFailedLog(user, ip, loginType, protocol, errorString string)
- func Debug(sender string, connectionID string, format string, v ...interface{})
- func DebugToConsole(format string, v ...interface{})
- func DisableLogger()
- func EnableConsoleLogger(level zerolog.Level)
- func Error(sender string, connectionID string, format string, v ...interface{})
- func ErrorToConsole(format string, v ...interface{})
- func GetLogger() *zerolog.Logger
- func Info(sender string, connectionID string, format string, v ...interface{})
- func InfoToConsole(format string, v ...interface{})
- func InitJournalDLogger(level zerolog.Level)
- func InitLogger(logFilePath string, logMaxSize int, logMaxBackups int, logMaxAge int, ...)
- func InitStdErrLogger(level zerolog.Level)
- func Log(level LogLevel, sender string, connectionID string, format string, ...)
- func NewStructuredLogger(logger *zerolog.Logger) func(next http.Handler) http.Handler
- func RotateLogFile() error
- func TransferLog(operation string, path string, elapsed int64, size int64, user string, ...)
- func Warn(sender string, connectionID string, format string, v ...interface{})
- func WarnToConsole(format string, v ...interface{})
- type LogLevel
- type StructuredLogger
- type StructuredLoggerEntry
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 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 ¶
EnableConsoleLogger enables the console logger
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 InitJournalDLogger ¶ added in v1.2.0
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
InitStdErrLogger configures the logger to write to stderr
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 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 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