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, connectionID, format string, v ...any)
- func DebugToConsole(format string, v ...any)
- func DisableLogger()
- func EnableConsoleLogger(level zerolog.Level)
- func Error(sender, connectionID, format string, v ...any)
- func ErrorToConsole(format string, v ...any)
- func GetLogger() *zerolog.Logger
- func Info(sender, connectionID, format string, v ...any)
- func InfoToConsole(format string, v ...any)
- 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, v ...any)
- func NewStructuredLogger(logger *zerolog.Logger) func(next http.Handler) http.Handler
- func RotateLogFile() error
- func SetLogTime(utc bool)
- func TransferLog(operation, path string, elapsed int64, size int64, ...)
- func Warn(sender, connectionID, format string, v ...any)
- func WarnToConsole(format string, v ...any)
- type HCLogAdapter
- func (l *HCLogAdapter) Debug(msg string, args ...any)
- func (l *HCLogAdapter) Error(msg string, args ...any)
- func (l *HCLogAdapter) Info(msg string, args ...any)
- func (l *HCLogAdapter) Log(level hclog.Level, msg string, args ...any)
- func (l *HCLogAdapter) Named(name string) hclog.Logger
- func (l *HCLogAdapter) StandardLogger(_ *hclog.StandardLoggerOptions) *log.Logger
- func (l *HCLogAdapter) StandardWriter(_ *hclog.StandardLoggerOptions) io.Writer
- func (l *HCLogAdapter) Trace(msg string, args ...any)
- func (l *HCLogAdapter) Warn(msg string, args ...any)
- func (l *HCLogAdapter) With(args ...any) hclog.Logger
- type LegoAdapter
- type LeveledLogger
- func (l *LeveledLogger) Debug(msg string, keysAndValues ...any)
- func (l *LeveledLogger) Error(msg string, keysAndValues ...any)
- func (l *LeveledLogger) Info(msg string, keysAndValues ...any)
- func (l *LeveledLogger) Panic(msg string, keysAndValues ...any)
- func (l *LeveledLogger) Warn(msg string, keysAndValues ...any)
- func (l *LeveledLogger) With(keysAndValues ...any) ftpserverlog.Logger
- type LogLevel
- type MailAdapter
- type StdLoggerWrapper
- 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, localAddr, remoteAddr string, elapsed 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 ¶
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 ¶
ErrorToConsole logs at error level to stdout
func InfoToConsole ¶
InfoToConsole logs at info level to stdout
func InitJournalDLogger ¶
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 ¶
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, path string, elapsed int64, size int64, user, connectionID, protocol, localAddr, remoteAddr, ftpMode string, err error, )
TransferLog logs uploads or downloads
func WarnToConsole ¶
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(_ *hclog.StandardLoggerOptions) *log.Logger
StandardLogger returns a value that conforms to the stdlib log.Logger interface
func (*HCLogAdapter) StandardWriter ¶
func (l *HCLogAdapter) StandardWriter(_ *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 ¶
type LegoAdapter struct {
LogToConsole bool
}
LegoAdapter is an adapter for lego.StdLogger
func (*LegoAdapter) Fatal ¶
func (l *LegoAdapter) Fatal(args ...any)
Fatal emits a log at Error level
func (*LegoAdapter) Fatalf ¶
func (l *LegoAdapter) Fatalf(format string, args ...any)
Fatalf emits a log at Error level
func (*LegoAdapter) Fatalln ¶
func (l *LegoAdapter) Fatalln(args ...any)
Fatalln is the same as Fatal
func (*LegoAdapter) Print ¶
func (l *LegoAdapter) Print(args ...any)
Print emits a log at Info level
func (*LegoAdapter) Printf ¶
func (l *LegoAdapter) Printf(format string, args ...any)
Printf emits a log at Info level
func (*LegoAdapter) Println ¶
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 ¶
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 MailAdapter ¶ added in v2.5.2
type MailAdapter struct {
ConnectionID string
}
MailAdapter is an adapter for mail.Logger
func (*MailAdapter) Debugf ¶ added in v2.5.2
func (l *MailAdapter) Debugf(logMsg log.Log)
Debugf emits a log at Debug level
func (*MailAdapter) Errorf ¶ added in v2.5.2
func (l *MailAdapter) Errorf(logMsg log.Log)
Errorf emits a log at Error level
func (*MailAdapter) Infof ¶ added in v2.5.2
func (l *MailAdapter) Infof(logMsg log.Log)
Infof emits a log at Info level
func (*MailAdapter) Warnf ¶ added in v2.5.2
func (l *MailAdapter) Warnf(logMsg log.Log)
Warnf emits a log at Warn level
type StdLoggerWrapper ¶
type StdLoggerWrapper struct {
Sender string
}
StdLoggerWrapper is a wrapper for standard logger compatibility
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 any, stack []byte)
Panic logs panics