go-mail/log/log.go
Winni Neessen 0189acf1e4
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.
2023-08-15 11:59:16 +02:00

53 lines
1.3 KiB
Go

// SPDX-FileCopyrightText: Copyright (c) 2022-2023 The go-mail Authors
//
// SPDX-License-Identifier: MIT
// Package log implements a logger interface that can be used within the go-mail package
package log
const (
DirServerToClient Direction = iota // Server to Client communication
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 {
Direction Direction
Format string
Messages []interface{}
}
// Logger is the log interface for go-mail
type Logger interface {
Debugf(Log)
Infof(Log)
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
}