Darien Raymond 8 роки тому
батько
коміт
4fa3c70429
2 змінених файлів з 17 додано та 41 видалено
  1. 2 2
      app/log/internal/log_entry.go
  2. 15 39
      app/log/log.go

+ 2 - 2
app/log/internal/log_entry.go

@@ -13,11 +13,11 @@ type LogEntry interface {
 
 type ErrorLog struct {
 	Prefix string
-	Values []interface{}
+	Error  error
 }
 
 func (v *ErrorLog) String() string {
-	return v.Prefix + serial.Concat(v.Values...)
+	return v.Prefix + v.Error.Error()
 }
 
 type AccessLog struct {

+ 15 - 39
app/log/log.go

@@ -51,54 +51,30 @@ func InitErrorLogger(file string) error {
 	return nil
 }
 
-// writeDebug outputs a debug log with given format and optional arguments.
-func writeDebug(val ...interface{}) {
-	debugLogger.Log(&internal.ErrorLog{
-		Prefix: "[Debug]",
-		Values: val,
-	})
-}
-
-// writeInfo outputs an info log with given format and optional arguments.
-func writeInfo(val ...interface{}) {
-	infoLogger.Log(&internal.ErrorLog{
-		Prefix: "[Info]",
-		Values: val,
-	})
-}
-
-// writeWarning outputs a warning log with given format and optional arguments.
-func writeWarning(val ...interface{}) {
-	warningLogger.Log(&internal.ErrorLog{
-		Prefix: "[Warning]",
-		Values: val,
-	})
-}
-
-// writeError outputs an error log with given format and optional arguments.
-func writeError(val ...interface{}) {
-	errorLogger.Log(&internal.ErrorLog{
-		Prefix: "[Error]",
-		Values: val,
-	})
-}
-
-func Trace(err error) {
-	s := errors.GetSeverity(err)
+func getLoggerAndPrefix(s errors.Severity) (internal.LogWriter, string) {
 	switch s {
 	case errors.SeverityDebug:
-		writeDebug(err)
+		return debugLogger, "[Debug]"
 	case errors.SeverityInfo:
-		writeInfo(err)
+		return infoLogger, "[Info]"
 	case errors.SeverityWarning:
-		writeWarning(err)
+		return infoLogger, "[Warning]"
 	case errors.SeverityError:
-		writeError(err)
+		return errorLogger, "[Error]"
 	default:
-		writeInfo(err)
+		return infoLogger, "[Info]"
 	}
 }
 
+// Trace logs an error message based on its severity.
+func Trace(err error) {
+	logger, prefix := getLoggerAndPrefix(errors.GetSeverity(err))
+	logger.Log(&internal.ErrorLog{
+		Prefix: prefix,
+		Error:  err,
+	})
+}
+
 type Instance struct {
 	config *Config
 }