diff --git a/lib.go b/lib.go index ea0ec31..2aab010 100644 --- a/lib.go +++ b/lib.go @@ -1,4 +1,5 @@ //package cwtch + package main 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) { - log.SetLevel(log.LevelDebug) - //log.ExcludeFromPattern("service.go") + log.SetLevel(log.LevelInfo) + log.ExcludeFromPattern("service.go") utils.InitGlobalSettingsFile(appDir, "be gay do crime") @@ -68,6 +69,7 @@ func StartCwtch(appDir string, torPath string) { acnQueue = event.NewQueue() newApp.GetPrimaryBus().Subscribe(event.ACNStatus, acnQueue) newApp.GetPrimaryBus().Subscribe(utils.UpdateGlobalSettings, acnQueue) + newApp.GetPrimaryBus().Subscribe(utils.SetLoggingLevel, acnQueue) eventHandler = utils.NewEventHandler(newApp) @@ -134,6 +136,22 @@ func SendAppEvent(eventJson string) { } log.Debugf("New Settings %v", 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 } } diff --git a/utils/contacts.go b/utils/contacts.go index 9e88cfd..ddd1f9a 100644 --- a/utils/contacts.go +++ b/utils/contacts.go @@ -1,8 +1,8 @@ package utils type Contact struct { - Name string `json:"name"` - Onion string `json:"onion"` - Status string `json:"status"` - Picture string `json:"picture"` + Name string `json:"name"` + Onion string `json:"onion"` + Status string `json:"status"` + Picture string `json:"picture"` } diff --git a/utils/eventHandler.go b/utils/eventHandler.go index 8c8e92a..45d0318 100644 --- a/utils/eventHandler.go +++ b/utils/eventHandler.go @@ -106,7 +106,7 @@ func (eh *EventHandler) handleAppBusEvent(e *event.Event) string { } cpicPath := GetPicturePath(cpic) 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) diff --git a/utils/logging.go b/utils/logging.go new file mode 100644 index 0000000..8a8d713 --- /dev/null +++ b/utils/logging.go @@ -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") +)