You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@mynewt.apache.org by GitBox <gi...@apache.org> on 2018/05/29 18:48:38 UTC

[GitHub] vrahane closed pull request #80: log handler: add support for type cbor parsing

vrahane closed pull request #80: log handler: add support for type cbor parsing
URL: https://github.com/apache/mynewt-newtmgr/pull/80
 
 
   

This is a PR merged from a forked repository.
As GitHub hides the original diff on merge, it is displayed below for
the sake of provenance:

As this is a foreign pull request (from a fork), the diff is supplied
below (as it won't show otherwise due to GitHub magic):

diff --git a/newtmgr/cli/log.go b/newtmgr/cli/log.go
index 169ba99a..3532c724 100644
--- a/newtmgr/cli/log.go
+++ b/newtmgr/cli/log.go
@@ -89,14 +89,15 @@ func logShowCmd(cmd *cobra.Command, args []string) {
 			return
 		}
 
-		fmt.Printf("%10s %22s | %11s %11s %s\n",
-			"[index]", "[timestamp]", "[module]", "[level]", "[message]")
+		fmt.Printf("%10s %22s | %11s %11s %6s %s\n",
+			"[index]", "[timestamp]", "[module]", "[level]", "[type]", "[message]")
 		for _, entry := range log.Entries {
-			fmt.Printf("%10d %20dus | %10s: %10s: %s\n",
+			fmt.Printf("%10d %20dus | %10s: %10s: %5s: %s\n",
 				entry.Index,
 				entry.Timestamp,
 				nmp.LogModuleToString(int(entry.Module)),
 				nmp.LogLevelToString(int(entry.Level)),
+				entry.Type,
 				entry.Msg)
 		}
 	}
diff --git a/nmxact/nmp/log.go b/nmxact/nmp/log.go
index b2b34a78..e20f0ae7 100644
--- a/nmxact/nmp/log.go
+++ b/nmxact/nmp/log.go
@@ -19,7 +19,11 @@
 
 package nmp
 
-import ()
+import (
+	"fmt"
+
+	"github.com/ugorji/go/codec"
+)
 
 //////////////////////////////////////////////////////////////////////////////
 // $defs                                                                    //
@@ -106,6 +110,20 @@ func LogTypeToString(lm int) string {
 // $show                                                                    //
 //////////////////////////////////////////////////////////////////////////////
 
+type LogEntryType int
+
+const (
+	LOG_ENTRY_TYPE_STRING LogEntryType = 0
+	LOG_ENTRY_TYPE_CBOR                = 1
+	LOG_ENTRY_TYPE_BINARY              = 2
+)
+
+var LogEntryTypeStringMap = map[LogEntryType]string{
+	LOG_ENTRY_TYPE_STRING: "str",
+	LOG_ENTRY_TYPE_CBOR:   "cbor",
+	LOG_ENTRY_TYPE_BINARY: "bin",
+}
+
 type LogShowReq struct {
 	NmpBase
 	Name      string `codec:"log_name"`
@@ -118,7 +136,8 @@ type LogEntry struct {
 	Timestamp int64  `codec:"ts"`
 	Module    uint8  `codec:"module"`
 	Level     uint8  `codec:"level"`
-	Msg       string `codec:"msg"`
+	Type      string `codec:"type"`
+	Msg       []byte `codec:"msg"`
 }
 
 type LogShowLog struct {
@@ -258,3 +277,61 @@ func NewLogClearRsp() *LogClearRsp {
 }
 
 func (r *LogClearRsp) Msg() *NmpMsg { return MsgFromReq(r) }
+
+//////////////////////////////////////////////////////////////////////////////
+// $LogType Marshal/Unmarshal                                               //
+//////////////////////////////////////////////////////////////////////////////
+
+func LogEntryTypeToString(LogType LogEntryType) string {
+	s := LogEntryTypeStringMap[LogType]
+	if s == "" {
+		return "???"
+	}
+
+	return s
+}
+
+func LogEntryTypeFromString(s string) (LogEntryType, error) {
+	for LogType, name := range LogEntryTypeStringMap {
+		if s == name {
+			return LogType, nil
+		}
+	}
+
+	return LogEntryType(0), fmt.Errorf("Invalid LogEntryType string: %s", s)
+}
+
+func (l LogEntryType) MarshalBinary([]byte, error) error {
+	var err error
+	var s string
+	var b []byte
+
+	handle := new(codec.CborHandle)
+
+	s = LogEntryTypeToString(l)
+
+	dec := codec.NewEncoderBytes(&b, handle)
+
+	err = dec.Encode(&b)
+	if err != nil {
+		return err
+	}
+
+	b = append(b, s...)
+
+	return err
+}
+
+func (l *LogEntryType) UnmarshalBinary(data []byte) error {
+	var err error
+	var s string
+
+	handle := new(codec.CborHandle)
+	dec := codec.NewDecoderBytes(data, handle)
+
+	err = dec.Decode(&s)
+
+	*l, err = LogEntryTypeFromString(s)
+
+	return err
+}


 

----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
users@infra.apache.org


With regards,
Apache Git Services