Skip to content

Commit

Permalink
Merge pull request #171 from peixian/log-hooks-to-stdout
Browse files Browse the repository at this point in the history
Log hooks to stdout
  • Loading branch information
Acconut authored Mar 19, 2018
2 parents 3648258 + 9cf50ff commit 966f1d5
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 7 deletions.
10 changes: 5 additions & 5 deletions cmd/tusd/cli/hooks.go
Original file line number Diff line number Diff line change
Expand Up @@ -70,16 +70,16 @@ func invokeHook(typ HookType, info tusd.FileInfo) {
func invokeHookSync(typ HookType, info tusd.FileInfo, captureOutput bool) ([]byte, error) {
switch typ {
case HookPostFinish:
logEv("UploadFinished", "id", info.ID, "size", strconv.FormatInt(info.Size, 10))
logEv(stdout, "UploadFinished", "id", info.ID, "size", strconv.FormatInt(info.Size, 10))
case HookPostTerminate:
logEv("UploadTerminated", "id", info.ID)
logEv(stdout, "UploadTerminated", "id", info.ID)
}

if !Flags.FileHooksInstalled && !Flags.HttpHooksInstalled {
return nil, nil
}
name := string(typ)
logEv("HookInvocationStart", "type", name, "id", info.ID)
logEv(stdout, "HookInvocationStart", "type", name, "id", info.ID)

output := []byte{}
err := error(nil)
Expand All @@ -93,9 +93,9 @@ func invokeHookSync(typ HookType, info tusd.FileInfo, captureOutput bool) ([]byt
}

if err != nil {
logEv("HookInvocationError", "type", string(typ), "id", info.ID, "error", err.Error())
logEv(stderr, "HookInvocationError", "type", string(typ), "id", info.ID, "error", err.Error())
} else {
logEv("HookInvocationFinish", "type", string(typ), "id", info.ID)
logEv(stdout, "HookInvocationFinish", "type", string(typ), "id", info.ID)
}

return output, err
Expand Down
4 changes: 2 additions & 2 deletions cmd/tusd/cli/log.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,6 @@ import (
var stdout = log.New(os.Stdout, "[tusd] ", 0)
var stderr = log.New(os.Stderr, "[tusd] ", 0)

func logEv(eventName string, details ...string) {
tusd.LogEvent(stderr, eventName, details...)
func logEv(logOutput *log.Logger, eventName string, details ...string) {
tusd.LogEvent(logOutput, eventName, details...)
}

0 comments on commit 966f1d5

Please sign in to comment.