log

package
v0.0.0-...-85548f4 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Mar 24, 2019 License: GPL-3.0 Imports: 15 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var DefaultLogger, _ = NewDefaultConfig().GetLogger()

Functions

func Debug

func Debug(format string, a ...interface{})

func Error

func Error(format string, a ...interface{})

func Fatal

func Fatal(format string, a ...interface{})

func Info

func Info(format string, a ...interface{})

func Warning

func Warning(format string, a ...interface{})

Types

type Config

type Config struct {
	Level          Level  `json:"log_level"`
	Format         Format `json:"log_format"`
	RequestLogFile string `json:"request_log_file"`
	WebHookURL     string `json:"webhook_url"`
}

func NewDefaultConfig

func NewDefaultConfig() *Config

func (Config) GetLogger

func (c Config) GetLogger() (handler *DefaultHandler, requestWriter *RequestWriter)

type DNSAnswer

type DNSAnswer struct {
	Name     string        `json:"name,omitempty"`
	Record   interface{}   `json:"record,omitempty"`
	TTL      time.Duration `json:"ttl,omitempty"`
	NXDomain string        `json:"nx_domain,omitempty"`
}

type DNSQuestion

type DNSQuestion struct {
	Name  string `json:"name"`
	Type  string `json:"type"`
	Class string `json:"class"`
}

func (*DNSQuestion) Load

func (q *DNSQuestion) Load(question dns.Question)

type DNSRecord

type DNSRecord struct {
	Questions []*DNSQuestion `json:"questions"`
	Answers   []*DNSAnswer   `json:"answers"`
}

func (*DNSRecord) AddAnswer

func (d *DNSRecord) AddAnswer(name string, ttl time.Duration, record dns.Record)

func (*DNSRecord) AddNXDomain

func (d *DNSRecord) AddNXDomain()

func (*DNSRecord) AddQuestions

func (d *DNSRecord) AddQuestions(questions []dns.Question)

type DefaultHandler

type DefaultHandler struct {
	Writers []Writer `json:"-"`
	Level   Level    `json:"log_level"`
}

func NewHandler

func NewHandler(level Level) *DefaultHandler

func (*DefaultHandler) AddWriter

func (l *DefaultHandler) AddWriter(w Writer)

func (*DefaultHandler) Debug

func (l *DefaultHandler) Debug(format string, a ...interface{})

func (*DefaultHandler) Error

func (l *DefaultHandler) Error(format string, a ...interface{})

func (*DefaultHandler) Fatal

func (l *DefaultHandler) Fatal(format string, a ...interface{})

func (*DefaultHandler) Info

func (l *DefaultHandler) Info(format string, a ...interface{})

func (*DefaultHandler) NewMSG

func (l *DefaultHandler) NewMSG() *MSG

func (*DefaultHandler) SetWriter

func (l *DefaultHandler) SetWriter(w Writer)

func (*DefaultHandler) Warning

func (l *DefaultHandler) Warning(format string, a ...interface{})

func (*DefaultHandler) WithDNSAnswer

func (l *DefaultHandler) WithDNSAnswer(name string, ttl time.Duration, record dns.Record) *MSG

func (*DefaultHandler) WithDNSNXDomain

func (l *DefaultHandler) WithDNSNXDomain() *MSG

func (*DefaultHandler) WithDNSQuestions

func (l *DefaultHandler) WithDNSQuestions(questions []dns.Question) *MSG

func (*DefaultHandler) WithError

func (l *DefaultHandler) WithError(err error) *MSG

func (*DefaultHandler) WithExitCode

func (l *DefaultHandler) WithExitCode(exitCode int) *MSG

func (*DefaultHandler) WithField

func (l *DefaultHandler) WithField(key string, value interface{}) *MSG

func (*DefaultHandler) WithRequest

func (l *DefaultHandler) WithRequest(req *http.Request) *MSG

func (*DefaultHandler) WithResponse

func (l *DefaultHandler) WithResponse(res *http.Response) *MSG

func (*DefaultHandler) Write

func (l *DefaultHandler) Write(msg *MSG)

type Format

type Format uint8
const (
	TEXT Format = 0
	JSON Format = 1 << iota
)

func (*Format) MarshalJSON

func (f *Format) MarshalJSON() ([]byte, error)

func (*Format) Parse

func (f *Format) Parse(level string)

func (Format) String

func (f Format) String() string

func (*Format) UnmarshalJSON

func (f *Format) UnmarshalJSON(data []byte) error

type Handler

type Handler interface {
	SetWriter(Writer)
	AddWriter(Writer)
	Write(*MSG)
	WithExitCode(int) *MSG
	WithError(error) *MSG
	WithField(string, interface{}) *MSG
	WithRequest(*http.Request) *MSG
	Info(string, ...interface{})
	Debug(string, ...interface{})
	Fatal(string, ...interface{})
	Warning(string, ...interface{})
	Error(string, ...interface{})
}

type JSONWriter

type JSONWriter struct {
	// contains filtered or unexported fields
}

func (*JSONWriter) SetLevel

func (w *JSONWriter) SetLevel(level Level)

func (*JSONWriter) Write

func (w *JSONWriter) Write(msg *MSG) error

type Level

type Level uint8
const (
	FATAL Level = 0
	ERROR Level = 1 << iota
	WARNING
	INFO
	DEBUG
)

func (*Level) MarshalJSON

func (l *Level) MarshalJSON() ([]byte, error)

func (*Level) Parse

func (l *Level) Parse(level string)

func (Level) String

func (l Level) String() string

func (*Level) UnmarshalJSON

func (l *Level) UnmarshalJSON(data []byte) error

type MSG

type MSG struct {
	Timestamp    time.Time              `json:"timestamp"`
	Message      string                 `json:"message"`
	Fields       map[string]interface{} `json:"fields,omitempty"`
	Request      *RequestRecord         `json:"request,omitempty"`
	Response     *ResponseRecord        `json:"response,omitempty"`
	DNS          *DNSRecord             `json:"dns,omitempty"`
	ErrorMessage string                 `json:"error,omitempty"`
	Level        Level                  `json:"level"`
	// contains filtered or unexported fields
}

func NewMSG

func NewMSG(l Handler) *MSG

func WithDNSAnswer

func WithDNSAnswer(name string, ttl time.Duration, record dns.Record) *MSG

func WithDNSNXDomain

func WithDNSNXDomain() *MSG

func WithDNSQuestions

func WithDNSQuestions(questions []dns.Question) *MSG

func WithError

func WithError(err error) *MSG

func WithExitCode

func WithExitCode(exitCode int) *MSG

func WithField

func WithField(key string, value interface{}) *MSG

func WithRequest

func WithRequest(req *http.Request) *MSG

func WithResponse

func WithResponse(res *http.Response) *MSG

func (*MSG) Debug

func (l *MSG) Debug(format string, a ...interface{})

func (*MSG) Error

func (l *MSG) Error(format string, a ...interface{})

func (*MSG) Fatal

func (l *MSG) Fatal(format string, a ...interface{})

func (*MSG) Info

func (l *MSG) Info(format string, a ...interface{})

func (*MSG) JSON

func (l *MSG) JSON() []byte

func (*MSG) String

func (l *MSG) String() (msg string)

func (*MSG) Warning

func (l *MSG) Warning(format string, a ...interface{})

func (*MSG) WithDNSAnswer

func (l *MSG) WithDNSAnswer(name string, ttl time.Duration, record dns.Record) *MSG

func (*MSG) WithDNSNXDomain

func (l *MSG) WithDNSNXDomain() *MSG

func (*MSG) WithDNSQuestions

func (l *MSG) WithDNSQuestions(questions []dns.Question) *MSG

func (*MSG) WithError

func (l *MSG) WithError(err error) *MSG

func (*MSG) WithExitCode

func (l *MSG) WithExitCode(exitCode int) *MSG

func (*MSG) WithField

func (l *MSG) WithField(key string, value interface{}) *MSG

func (*MSG) WithRequest

func (l *MSG) WithRequest(req *http.Request) *MSG

func (*MSG) WithResponse

func (l *MSG) WithResponse(res *http.Response) *MSG

type RequestRecord

type RequestRecord struct {
	Method           string
	URL              *url.URL
	Proto            string
	ProtoMajor       int
	ProtoMinor       int
	Header           map[string][]string
	Body             string
	ContentLength    int64
	TransferEncoding []string
	Host             string
	Form             url.Values
	PostForm         url.Values
	MultipartForm    *multipart.Form
	Trailer          map[string][]string
	RemoteAddr       string
	RequestURI       string
	TLS              bool
	TimeStamp        time.Time
	// contains filtered or unexported fields
}

func (*RequestRecord) Load

func (r *RequestRecord) Load(req *http.Request) (err error)

func (*RequestRecord) MarshalJSON

func (r *RequestRecord) MarshalJSON() ([]byte, error)

func (*RequestRecord) ReadBody

func (r *RequestRecord) ReadBody() error

type RequestWriter

type RequestWriter struct {
	RequestLogFile string `json:"request_log_file"`
	// contains filtered or unexported fields
}

func (*RequestWriter) Close

func (w *RequestWriter) Close() error

func (*RequestWriter) SetLevel

func (w *RequestWriter) SetLevel(level Level)

func (*RequestWriter) Write

func (w *RequestWriter) Write(msg *MSG) (err error)

type ResponseRecord

type ResponseRecord struct {
	Status           string
	StatusCode       int
	Proto            string
	ProtoMajor       int
	ProtoMinor       int
	Header           http.Header
	Body             string
	ContentLength    int64
	TransferEncoding []string
	Uncompressed     bool
	Trailer          http.Header
	TLS              bool
	TimeStamp        time.Time
	// contains filtered or unexported fields
}

func (*ResponseRecord) Load

func (r *ResponseRecord) Load(res *http.Response) (err error)

func (*ResponseRecord) MarshalJSON

func (r *ResponseRecord) MarshalJSON() ([]byte, error)

func (*ResponseRecord) ReadBody

func (r *ResponseRecord) ReadBody() error

type TextWriter

type TextWriter struct {
	// contains filtered or unexported fields
}

func (*TextWriter) SetLevel

func (w *TextWriter) SetLevel(level Level)

func (*TextWriter) Write

func (w *TextWriter) Write(msg *MSG) error

type WebHookWriter

type WebHookWriter struct {
	WebHookURL string `json:"webhook_url"`
	// contains filtered or unexported fields
}

func (*WebHookWriter) SetLevel

func (w *WebHookWriter) SetLevel(level Level)

func (*WebHookWriter) Write

func (w *WebHookWriter) Write(msg *MSG) error

type Writer

type Writer interface {
	Write(*MSG) error
	SetLevel(Level)
}

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL