Merge pull request #171 from peixian/log-hooks-to-stdout
Log hooks to stdout
This commit is contained in:
commit
966f1d5163
|
@ -70,16 +70,16 @@ func invokeHook(typ HookType, info tusd.FileInfo) {
|
||||||
func invokeHookSync(typ HookType, info tusd.FileInfo, captureOutput bool) ([]byte, error) {
|
func invokeHookSync(typ HookType, info tusd.FileInfo, captureOutput bool) ([]byte, error) {
|
||||||
switch typ {
|
switch typ {
|
||||||
case HookPostFinish:
|
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:
|
case HookPostTerminate:
|
||||||
logEv("UploadTerminated", "id", info.ID)
|
logEv(stdout, "UploadTerminated", "id", info.ID)
|
||||||
}
|
}
|
||||||
|
|
||||||
if !Flags.FileHooksInstalled && !Flags.HttpHooksInstalled {
|
if !Flags.FileHooksInstalled && !Flags.HttpHooksInstalled {
|
||||||
return nil, nil
|
return nil, nil
|
||||||
}
|
}
|
||||||
name := string(typ)
|
name := string(typ)
|
||||||
logEv("HookInvocationStart", "type", name, "id", info.ID)
|
logEv(stdout, "HookInvocationStart", "type", name, "id", info.ID)
|
||||||
|
|
||||||
output := []byte{}
|
output := []byte{}
|
||||||
err := error(nil)
|
err := error(nil)
|
||||||
|
@ -93,9 +93,9 @@ func invokeHookSync(typ HookType, info tusd.FileInfo, captureOutput bool) ([]byt
|
||||||
}
|
}
|
||||||
|
|
||||||
if err != nil {
|
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 {
|
} else {
|
||||||
logEv("HookInvocationFinish", "type", string(typ), "id", info.ID)
|
logEv(stdout, "HookInvocationFinish", "type", string(typ), "id", info.ID)
|
||||||
}
|
}
|
||||||
|
|
||||||
return output, err
|
return output, err
|
||||||
|
|
|
@ -10,6 +10,6 @@ import (
|
||||||
var stdout = log.New(os.Stdout, "[tusd] ", 0)
|
var stdout = log.New(os.Stdout, "[tusd] ", 0)
|
||||||
var stderr = log.New(os.Stderr, "[tusd] ", 0)
|
var stderr = log.New(os.Stderr, "[tusd] ", 0)
|
||||||
|
|
||||||
func logEv(eventName string, details ...string) {
|
func logEv(logOutput *log.Logger, eventName string, details ...string) {
|
||||||
tusd.LogEvent(stderr, eventName, details...)
|
tusd.LogEvent(logOutput, eventName, details...)
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue