Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support for production log levels #1555

Merged
merged 2 commits into from
Jul 14, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 1 addition & 6 deletions v2/internal/appng/app_production.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ import (
"github.com/wailsapp/wails/v2/internal/frontend/runtime"
"github.com/wailsapp/wails/v2/internal/logger"
"github.com/wailsapp/wails/v2/internal/menumanager"
pkgLog "github.com/wailsapp/wails/v2/pkg/logger"
"github.com/wailsapp/wails/v2/pkg/options"
)

Expand Down Expand Up @@ -61,11 +60,7 @@ func CreateApp(appoptions *options.App) (*App, error) {

// Set up logger
myLogger := logger.New(appoptions.Logger)
myLogger.SetLogLevel(appoptions.LogLevel)

if !IsDebug() {
myLogger.SetLogLevel(pkgLog.ERROR)
}
myLogger.SetLogLevel(appoptions.LogLevelProduction)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Doesn't this change the log level always to the production one, even when using '--debug' build?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah, yeah, nice catch. It should be using the standard level defined for that else this ☝️

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pushed fix to master. Thanks for picking that up!

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Awesome thanks 🚀

ctx = context.WithValue(ctx, "logger", myLogger)

// Preflight Checks
Expand Down
9 changes: 5 additions & 4 deletions v2/pkg/options/default.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,11 @@ import (

// Default options for creating the App
var Default = &App{
Width: 1024,
Height: 768,
Logger: logger.NewDefaultLogger(),
LogLevel: logger.INFO,
Width: 1024,
Height: 768,
Logger: logger.NewDefaultLogger(),
LogLevel: logger.INFO,
LogLevelProduction: logger.ERROR,
}

var defaultMacMenu = menu.NewMenuFromItems(
Expand Down
25 changes: 13 additions & 12 deletions v2/pkg/options/options.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,18 +43,19 @@ type App struct {
AlwaysOnTop bool
BackgroundColour *RGBA
// RGBA is deprecated. Please use BackgroundColour
RGBA *RGBA
Assets fs.FS
AssetsHandler http.Handler
Menu *menu.Menu
Logger logger.Logger `json:"-"`
LogLevel logger.LogLevel
OnStartup func(ctx context.Context) `json:"-"`
OnDomReady func(ctx context.Context) `json:"-"`
OnShutdown func(ctx context.Context) `json:"-"`
OnBeforeClose func(ctx context.Context) (prevent bool) `json:"-"`
Bind []interface{}
WindowStartState WindowStartState
RGBA *RGBA
Assets fs.FS
AssetsHandler http.Handler
Menu *menu.Menu
Logger logger.Logger `json:"-"`
LogLevel logger.LogLevel
LogLevelProduction logger.LogLevel
OnStartup func(ctx context.Context) `json:"-"`
OnDomReady func(ctx context.Context) `json:"-"`
OnShutdown func(ctx context.Context) `json:"-"`
OnBeforeClose func(ctx context.Context) (prevent bool) `json:"-"`
Bind []interface{}
WindowStartState WindowStartState

//ContextMenus []*menu.ContextMenu
//TrayMenus []*menu.TrayMenu
Expand Down
59 changes: 35 additions & 24 deletions website/docs/reference/options.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -15,30 +15,31 @@ import "github.com/wailsapp/wails/v2/pkg/options"
func main() {

err := wails.Run(&options.App{
Title: "Menus Demo",
Width: 800,
Height: 600,
DisableResize: false,
Fullscreen: false,
Frameless: true,
MinWidth: 400,
MinHeight: 400,
MaxWidth: 1280,
MaxHeight: 1024,
StartHidden: false,
HideWindowOnClose: false,
BackgroundColour: &options.RGBA{R: 0, G: 0, B: 0, A: 255},
AlwaysOnTop: false,
Assets: assets,
AssetsHandler: assetsHandler,
Menu: app.applicationMenu(),
Logger: nil,
LogLevel: logger.DEBUG,
OnStartup: app.startup,
OnDomReady: app.domready,
OnShutdown: app.shutdown,
OnBeforeClose: app.beforeClose,
WindowStartState: options.Maximised,
Title: "Menus Demo",
Width: 800,
Height: 600,
DisableResize: false,
Fullscreen: false,
Frameless: true,
MinWidth: 400,
MinHeight: 400,
MaxWidth: 1280,
MaxHeight: 1024,
StartHidden: false,
HideWindowOnClose: false,
BackgroundColour: &options.RGBA{R: 0, G: 0, B: 0, A: 255},
AlwaysOnTop: false,
Assets: assets,
AssetsHandler: assetsHandler,
Menu: app.applicationMenu(),
Logger: nil,
LogLevel: logger.DEBUG,
LogLevelProduction: logger.ERROR,
OnStartup: app.startup,
OnDomReady: app.domready,
OnShutdown: app.shutdown,
OnBeforeClose: app.beforeClose,
WindowStartState: options.Maximised,
Bind: []interface{}{
app,
},
Expand Down Expand Up @@ -286,6 +287,16 @@ Default: `Info` in dev mode, `Error` in production mode

The default log level. More details about logging in the [Log Reference](../reference/runtime/log.mdx).

### LogLevelProduction

Name: LogLevelProduction

Type: logger.LogLevel

Default: `Error`

The default log level for production builds. More details about logging in the [Log Reference](../reference/runtime/log.mdx).

### OnStartup

Name: OnStartup
Expand Down