mirror of
https://github.com/wneessen/go-mail.git
synced 2024-11-25 15:10:48 +01:00
Refactor log level and direction function to separate file
Moved Level constants and directionPrefix() function from log/stdlog.go to log/log.go. This change improves the organization of the code by grouping log level constants and related functions in the same file. Furthermore, this removes redundancy and ensures consistency of log level across different files.
This commit is contained in:
parent
9ee864316a
commit
0189acf1e4
2 changed files with 23 additions and 23 deletions
23
log/log.go
23
log/log.go
|
@ -10,9 +10,23 @@ const (
|
|||
DirClientToServer // Client to Server communication
|
||||
)
|
||||
|
||||
const (
|
||||
// LevelError is the Level for only ERROR log messages
|
||||
LevelError Level = iota
|
||||
// LevelWarn is the Level for WARN and higher log messages
|
||||
LevelWarn
|
||||
// LevelInfo is the Level for INFO and higher log messages
|
||||
LevelInfo
|
||||
// LevelDebug is the Level for DEBUG and higher log messages
|
||||
LevelDebug
|
||||
)
|
||||
|
||||
// Direction is a type wrapper for the direction a debug log message goes
|
||||
type Direction int
|
||||
|
||||
// Level is a type wrapper for an int
|
||||
type Level int
|
||||
|
||||
// Log represents a log message type that holds a log Direction, a Format string
|
||||
// and a slice of Messages
|
||||
type Log struct {
|
||||
|
@ -28,3 +42,12 @@ type Logger interface {
|
|||
Warnf(Log)
|
||||
Errorf(Log)
|
||||
}
|
||||
|
||||
// directionPrefix will return a prefix string depending on the Direction.
|
||||
func (l Log) directionPrefix() string {
|
||||
p := "C <-- S:"
|
||||
if l.Direction == DirClientToServer {
|
||||
p = "C --> S:"
|
||||
}
|
||||
return p
|
||||
}
|
||||
|
|
|
@ -10,9 +10,6 @@ import (
|
|||
"log"
|
||||
)
|
||||
|
||||
// Level is a type wrapper for an int
|
||||
type Level int
|
||||
|
||||
// Stdlog is the default logger that satisfies the Logger interface
|
||||
type Stdlog struct {
|
||||
l Level
|
||||
|
@ -22,17 +19,6 @@ type Stdlog struct {
|
|||
debug *log.Logger
|
||||
}
|
||||
|
||||
const (
|
||||
// LevelError is the Level for only ERROR log messages
|
||||
LevelError Level = iota
|
||||
// LevelWarn is the Level for WARN and higher log messages
|
||||
LevelWarn
|
||||
// LevelInfo is the Level for INFO and higher log messages
|
||||
LevelInfo
|
||||
// LevelDebug is the Level for DEBUG and higher log messages
|
||||
LevelDebug
|
||||
)
|
||||
|
||||
// CallDepth is the call depth value for the log.Logger's Output method
|
||||
// This defaults to 2 and is only here for better readablity of the code
|
||||
const CallDepth = 2
|
||||
|
@ -80,12 +66,3 @@ func (l *Stdlog) Errorf(lo Log) {
|
|||
_ = l.err.Output(CallDepth, fmt.Sprintf(f, lo.Messages...))
|
||||
}
|
||||
}
|
||||
|
||||
// directionPrefix will return a prefix string depending on the Direction.
|
||||
func (l Log) directionPrefix() string {
|
||||
p := "C <-- S:"
|
||||
if l.Direction == DirClientToServer {
|
||||
p = "C --> S:"
|
||||
}
|
||||
return p
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue