You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@mynewt.apache.org by cc...@apache.org on 2016/04/14 03:29:59 UTC
incubator-mynewt-newt git commit: - Changing log handlers for newtmgr
Repository: incubator-mynewt-newt
Updated Branches:
refs/heads/develop e9050819e -> 9d2dc4adc
- Changing log handlers for newtmgr
Project: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-newt/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-newt/commit/9d2dc4ad
Tree: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-newt/tree/9d2dc4ad
Diff: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-newt/diff/9d2dc4ad
Branch: refs/heads/develop
Commit: 9d2dc4adc74e9312b21b865a673fea9f25fa5dd4
Parents: e905081
Author: Vipul Rahane <vi...@runtime.io>
Authored: Wed Apr 13 12:42:39 2016 -0700
Committer: Vipul Rahane <vi...@runtime.io>
Committed: Wed Apr 13 17:59:21 2016 -0700
----------------------------------------------------------------------
newtmgr/cli/logs.go | 69 +++++++++++++++++++++++++++++++++++++++++--
newtmgr/protocol/logs.go | 12 ++++++--
2 files changed, 76 insertions(+), 5 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/incubator-mynewt-newt/blob/9d2dc4ad/newtmgr/cli/logs.go
----------------------------------------------------------------------
diff --git a/newtmgr/cli/logs.go b/newtmgr/cli/logs.go
index c43fa13..390aa28 100644
--- a/newtmgr/cli/logs.go
+++ b/newtmgr/cli/logs.go
@@ -22,12 +22,64 @@ package cli
import (
"fmt"
+ "github.com/spf13/cobra"
"mynewt.apache.org/newt/newtmgr/config"
"mynewt.apache.org/newt/newtmgr/protocol"
"mynewt.apache.org/newt/newtmgr/transport"
- "github.com/spf13/cobra"
)
+const (
+ DEBUG uint64 = 1
+ INFO uint64 = 2
+ WARN uint64 = 4
+ ERROR uint64 = 8
+ CRITICAL uint64 = 10
+ /* Upto 7 custom loglevels */
+ PERUSER uint64 = 12
+)
+
+const (
+ STREAM_LOG uint64 = 0
+ MEMORY_LOG uint64 = 1
+ STORAGE_LOG uint64 = 2
+)
+
+func LoglevelToString(ll uint64) string {
+ s := ""
+ switch ll {
+ case DEBUG:
+ s = "DEBUG"
+ case INFO:
+ s = "INFO"
+ case WARN:
+ s = "WARN"
+ case ERROR:
+ s = "ERROR"
+ case CRITICAL:
+ s = "CRITICAL"
+ case PERUSER:
+ s = "PERUSER"
+ default:
+ s = "CUSTOM"
+ }
+ return s
+}
+
+func LogTypeToString(lt uint64) string {
+ s := ""
+ switch lt {
+ case STREAM_LOG:
+ s = "STREAM"
+ case MEMORY_LOG:
+ s = "MEMORY"
+ case STORAGE_LOG:
+ s = "STORAGE"
+ default:
+ s = "UNDEFINED"
+ }
+ return s
+}
+
func logsShowCmd(cmd *cobra.Command, args []string) {
cpm, err := config.NewConnProfileMgr()
if err != nil {
@@ -72,8 +124,19 @@ func logsShowCmd(cmd *cobra.Command, args []string) {
if err != nil {
nmUsage(cmd, err)
}
- for i := 0; i < len(decodedResponse.Logs); i++ {
- fmt.Println(decodedResponse.Logs[i])
+
+ for j := 0; j < len(decodedResponse.Logs); j++ {
+
+ fmt.Println("Name:", decodedResponse.Logs[j].Name)
+ fmt.Println("Type:", LogTypeToString(decodedResponse.Logs[j].Type))
+
+ for i := 0; i < len(decodedResponse.Logs[j].Entries); i++ {
+ fmt.Println(fmt.Sprintf("%+v:> %+v usecs :%s: %s",
+ decodedResponse.Logs[j].Entries[i].Index,
+ decodedResponse.Logs[j].Entries[i].Timestamp,
+ LoglevelToString(decodedResponse.Logs[j].Entries[i].Level),
+ decodedResponse.Logs[j].Entries[i].Msg))
+ }
}
}
http://git-wip-us.apache.org/repos/asf/incubator-mynewt-newt/blob/9d2dc4ad/newtmgr/protocol/logs.go
----------------------------------------------------------------------
diff --git a/newtmgr/protocol/logs.go b/newtmgr/protocol/logs.go
index 77417be..9231350 100644
--- a/newtmgr/protocol/logs.go
+++ b/newtmgr/protocol/logs.go
@@ -31,9 +31,17 @@ const (
type LogsShowReq struct {
}
+type LogEntry struct {
+ Timestamp int64 `json:"ts"`
+ Msg string `json:"msg"`
+ Level uint64 `json:"level"`
+ Index uint64 `json:"index"`
+}
+
type LogsShowLog struct {
- Timestamp uint64 `json:"ts"`
- Log string `json:"log"`
+ Name string `json:"name"`
+ Type uint64 `json:"type"`
+ Entries []LogEntry `json:"entries"`
}
type LogsShowRsp struct {