diff --git a/.drone.yml b/.drone.yml index 419c14b..1abeb82 100644 --- a/.drone.yml +++ b/.drone.yml @@ -10,54 +10,54 @@ steps: repo: flutter/libcwtch-go branch: trunk event: [ push, pull_request ] + commands: + - wget https://git.openprivacy.ca/openprivacy/buildfiles/raw/master/tor/tor + - wget https://git.openprivacy.ca/openprivacy/buildfiles/raw/master/tor/torrc + - chmod a+x tor + - go get -u golang.org/x/lint/golint + - go mod vendor + - name: quality + image: golang + when: + repo: flutter/libcwtch-go + branch: trunk + event: [ push, pull_request ] + commands: + - go list ./... | xargs go vet + - go list ./... | xargs golint -set_exit_status + - name: buildLinux + image: openpriv/android-go-mobile:2021 + when: + repo: flutter/libcwtch-go + branch: trunk + event: [ push, pull_request ] commands: - - wget https://git.openprivacy.ca/openprivacy/buildfiles/raw/master/tor/tor - - wget https://git.openprivacy.ca/openprivacy/buildfiles/raw/master/tor/torrc - - chmod a+x tor - - go get -u golang.org/x/lint/golint - - go mod vendor - quality: - image: golang - when: - repo: flutter/libcwtch-go - branch: trunk - event: [ push, pull_request ] - commands: - - go list ./... | xargs go vet - - go list ./... | xargs golint -set_exit_status - build-linux: - image: openpriv/android-go-mobile:2021 - when: - repo: flutter/libcwtch-go - branch: trunk - event: [ push, pull_request ] - commands: - - make linux - build-androiud: - image: openpriv/android-go-mobile:2021 - when: - repo: flutter/libcwtch-go - branch: trunk - event: [ push, pull_request ] - commands: - - make android - notify-email: - image: drillster/drone-email - host: build.openprivacy.ca - port: 25 - skip_verify: true - from: drone@openprivacy.ca - when: - repo: flutter/libcwtch-go - branch: trunk - event: [ push, pull_request ] - status: [ failure ] - notify-gogs: - image: openpriv/drone-gogs - when: - repo: flutter/libcwtch-go - branch: trunk - event: pull_request - status: [ success, changed, failure ] - secrets: [gogs_account_token] - gogs_url: https://git.openprivacy.ca \ No newline at end of file + - make linux + - name: build-androiud + image: openpriv/android-go-mobile:2021 + when: + repo: flutter/libcwtch-go + branch: trunk + event: [ push, pull_request ] + commands: + - make android + - name: notify-email + image: drillster/drone-email + host: build.openprivacy.ca + port: 25 + skip_verify: true + from: drone@openprivacy.ca + when: + repo: flutter/libcwtch-go + branch: trunk + event: [ push, pull_request ] + status: [ failure ] + - name: notify-gogs + image: openpriv/drone-gogs + when: + repo: flutter/libcwtch-go + branch: trunk + event: pull_request + status: [ success, changed, failure ] + secrets: [gogs_account_token] + gogs_url: https://git.openprivacy.ca \ No newline at end of file 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") +)