Skip to content

Commit

Permalink
fix dev mode logging bug
Browse files Browse the repository at this point in the history
changelog.md

retain env support

actually fix the issue
  • Loading branch information
atterpac committed Dec 30, 2024
1 parent 82fd9de commit 5175127
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 11 deletions.
21 changes: 10 additions & 11 deletions v2/internal/app/app_dev.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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)
}
}
}

Expand Down Expand Up @@ -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")
Expand Down
18 changes: 18 additions & 0 deletions v2/pkg/logger/logger.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
1 change: 1 addition & 0 deletions website/src/pages/changelog.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -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 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
- Fixed example for macOS menu by @takuyahara in [PR](https://github.com/wailsapp/wails/pull/3847)
Expand Down

0 comments on commit 5175127

Please sign in to comment.