5
0
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:
Lea Anthony 2022-07-14 21:45:13 +10:00 committed by GitHub
parent 77db50a76a
commit f068c33dcf
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 54 additions and 46 deletions

View File

@ -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"
)
@ -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)
ctx = context.WithValue(ctx, "logger", myLogger)
// Preflight Checks

View File

@ -11,6 +11,7 @@ var Default = &App{
Height: 768,
Logger: logger.NewDefaultLogger(),
LogLevel: logger.INFO,
LogLevelProduction: logger.ERROR,
}
var defaultMacMenu = menu.NewMenuFromItems(

View File

@ -49,6 +49,7 @@ type App struct {
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:"-"`

View File

@ -34,6 +34,7 @@ func main() {
Menu: app.applicationMenu(),
Logger: nil,
LogLevel: logger.DEBUG,
LogLevelProduction: logger.ERROR,
OnStartup: app.startup,
OnDomReady: app.domready,
OnShutdown: app.shutdown,
@ -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