5
0
mirror of https://github.com/wailsapp/wails.git synced 2025-05-02 04:59:38 +08:00
wails/v2/pkg/logger/logger.go
Atterpac d824318a66
fix dev mode logging bug (#3972)
changelog.md

retain env support

actually fix the issue
2025-01-23 11:12:18 +00:00

73 lines
1.2 KiB
Go

package logger
import (
"fmt"
"strings"
)
// LogLevel is an unsigned 8bit int
type LogLevel uint8
const (
// TRACE level
TRACE LogLevel = 1
// DEBUG level logging
DEBUG LogLevel = 2
// INFO level logging
INFO LogLevel = 3
// WARNING level logging
WARNING LogLevel = 4
// ERROR level logging
ERROR LogLevel = 5
)
var logLevelMap = map[string]LogLevel{
"trace": TRACE,
"debug": DEBUG,
"info": INFO,
"warning": WARNING,
"error": ERROR,
}
func StringToLogLevel(input string) (LogLevel, error) {
result, ok := logLevelMap[strings.ToLower(input)]
if !ok {
return ERROR, fmt.Errorf("invalid log level: %s", input)
}
return result, nil
}
// String returns the string representation of the LogLevel
func (l LogLevel) String() string {
switch l {
case TRACE:
return "trace"
case DEBUG:
return "debug"
case INFO:
return "info"
case WARNING:
return "warning"
case ERROR:
return "error"
default:
return "debug"
}
}
// Logger specifies the methods required to attach
// a logger to a Wails application
type Logger interface {
Print(message string)
Trace(message string)
Debug(message string)
Info(message string)
Warning(message string)
Error(message string)
Fatal(message string)
}