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
8f16a4ef
Commit
8f16a4ef
authored
10 years ago
by
Brian Tiger Chow
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
feat(eventlog) add support for e := log.Begin... e.Append(Loggable)
parent
88fa7388
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
29 additions
and
19 deletions
+29
-19
thirdparty/eventlog/log.go
thirdparty/eventlog/log.go
+29
-19
No files found.
thirdparty/eventlog/log.go
View file @
8f16a4ef
...
...
@@ -2,7 +2,6 @@ package eventlog
import
(
"fmt"
"io"
"time"
"github.com/jbenet/go-ipfs/Godeps/_workspace/src/code.google.com/p/go.net/context"
...
...
@@ -50,14 +49,7 @@ type EventLogger interface {
// the metadata is logged.
Event
(
ctx
context
.
Context
,
event
string
,
m
...
Loggable
)
EventBegin
(
ctx
context
.
Context
,
event
string
,
m
...
Loggable
)
DoneCloser
}
type
DoneCloser
interface
{
// Done ends the event
Done
()
// io.Closer is a convenience-alias for Done
io
.
Closer
EventBegin
(
ctx
context
.
Context
,
event
string
,
m
...
Loggable
)
EventInProgress
}
// Logger retrieves an event logger by name
...
...
@@ -76,14 +68,21 @@ type eventLogger struct {
// TODO add log-level
}
func
(
el
*
eventLogger
)
EventBegin
(
ctx
context
.
Context
,
event
string
,
metadata
...
Loggable
)
DoneCloser
{
func
(
el
*
eventLogger
)
EventBegin
(
ctx
context
.
Context
,
event
string
,
metadata
...
Loggable
)
EventInProgress
{
start
:=
time
.
Now
()
el
.
Event
(
ctx
,
fmt
.
Sprintf
(
"%sBegin"
,
event
),
metadata
...
)
return
doneCloserFunc
(
func
()
{
el
.
Event
(
ctx
,
event
,
append
(
metadata
,
LoggableMap
(
map
[
string
]
interface
{}{
eip
:=
EventInProgress
{}
eip
.
doneFunc
=
func
(
additional
[]
Loggable
)
{
metadata
=
append
(
metadata
,
additional
...
)
// anything added during the operation
metadata
=
append
(
metadata
,
LoggableMap
(
map
[
string
]
interface
{}{
// finally, duration of event
"duration"
:
time
.
Now
()
.
Sub
(
start
),
}))
...
)
})
}))
el
.
Event
(
ctx
,
event
,
metadata
...
)
}
return
eip
}
func
(
el
*
eventLogger
)
Event
(
ctx
context
.
Context
,
event
string
,
metadata
...
Loggable
)
{
...
...
@@ -111,13 +110,24 @@ func (el *eventLogger) Event(ctx context.Context, event string, metadata ...Logg
e
.
Log
()
// TODO replace this when leveled-logs have been implemented
}
type
doneCloserFunc
func
()
type
EventInProgress
struct
{
loggables
[]
Loggable
doneFunc
func
([]
Loggable
)
}
// Append adds loggables to be included in the call to Done
func
(
eip
EventInProgress
)
Append
(
l
Loggable
)
{
eip
.
loggables
=
append
(
eip
.
loggables
,
l
)
}
func
(
f
doneCloserFunc
)
Done
()
{
f
()
// Done creates a new Event entry that includes the duration and appended
// loggables.
func
(
eip
EventInProgress
)
Done
()
{
eip
.
doneFunc
(
eip
.
loggables
)
// create final event with extra data
}
func
(
f
doneCloserFunc
)
Close
()
error
{
f
.
Done
()
// Close is an alias for done
func
(
eip
EventInProgress
)
Close
()
error
{
eip
.
Done
()
return
nil
}
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