Skip to content

Commit

Permalink
Update log plugin to have log levels.
Browse files Browse the repository at this point in the history
  • Loading branch information
leaanthony committed Sep 12, 2023
1 parent ea3509d commit 8c72746
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 2 deletions.
15 changes: 13 additions & 2 deletions v3/plugins/log/plugin.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,23 +18,29 @@ type Config struct {
// Logger is the logger to use. If not set, a default logger will be used.
Logger *slog.Logger

// LogLevel defines the log level of the logger.
LogLevel slog.Level

// Handles errors that occur when writing to the log
ErrorHandler func(err error)
}

type Plugin struct {
config *Config
app *application.App
level slog.LevelVar
}

func NewPluginWithConfig(config *Config) *Plugin {
if config.Logger == nil {
config.Logger = application.DefaultLogger()
config.Logger = application.DefaultLogger(config.LogLevel)
}

return &Plugin{
result := &Plugin{
config: config,
}
result.level.Set(config.LogLevel)
return result
}

func NewPlugin() *Plugin {
Expand Down Expand Up @@ -62,6 +68,7 @@ func (p *Plugin) CallableByJS() []string {
"Info",
"Warning",
"Error",
"SetLogLevel",
}
}

Expand Down Expand Up @@ -90,3 +97,7 @@ func (p *Plugin) Warning(message string, args ...any) {
func (p *Plugin) Error(message string, args ...any) {
p.config.Logger.Error(message, args...)
}

func (p *Plugin) SetLogLevel(level slog.Level) {
p.level.Set(level)
}
15 changes: 15 additions & 0 deletions v3/plugins/log/plugin.js
Original file line number Diff line number Diff line change
Expand Up @@ -42,3 +42,18 @@ function Warning(input, ...args) {
function Error(input, ...args) {
return wails.CallByID(878590242, input, ...args);
}

const LevelDebug = -4
const LevelInfo = 0
const LevelWarn = 4
const LevelError = 8


/**
* Set Log level
* @param level {LogLevel} - The log level to set.
* @returns {Promise<void|Error>}
*/
function SetLogLevel(level) {
return wails.CallByID(2758810652, level);
}

0 comments on commit 8c72746

Please sign in to comment.