Set default logging level and allow event bus configuration
This commit is contained in:
parent
eb06bdd19a
commit
64aeaad23a
22
lib.go
22
lib.go
|
@ -1,4 +1,5 @@
|
||||||
//package cwtch
|
//package cwtch
|
||||||
|
|
||||||
package main
|
package main
|
||||||
|
|
||||||
import "C"
|
import "C"
|
||||||
|
@ -37,8 +38,8 @@ func c_StartCwtch(dir_c *C.char, len C.int, tor_c *C.char, torLen C.int) {
|
||||||
}
|
}
|
||||||
|
|
||||||
func StartCwtch(appDir string, torPath string) {
|
func StartCwtch(appDir string, torPath string) {
|
||||||
log.SetLevel(log.LevelDebug)
|
log.SetLevel(log.LevelInfo)
|
||||||
//log.ExcludeFromPattern("service.go")
|
log.ExcludeFromPattern("service.go")
|
||||||
|
|
||||||
utils.InitGlobalSettingsFile(appDir, "be gay do crime")
|
utils.InitGlobalSettingsFile(appDir, "be gay do crime")
|
||||||
|
|
||||||
|
@ -68,6 +69,7 @@ func StartCwtch(appDir string, torPath string) {
|
||||||
acnQueue = event.NewQueue()
|
acnQueue = event.NewQueue()
|
||||||
newApp.GetPrimaryBus().Subscribe(event.ACNStatus, acnQueue)
|
newApp.GetPrimaryBus().Subscribe(event.ACNStatus, acnQueue)
|
||||||
newApp.GetPrimaryBus().Subscribe(utils.UpdateGlobalSettings, acnQueue)
|
newApp.GetPrimaryBus().Subscribe(utils.UpdateGlobalSettings, acnQueue)
|
||||||
|
newApp.GetPrimaryBus().Subscribe(utils.SetLoggingLevel, acnQueue)
|
||||||
|
|
||||||
eventHandler = utils.NewEventHandler(newApp)
|
eventHandler = utils.NewEventHandler(newApp)
|
||||||
|
|
||||||
|
@ -134,6 +136,22 @@ func SendAppEvent(eventJson string) {
|
||||||
}
|
}
|
||||||
log.Debugf("New Settings %v", globalSettings)
|
log.Debugf("New Settings %v", globalSettings)
|
||||||
utils.WriteGlobalSettings(globalSettings)
|
utils.WriteGlobalSettings(globalSettings)
|
||||||
|
case utils.SetLoggingLevel:
|
||||||
|
_, warn := new_event.Data[utils.Warn]
|
||||||
|
_, error := new_event.Data[utils.Error]
|
||||||
|
_, debug := new_event.Data[utils.Debug]
|
||||||
|
_, info := new_event.Data[utils.Info]
|
||||||
|
// Assign logging level in priority order. The highest logging level wins in the
|
||||||
|
// event of multiple fields.
|
||||||
|
if info {
|
||||||
|
log.SetLevel(log.LevelInfo)
|
||||||
|
} else if warn {
|
||||||
|
log.SetLevel(log.LevelWarn)
|
||||||
|
} else if error {
|
||||||
|
log.SetLevel(log.LevelError)
|
||||||
|
} else if debug {
|
||||||
|
log.SetLevel(log.LevelDebug)
|
||||||
|
}
|
||||||
default: // do nothing
|
default: // do nothing
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,8 +1,8 @@
|
||||||
package utils
|
package utils
|
||||||
|
|
||||||
type Contact struct {
|
type Contact struct {
|
||||||
Name string `json:"name"`
|
Name string `json:"name"`
|
||||||
Onion string `json:"onion"`
|
Onion string `json:"onion"`
|
||||||
Status string `json:"status"`
|
Status string `json:"status"`
|
||||||
Picture string `json:"picture"`
|
Picture string `json:"picture"`
|
||||||
}
|
}
|
||||||
|
|
|
@ -106,7 +106,7 @@ func (eh *EventHandler) handleAppBusEvent(e *event.Event) string {
|
||||||
}
|
}
|
||||||
cpicPath := GetPicturePath(cpic)
|
cpicPath := GetPicturePath(cpic)
|
||||||
contactInfo := profile.GetContact(contact)
|
contactInfo := profile.GetContact(contact)
|
||||||
contacts = append(contacts, Contact{Name: contactInfo.Name, Onion: contactInfo.Onion, Status: contactInfo.State, Picture: cpicPath,})
|
contacts = append(contacts, Contact{Name: contactInfo.Name, Onion: contactInfo.Onion, Status: contactInfo.State, Picture: cpicPath})
|
||||||
}
|
}
|
||||||
|
|
||||||
bytes, _ := json.Marshal(contacts)
|
bytes, _ := json.Marshal(contacts)
|
||||||
|
|
|
@ -0,0 +1,18 @@
|
||||||
|
package utils
|
||||||
|
|
||||||
|
import "cwtch.im/cwtch/event"
|
||||||
|
|
||||||
|
// An event to set the logging level dynamically from the UI
|
||||||
|
const (
|
||||||
|
SetLoggingLevel = event.Type("SetLoggingLevel")
|
||||||
|
)
|
||||||
|
|
||||||
|
// Logging Levels as Event Fields. Note: Unlike most event we don't cae about
|
||||||
|
// the *value* of the field, only the presence. If more than one of these fields is
|
||||||
|
// present in a single SetLoggingLevel event then the highest logging level is used. INFO < WARN < ERROR < DEBUG
|
||||||
|
const (
|
||||||
|
Warn = event.Field("Warn")
|
||||||
|
Error = event.Field("Error")
|
||||||
|
Debug = event.Field("Debug")
|
||||||
|
Info = event.Field("Info")
|
||||||
|
)
|
Loading…
Reference in New Issue