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
p2p
go-p2p-loggables
Commits
1704db59
Commit
1704db59
authored
9 years ago
by
Jeromy
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
vendor go-ipfs-util
parents
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
71 additions
and
0 deletions
+71
-0
loggables.go
loggables.go
+71
-0
No files found.
loggables.go
0 → 100644
View file @
1704db59
// Package loggables includes a bunch of transaltor functions for commonplace/stdlib
// objects. This is boilerplate code that shouldn't change much, and not sprinkled
// all over the place (i.e. gather it here).
//
// Note: it may make sense to put all stdlib Loggable functions in the eventlog
// package. Putting it here for now in case we don't want to polute it.
package
loggables
import
(
"net"
ma
"QmbWxL1aXQhBjc1XGjGF1f2KGBMCBYSuT2ThA8YXnXJK83/go-multiaddr"
logging
"QmWRypnfEwrgH4k93KEHN5hng7VjKYkWmzDYRuTZeh2Mgh/go-log"
peer
"github.com/ipfs/go-libp2p/p2p/peer"
)
// NetConn returns an eventlog.Metadata with the conn addresses
func
NetConn
(
c
net
.
Conn
)
logging
.
Loggable
{
return
logging
.
Metadata
{
"localAddr"
:
c
.
LocalAddr
(),
"remoteAddr"
:
c
.
RemoteAddr
(),
}
}
// Error returns an eventlog.Metadata with an error
func
Error
(
e
error
)
logging
.
Loggable
{
return
logging
.
Metadata
{
"error"
:
e
.
Error
(),
}
}
// Dial metadata is metadata for dial events
func
Dial
(
sys
string
,
lid
,
rid
peer
.
ID
,
laddr
,
raddr
ma
.
Multiaddr
)
DeferredMap
{
m
:=
DeferredMap
{}
m
[
"subsystem"
]
=
sys
if
lid
!=
""
{
m
[
"localPeer"
]
=
func
()
interface
{}
{
return
lid
.
Pretty
()
}
}
if
laddr
!=
nil
{
m
[
"localAddr"
]
=
func
()
interface
{}
{
return
laddr
.
String
()
}
}
if
rid
!=
""
{
m
[
"remotePeer"
]
=
func
()
interface
{}
{
return
rid
.
Pretty
()
}
}
if
raddr
!=
nil
{
m
[
"remoteAddr"
]
=
func
()
interface
{}
{
return
raddr
.
String
()
}
}
return
m
}
// DeferredMap is a Loggable which may contained deffered values.
type
DeferredMap
map
[
string
]
interface
{}
// Loggable describes objects that can be marshalled into Metadata for logging
func
(
m
DeferredMap
)
Loggable
()
map
[
string
]
interface
{}
{
m2
:=
map
[
string
]
interface
{}{}
for
k
,
v
:=
range
m
{
if
vf
,
ok
:=
v
.
(
func
()
interface
{});
ok
{
// if it's a DeferredVal, call it.
m2
[
k
]
=
vf
()
}
else
{
// else use the value as is.
m2
[
k
]
=
v
}
}
return
m2
}
This diff is collapsed.
Click to expand it.
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