mirror of
https://github.com/wailsapp/wails.git
synced 2025-05-03 06:20:48 +08:00
Add support for production log levels (#1555)
This commit is contained in:
parent
77db50a76a
commit
f068c33dcf
@ -13,7 +13,6 @@ import (
|
|||||||
"github.com/wailsapp/wails/v2/internal/frontend/runtime"
|
"github.com/wailsapp/wails/v2/internal/frontend/runtime"
|
||||||
"github.com/wailsapp/wails/v2/internal/logger"
|
"github.com/wailsapp/wails/v2/internal/logger"
|
||||||
"github.com/wailsapp/wails/v2/internal/menumanager"
|
"github.com/wailsapp/wails/v2/internal/menumanager"
|
||||||
pkgLog "github.com/wailsapp/wails/v2/pkg/logger"
|
|
||||||
"github.com/wailsapp/wails/v2/pkg/options"
|
"github.com/wailsapp/wails/v2/pkg/options"
|
||||||
)
|
)
|
||||||
|
|
||||||
@ -61,11 +60,7 @@ func CreateApp(appoptions *options.App) (*App, error) {
|
|||||||
|
|
||||||
// Set up logger
|
// Set up logger
|
||||||
myLogger := logger.New(appoptions.Logger)
|
myLogger := logger.New(appoptions.Logger)
|
||||||
myLogger.SetLogLevel(appoptions.LogLevel)
|
myLogger.SetLogLevel(appoptions.LogLevelProduction)
|
||||||
|
|
||||||
if !IsDebug() {
|
|
||||||
myLogger.SetLogLevel(pkgLog.ERROR)
|
|
||||||
}
|
|
||||||
ctx = context.WithValue(ctx, "logger", myLogger)
|
ctx = context.WithValue(ctx, "logger", myLogger)
|
||||||
|
|
||||||
// Preflight Checks
|
// Preflight Checks
|
||||||
|
@ -7,10 +7,11 @@ import (
|
|||||||
|
|
||||||
// Default options for creating the App
|
// Default options for creating the App
|
||||||
var Default = &App{
|
var Default = &App{
|
||||||
Width: 1024,
|
Width: 1024,
|
||||||
Height: 768,
|
Height: 768,
|
||||||
Logger: logger.NewDefaultLogger(),
|
Logger: logger.NewDefaultLogger(),
|
||||||
LogLevel: logger.INFO,
|
LogLevel: logger.INFO,
|
||||||
|
LogLevelProduction: logger.ERROR,
|
||||||
}
|
}
|
||||||
|
|
||||||
var defaultMacMenu = menu.NewMenuFromItems(
|
var defaultMacMenu = menu.NewMenuFromItems(
|
||||||
|
@ -43,18 +43,19 @@ type App struct {
|
|||||||
AlwaysOnTop bool
|
AlwaysOnTop bool
|
||||||
BackgroundColour *RGBA
|
BackgroundColour *RGBA
|
||||||
// RGBA is deprecated. Please use BackgroundColour
|
// RGBA is deprecated. Please use BackgroundColour
|
||||||
RGBA *RGBA
|
RGBA *RGBA
|
||||||
Assets fs.FS
|
Assets fs.FS
|
||||||
AssetsHandler http.Handler
|
AssetsHandler http.Handler
|
||||||
Menu *menu.Menu
|
Menu *menu.Menu
|
||||||
Logger logger.Logger `json:"-"`
|
Logger logger.Logger `json:"-"`
|
||||||
LogLevel logger.LogLevel
|
LogLevel logger.LogLevel
|
||||||
OnStartup func(ctx context.Context) `json:"-"`
|
LogLevelProduction logger.LogLevel
|
||||||
OnDomReady func(ctx context.Context) `json:"-"`
|
OnStartup func(ctx context.Context) `json:"-"`
|
||||||
OnShutdown func(ctx context.Context) `json:"-"`
|
OnDomReady func(ctx context.Context) `json:"-"`
|
||||||
OnBeforeClose func(ctx context.Context) (prevent bool) `json:"-"`
|
OnShutdown func(ctx context.Context) `json:"-"`
|
||||||
Bind []interface{}
|
OnBeforeClose func(ctx context.Context) (prevent bool) `json:"-"`
|
||||||
WindowStartState WindowStartState
|
Bind []interface{}
|
||||||
|
WindowStartState WindowStartState
|
||||||
|
|
||||||
//ContextMenus []*menu.ContextMenu
|
//ContextMenus []*menu.ContextMenu
|
||||||
//TrayMenus []*menu.TrayMenu
|
//TrayMenus []*menu.TrayMenu
|
||||||
|
@ -15,30 +15,31 @@ import "github.com/wailsapp/wails/v2/pkg/options"
|
|||||||
func main() {
|
func main() {
|
||||||
|
|
||||||
err := wails.Run(&options.App{
|
err := wails.Run(&options.App{
|
||||||
Title: "Menus Demo",
|
Title: "Menus Demo",
|
||||||
Width: 800,
|
Width: 800,
|
||||||
Height: 600,
|
Height: 600,
|
||||||
DisableResize: false,
|
DisableResize: false,
|
||||||
Fullscreen: false,
|
Fullscreen: false,
|
||||||
Frameless: true,
|
Frameless: true,
|
||||||
MinWidth: 400,
|
MinWidth: 400,
|
||||||
MinHeight: 400,
|
MinHeight: 400,
|
||||||
MaxWidth: 1280,
|
MaxWidth: 1280,
|
||||||
MaxHeight: 1024,
|
MaxHeight: 1024,
|
||||||
StartHidden: false,
|
StartHidden: false,
|
||||||
HideWindowOnClose: false,
|
HideWindowOnClose: false,
|
||||||
BackgroundColour: &options.RGBA{R: 0, G: 0, B: 0, A: 255},
|
BackgroundColour: &options.RGBA{R: 0, G: 0, B: 0, A: 255},
|
||||||
AlwaysOnTop: false,
|
AlwaysOnTop: false,
|
||||||
Assets: assets,
|
Assets: assets,
|
||||||
AssetsHandler: assetsHandler,
|
AssetsHandler: assetsHandler,
|
||||||
Menu: app.applicationMenu(),
|
Menu: app.applicationMenu(),
|
||||||
Logger: nil,
|
Logger: nil,
|
||||||
LogLevel: logger.DEBUG,
|
LogLevel: logger.DEBUG,
|
||||||
OnStartup: app.startup,
|
LogLevelProduction: logger.ERROR,
|
||||||
OnDomReady: app.domready,
|
OnStartup: app.startup,
|
||||||
OnShutdown: app.shutdown,
|
OnDomReady: app.domready,
|
||||||
OnBeforeClose: app.beforeClose,
|
OnShutdown: app.shutdown,
|
||||||
WindowStartState: options.Maximised,
|
OnBeforeClose: app.beforeClose,
|
||||||
|
WindowStartState: options.Maximised,
|
||||||
Bind: []interface{}{
|
Bind: []interface{}{
|
||||||
app,
|
app,
|
||||||
},
|
},
|
||||||
@ -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).
|
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
|
### OnStartup
|
||||||
|
|
||||||
Name: OnStartup
|
Name: OnStartup
|
||||||
|
Loading…
Reference in New Issue
Block a user