-
Notifications
You must be signed in to change notification settings - Fork 19
Expand file tree
/
Copy pathlogging.go
More file actions
47 lines (41 loc) · 795 Bytes
/
logging.go
File metadata and controls
47 lines (41 loc) · 795 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
package epp
import (
"bytes"
"encoding/xml"
"fmt"
"io"
)
// DebugLogger is an io.Writer. Set to enable logging of EPP message XML.
var DebugLogger io.Writer
func logXML(pfx string, p []byte) {
if DebugLogger == nil {
return
}
var b bytes.Buffer
enc := xml.NewEncoder(&b)
enc.Indent("", "\t")
dec := xml.NewDecoder(bytes.NewReader(p))
var t xml.Token
var err error
for {
t, err = dec.RawToken()
if err == io.EOF {
err = enc.Flush()
break
}
if err != nil {
break
}
err = enc.EncodeToken(t)
if err != nil {
break
}
}
if err != nil {
fmt.Fprintf(DebugLogger, "Indentation error. Raw XML: %s\n%s\n\n", pfx, string(p))
return
}
fmt.Fprintf(DebugLogger, "%s (pretty-printed)\n", pfx)
io.Copy(DebugLogger, &b)
fmt.Fprint(DebugLogger, "\n\n")
}