mirror of
https://github.com/taigrr/wails.git
synced 2026-04-02 05:08:54 -07:00
Add Log to Go runtime
This commit is contained in:
50
v2/internal/runtime/goruntime/log.go
Normal file
50
v2/internal/runtime/goruntime/log.go
Normal file
@@ -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)
|
||||
}
|
||||
@@ -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,
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user