Skip to content

Commit

Permalink
Add support for sessionId identification inside Target (https://chrom…
Browse files Browse the repository at this point in the history
  • Loading branch information
Mateusz Gajewski committed Jul 23, 2017
1 parent e9b96ff commit 7428e38
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 3 deletions.
1 change: 1 addition & 0 deletions logger.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ const (
fieldLevel = "level"
fieldType = "type"
fieldTargetId = "targetId"
fieldSessionId = "sessionId"
fieldRequest = "request"
fieldMethod = "method"
fieldInspectorId = "inspectorId"
Expand Down
6 changes: 3 additions & 3 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -153,20 +153,20 @@ func dumpStream(logger *logrus.Entry, stream chan *protocolMessage) {
var targetLogger *logrus.Entry

if *flagDistributeLogs {
logger, err := createLogger(fmt.Sprintf("target-%s", msg.Params["targetId"]))
logger, err := createLogger(fmt.Sprintf("target-%s", msg.TargetId()))
if err != nil {
panic(fmt.Sprintf("could not create logger: %v", err))
}

targetLogger = logger.WithFields(logrus.Fields{
fieldLevel: levelTarget,
fieldTargetId: msg.Params["targetId"],
fieldTargetId: msg.TargetId(),
})

} else {
targetLogger = logger.WithFields(logrus.Fields{
fieldLevel: levelTarget,
fieldTargetId: msg.Params["targetId"],
fieldTargetId: msg.TargetId(),
})
}

Expand Down
15 changes: 15 additions & 0 deletions protocol.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ type protocolMessage struct {

type targetedProtocolMessage struct {
TargetId string `json:"targetId"`
SessionId string `json:"sessionId"`
Message string `json:"message"`
}

Expand Down Expand Up @@ -53,3 +54,17 @@ func (p *protocolMessage) IsEvent() bool {
func (p *protocolMessage) InTarget() bool {
return p.Method == "Target.sendMessageToTarget" || p.Method == "Target.receivedMessageFromTarget"
}

func (p *protocolMessage) TargetId() string {
if (p.InTarget()) {
if val, ok := p.Params["sessionId"]; ok {
return val.(string)
}

if val, ok := p.Params["targetId"]; ok {
return val.(string)
}
}

return ""
}

0 comments on commit 7428e38

Please sign in to comment.