From 0189acf1e45f90afe7c6948b598f36d89a04f18a Mon Sep 17 00:00:00 2001 From: Winni Neessen Date: Tue, 15 Aug 2023 11:59:16 +0200 Subject: [PATCH] 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. --- log/log.go | 23 +++++++++++++++++++++++ log/stdlog.go | 23 ----------------------- 2 files changed, 23 insertions(+), 23 deletions(-) diff --git a/log/log.go b/log/log.go index 8e95bfa..8ec5205 100644 --- a/log/log.go +++ b/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 +} diff --git a/log/stdlog.go b/log/stdlog.go index 65ae6e1..2ac2430 100644 --- a/log/stdlog.go +++ b/log/stdlog.go @@ -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 -}