mirror of
https://github.com/moby/moby.git
synced 2022-11-09 12:21:53 -05:00
Improve the debug function
This commit is contained in:
parent
22598ee572
commit
6576b19a28
1 changed files with 14 additions and 3 deletions
17
utils.go
17
utils.go
|
@ -7,11 +7,12 @@ import (
|
||||||
"fmt"
|
"fmt"
|
||||||
"github.com/dotcloud/docker/rcli"
|
"github.com/dotcloud/docker/rcli"
|
||||||
"io"
|
"io"
|
||||||
"log"
|
|
||||||
"net/http"
|
"net/http"
|
||||||
"os"
|
"os"
|
||||||
"os/exec"
|
"os/exec"
|
||||||
"path/filepath"
|
"path/filepath"
|
||||||
|
"runtime"
|
||||||
|
"strings"
|
||||||
"sync"
|
"sync"
|
||||||
"time"
|
"time"
|
||||||
)
|
)
|
||||||
|
@ -43,9 +44,19 @@ func Download(url string, stderr io.Writer) (*http.Response, error) {
|
||||||
// If Docker is in damon mode, also send the debug info on the socket
|
// If Docker is in damon mode, also send the debug info on the socket
|
||||||
func Debugf(format string, a ...interface{}) {
|
func Debugf(format string, a ...interface{}) {
|
||||||
if rcli.DEBUG_FLAG {
|
if rcli.DEBUG_FLAG {
|
||||||
log.Printf(format, a...)
|
|
||||||
|
// Retrieve the stack infos
|
||||||
|
_, file, line, ok := runtime.Caller(1)
|
||||||
|
if !ok {
|
||||||
|
file = "<unknown>"
|
||||||
|
line = -1
|
||||||
|
} else {
|
||||||
|
file = file[strings.LastIndex(file, "/")+1:]
|
||||||
|
}
|
||||||
|
|
||||||
|
fmt.Fprintf(os.Stderr, fmt.Sprintf("[debug] %s:%d %s\n", file, line, format), a...)
|
||||||
if rcli.CLIENT_SOCKET != nil {
|
if rcli.CLIENT_SOCKET != nil {
|
||||||
fmt.Fprintf(rcli.CLIENT_SOCKET, log.Prefix()+format, a...)
|
fmt.Fprintf(rcli.CLIENT_SOCKET, fmt.Sprintf("[debug] %s:%d %s\n", file, line, format), a...)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue