5
0
mirror of https://github.com/wailsapp/wails.git synced 2025-05-01 22:42:37 +08:00

fix dev mode logging bug (#3972)

changelog.md

retain env support

actually fix the issue
This commit is contained in:
Atterpac 2025-01-23 04:12:18 -07:00 committed by GitHub
parent 00be6f24d2
commit d824318a66
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
3 changed files with 29 additions and 11 deletions

View File

@ -75,7 +75,7 @@ func CreateApp(appoptions *options.App) (*App, error) {
loglevel := os.Getenv("loglevel")
if loglevel == "" {
loglevelFlag = devFlags.String("loglevel", "debug", "Loglevel to use - Trace, Debug, Info, Warning, Error")
loglevelFlag = devFlags.String("loglevel", appoptions.LogLevel.String(), "Loglevel to use - Trace, Debug, Info, Warning, Error")
}
// If we weren't given the assetdir in the environment variables
@ -91,8 +91,15 @@ func CreateApp(appoptions *options.App) (*App, error) {
if frontendDevServerURLFlag != nil {
frontendDevServerURL = *frontendDevServerURLFlag
}
if loglevelFlag != nil {
loglevel = *loglevelFlag
// Only override LogLevel if the flag was explicitly set
if loglevelFlag != nil && devFlags.Lookup("loglevel").Value.String() != appoptions.LogLevel.String() {
loggerLevel, err := pkglogger.StringToLogLevel(*loglevelFlag)
if err != nil {
return nil, err
}
if loggerLevel != appoptions.LogLevel {
myLogger.SetLogLevel(loggerLevel)
}
}
}
@ -169,14 +176,6 @@ func CreateApp(appoptions *options.App) (*App, error) {
ctx = context.WithValue(ctx, "devserver", devServer)
}
if loglevel != "" {
level, err := pkglogger.StringToLogLevel(loglevel)
if err != nil {
return nil, err
}
myLogger.SetLogLevel(level)
}
// Attach logger to context
ctx = context.WithValue(ctx, "logger", myLogger)
ctx = context.WithValue(ctx, "buildtype", "dev")

View File

@ -41,6 +41,24 @@ func StringToLogLevel(input string) (LogLevel, error) {
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 {

View File

@ -21,6 +21,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
- Added option to set window class name on Windows. Added in [PR](https://github.com/wailsapp/wails/pull/3828) by @APshenkin
### Fixed
- Fixed dev mode logging bug by @attperac in [#3972](https://wailsapp/wails/pull/3972)
- Fixed `reloaddirs` wails.json config options by @atterpac in [#4005](https//github.com/wailsapp/wails/pull/4005)
- Fixed cross compilation failed with CGO [PR](https://github.com/wailsapp/wails/pull/3795) by [@fcying](https://github.com/fcying)
- Using go-webview2 v0.1.17 to fix native webview2loader issue, by @leaanthony