From 6eb89f61b390e56219b057ccbb9f7442d4aee40e Mon Sep 17 00:00:00 2001 From: Lea Anthony Date: Thu, 8 Oct 2020 07:39:01 +1100 Subject: [PATCH] Add Log to Go runtime --- v2/internal/runtime/goruntime/log.go | 50 ++++++++++++++++++++++++ v2/internal/runtime/goruntime/runtime.go | 2 + 2 files changed, 52 insertions(+) create mode 100644 v2/internal/runtime/goruntime/log.go diff --git a/v2/internal/runtime/goruntime/log.go b/v2/internal/runtime/goruntime/log.go new file mode 100644 index 00000000..85e72244 --- /dev/null +++ b/v2/internal/runtime/goruntime/log.go @@ -0,0 +1,50 @@ +package goruntime + +import ( + "github.com/wailsapp/wails/v2/internal/servicebus" +) + +// Log defines all Log related operations +type Log interface { + Debug(message string) + Info(message string) + Warning(message string) + Error(message string) + Fatal(message string) +} + +type log struct { + bus *servicebus.ServiceBus +} + +// newLog creates a new Log struct +func newLog(bus *servicebus.ServiceBus) Log { + return &log{ + bus: bus, + } +} + +// Debug prints a Debug level message +func (r *log) Debug(message string) { + r.bus.Publish("log:debug", message) +} + +// Info prints a Info level message +func (r *log) Info(message string) { + r.bus.Publish("log:info", message) +} + +// Warning prints a Warning level message +func (r *log) Warning(message string) { + r.bus.Publish("log:warning", message) +} + +// Error prints a Error level message +func (r *log) Error(message string) { + r.bus.Publish("log:error", message) +} + +// Fatal prints a Fatal level message +func (r *log) Fatal(message string) { + r.bus.Publish("log:fatal", message) +} diff --git a/v2/internal/runtime/goruntime/runtime.go b/v2/internal/runtime/goruntime/runtime.go index 1d044ac9..42ce1f16 100644 --- a/v2/internal/runtime/goruntime/runtime.go +++ b/v2/internal/runtime/goruntime/runtime.go @@ -9,6 +9,7 @@ type Runtime struct { Window Window Dialog Dialog System System + Log Log bus *servicebus.ServiceBus } @@ -20,6 +21,7 @@ func New(serviceBus *servicebus.ServiceBus) *Runtime { Window: newWindow(serviceBus), Dialog: newDialog(serviceBus), System: newSystem(serviceBus), + Log: newLog(serviceBus), bus: serviceBus, } }