@@ -16,7 +16,7 @@ import (
1616// FormatFunc is the function that the workers use to create
1717// a new Formatter per worker allowing reusable go routine safe
1818// variable to be used within your Formatter function.
19- type FormatFunc func (h * HTTP ) Formatter
19+ type FormatFunc func (h HTTP ) Formatter
2020
2121// Formatter is the function used to format the HTTP entry
2222type Formatter func (e * log.Entry ) []byte
@@ -30,8 +30,20 @@ const (
3030 gopath = "GOPATH"
3131)
3232
33+ // HTTP interface to allow for defining handlers based upon this one.
34+ type HTTP interface {
35+ SetFilenameDisplay (fd log.FilenameDisplay )
36+ FilenameDisplay () log.FilenameDisplay
37+ SetBuffersAndWorkers (size uint , workers uint )
38+ SetTimestampFormat (format string )
39+ TimestampFormat () string
40+ GOPATH () string
41+ SetFormatFunc (fn FormatFunc )
42+ Run () chan <- * log.Entry
43+ }
44+
3345// HTTP is an instance of the http logger
34- type HTTP struct {
46+ type internalHTTP struct {
3547 buffer uint // channel buffer
3648 numWorkers uint
3749 remoteHost string
@@ -44,14 +56,16 @@ type HTTP struct {
4456 fileDisplay log.FilenameDisplay
4557}
4658
59+ var _ HTTP = new (internalHTTP )
60+
4761// New returns a new instance of the http logger
48- func New (remoteHost string , method string , header stdhttp.Header ) (* HTTP , error ) {
62+ func New (remoteHost string , method string , header stdhttp.Header ) (HTTP , error ) {
4963
5064 if _ , err := url .Parse (remoteHost ); err != nil {
5165 return nil , err
5266 }
5367
54- return & HTTP {
68+ return & internalHTTP {
5569 buffer : 0 ,
5670 remoteHost : remoteHost ,
5771 numWorkers : 1 ,
@@ -65,18 +79,18 @@ func New(remoteHost string, method string, header stdhttp.Header) (*HTTP, error)
6579}
6680
6781// SetFilenameDisplay tells HTTP the filename, when present, how to display
68- func (h * HTTP ) SetFilenameDisplay (fd log.FilenameDisplay ) {
82+ func (h * internalHTTP ) SetFilenameDisplay (fd log.FilenameDisplay ) {
6983 h .fileDisplay = fd
7084}
7185
7286// FilenameDisplay returns Console's current filename display setting
73- func (h * HTTP ) FilenameDisplay () log.FilenameDisplay {
87+ func (h * internalHTTP ) FilenameDisplay () log.FilenameDisplay {
7488 return h .fileDisplay
7589}
7690
7791// SetBuffersAndWorkers sets the channels buffer size and number of concurrent workers.
7892// These settings should be thought about together, hence setting both in the same function.
79- func (h * HTTP ) SetBuffersAndWorkers (size uint , workers uint ) {
93+ func (h * internalHTTP ) SetBuffersAndWorkers (size uint , workers uint ) {
8094 h .buffer = size
8195
8296 if workers == 0 {
@@ -92,28 +106,28 @@ func (h *HTTP) SetBuffersAndWorkers(size uint, workers uint) {
92106
93107// SetTimestampFormat sets HTTP's timestamp output format
94108// Default is : "2006-01-02T15:04:05.000000000Z07:00"
95- func (h * HTTP ) SetTimestampFormat (format string ) {
109+ func (h * internalHTTP ) SetTimestampFormat (format string ) {
96110 h .timestampFormat = format
97111}
98112
99113// TimestampFormat returns HTTP's current timestamp output format
100- func (h * HTTP ) TimestampFormat () string {
114+ func (h * internalHTTP ) TimestampFormat () string {
101115 return h .timestampFormat
102116}
103117
104118// GOPATH returns the GOPATH calculated by HTTP
105- func (h * HTTP ) GOPATH () string {
119+ func (h * internalHTTP ) GOPATH () string {
106120 return h .gopath
107121}
108122
109123// SetFormatFunc sets FormatFunc each worker will call to get
110124// a Formatter func
111- func (h * HTTP ) SetFormatFunc (fn FormatFunc ) {
125+ func (h * internalHTTP ) SetFormatFunc (fn FormatFunc ) {
112126 h .formatFunc = fn
113127}
114128
115129// Run starts the logger consuming on the returned channed
116- func (h * HTTP ) Run () chan <- * log.Entry {
130+ func (h * internalHTTP ) Run () chan <- * log.Entry {
117131
118132 // pre-setup
119133 if h .fileDisplay == log .Llongfile {
@@ -133,7 +147,7 @@ func (h *HTTP) Run() chan<- *log.Entry {
133147 return ch
134148}
135149
136- func defaultFormatFunc (h * HTTP ) Formatter {
150+ func defaultFormatFunc (h HTTP ) Formatter {
137151
138152 var b []byte
139153 var file string
@@ -233,7 +247,7 @@ func defaultFormatFunc(h *HTTP) Formatter {
233247 }
234248}
235249
236- func (h * HTTP ) handleLog (entries <- chan * log.Entry ) {
250+ func (h * internalHTTP ) handleLog (entries <- chan * log.Entry ) {
237251 var e * log.Entry
238252 var b []byte
239253 var reader * bytes.Reader
0 commit comments