Skip to content
GitLab
Projects
Groups
Snippets
Help
Loading...
Help
What's new
10
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Open sidebar
dms3
go-dms3
Commits
4b160781
Commit
4b160781
authored
Nov 15, 2014
by
Brian Tiger Chow
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
log(dht) log a couple events to demonstrate API
License: MIT Signed-off-by:
Brian Tiger Chow
<
brian@perfmode.com
>
parent
2c88e342
Changes
5
Show whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
38 additions
and
5 deletions
+38
-5
peer/peer.go
peer/peer.go
+22
-0
routing/dht/dht.go
routing/dht/dht.go
+4
-1
routing/dht/pb/message.go
routing/dht/pb/message.go
+8
-0
util/elog/log.go
util/elog/log.go
+3
-3
util/elog/metadata.go
util/elog/metadata.go
+1
-1
No files found.
peer/peer.go
View file @
4b160781
...
...
@@ -101,6 +101,8 @@ type Peer interface {
// Update with the data of another peer instance
Update
(
Peer
)
error
Loggable
()
map
[
string
]
interface
{}
}
type
Type
uint8
...
...
@@ -112,6 +114,17 @@ const (
Remote
)
func
(
t
Type
)
String
()
string
{
switch
t
{
case
Local
:
return
"localPeer"
case
Remote
:
return
"remotePeer"
default
:
}
return
"unspecifiedPeer"
}
type
peer
struct
{
id
ID
addresses
[]
ma
.
Multiaddr
...
...
@@ -145,6 +158,15 @@ func (p *peer) String() string {
return
"[Peer "
+
pid
[
:
maxRunes
]
+
"]"
}
func
(
p
*
peer
)
Loggable
()
map
[
string
]
interface
{}
{
return
map
[
string
]
interface
{}{
p
.
GetType
()
.
String
()
:
map
[
string
]
interface
{}{
"id"
:
p
.
ID
(),
"latency"
:
p
.
GetLatency
(),
},
}
}
// Key returns the ID as a Key (string) for maps.
func
(
p
*
peer
)
Key
()
u
.
Key
{
return
u
.
Key
(
p
.
id
)
...
...
routing/dht/dht.go
View file @
4b160781
...
...
@@ -18,6 +18,7 @@ import (
kb
"github.com/jbenet/go-ipfs/routing/kbucket"
u
"github.com/jbenet/go-ipfs/util"
ctxc
"github.com/jbenet/go-ipfs/util/ctxcloser"
"github.com/jbenet/go-ipfs/util/elog"
context
"github.com/jbenet/go-ipfs/Godeps/_workspace/src/code.google.com/p/go.net/context"
ds
"github.com/jbenet/go-ipfs/Godeps/_workspace/src/github.com/jbenet/go-datastore"
...
...
@@ -25,7 +26,7 @@ import (
"github.com/jbenet/go-ipfs/Godeps/_workspace/src/code.google.com/p/goprotobuf/proto"
)
var
log
=
u
.
Logger
(
"dht"
)
var
log
=
elog
.
Logger
(
"dht"
)
const
doPinging
=
false
...
...
@@ -152,6 +153,7 @@ func (dht *IpfsDHT) HandleMessage(ctx context.Context, mes msg.NetMessage) msg.N
dht
.
Update
(
mPeer
)
// Print out diagnostic
log
.
Event
(
ctx
,
"foo"
,
dht
.
self
,
mPeer
,
pmes
)
log
.
Debugf
(
"%s got message type: '%s' from %s"
,
dht
.
self
,
pb
.
Message_MessageType_name
[
int32
(
pmes
.
GetType
())],
mPeer
)
...
...
@@ -197,6 +199,7 @@ func (dht *IpfsDHT) sendRequest(ctx context.Context, p peer.Peer, pmes *pb.Messa
start
:=
time
.
Now
()
// Print out diagnostic
log
.
Event
(
ctx
,
"sentMessage"
,
dht
.
self
,
p
,
pmes
)
log
.
Debugf
(
"Sent message type: '%s' to %s"
,
pb
.
Message_MessageType_name
[
int32
(
pmes
.
GetType
())],
p
)
...
...
routing/dht/pb/message.go
View file @
4b160781
...
...
@@ -65,3 +65,11 @@ func (m *Message) SetClusterLevel(level int) {
lvl
:=
int32
(
level
)
m
.
ClusterLevelRaw
=
&
lvl
}
func
(
m
*
Message
)
Loggable
()
map
[
string
]
interface
{}
{
return
map
[
string
]
interface
{}{
"message"
:
map
[
string
]
string
{
"type"
:
m
.
Type
.
String
(),
},
}
}
util/elog/log.go
View file @
4b160781
...
...
@@ -14,7 +14,7 @@ func init() {
type
EventLogger
interface
{
StandardLogger
Event
(
ctx
context
.
Context
,
event
string
,
m
...
Metadata
)
Event
(
ctx
context
.
Context
,
event
string
,
m
...
Loggable
)
}
type
StandardLogger
interface
{
...
...
@@ -46,14 +46,14 @@ type eventLogger struct {
*
logging
.
Logger
}
func
(
el
*
eventLogger
)
Event
(
ctx
context
.
Context
,
event
string
,
metadata
...
Metadata
)
{
func
(
el
*
eventLogger
)
Event
(
ctx
context
.
Context
,
event
string
,
metadata
...
Loggable
)
{
existing
,
err
:=
MetadataFromContext
(
ctx
)
if
err
!=
nil
{
existing
=
Metadata
{}
}
accum
:=
existing
for
_
,
datum
:=
range
metadata
{
accum
=
DeepMerge
(
accum
,
datum
)
accum
=
DeepMerge
(
accum
,
datum
.
Loggable
()
)
}
accum
[
"event"
]
=
event
...
...
util/elog/metadata.go
View file @
4b160781
...
...
@@ -13,7 +13,7 @@ type Metadata map[string]interface{}
// Loggable describes objects that can be marshalled into Metadata for logging
type
Loggable
interface
{
Loggable
()
Metadata
Loggable
()
map
[
string
]
interface
{}
}
// UniqueEvent returns a Metadata with the string key and UUID value
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment