Feature: add custom DNS support (#56)

This commit is contained in:
Dreamacro
2018-12-05 21:13:29 +08:00
committed by GitHub
parent da5db36ccf
commit 03c249ecb1
23 changed files with 939 additions and 124 deletions

View File

@ -3,18 +3,16 @@ package log
import (
"encoding/json"
"errors"
yaml "gopkg.in/yaml.v2"
)
var (
// LogLevelMapping is a mapping for LogLevel enum
LogLevelMapping = map[string]LogLevel{
"error": ERROR,
"warning": WARNING,
"info": INFO,
"debug": DEBUG,
"silent": SILENT,
ERROR.String(): ERROR,
WARNING.String(): WARNING,
INFO.String(): INFO,
DEBUG.String(): DEBUG,
SILENT.String(): SILENT,
}
)
@ -28,10 +26,10 @@ const (
type LogLevel int
// UnmarshalYAML unserialize Mode with yaml
func (l *LogLevel) UnmarshalYAML(data []byte) error {
// UnmarshalYAML unserialize LogLevel with yaml
func (l *LogLevel) UnmarshalYAML(unmarshal func(interface{}) error) error {
var tp string
yaml.Unmarshal(data, &tp)
unmarshal(&tp)
level, exist := LogLevelMapping[tp]
if !exist {
return errors.New("invalid mode")
@ -40,12 +38,7 @@ func (l *LogLevel) UnmarshalYAML(data []byte) error {
return nil
}
// MarshalYAML serialize Mode with yaml
func (l LogLevel) MarshalYAML() ([]byte, error) {
return yaml.Marshal(l.String())
}
// UnmarshalJSON unserialize Mode with json
// UnmarshalJSON unserialize LogLevel with json
func (l *LogLevel) UnmarshalJSON(data []byte) error {
var tp string
json.Unmarshal(data, &tp)
@ -57,7 +50,7 @@ func (l *LogLevel) UnmarshalJSON(data []byte) error {
return nil
}
// MarshalJSON serialize Mode with json
// MarshalJSON serialize LogLevel with json
func (l LogLevel) MarshalJSON() ([]byte, error) {
return json.Marshal(l.String())
}
@ -75,6 +68,6 @@ func (l LogLevel) String() string {
case SILENT:
return "silent"
default:
return "unknow"
return "unknown"
}
}

View File

@ -14,6 +14,10 @@ var (
level = INFO
)
func init() {
log.SetLevel(log.DebugLevel)
}
type Event struct {
LogLevel LogLevel
Payload string
@ -47,6 +51,10 @@ func Debugln(format string, v ...interface{}) {
print(event)
}
func Fatalln(format string, v ...interface{}) {
log.Fatalf(format, v...)
}
func Subscribe() observable.Subscription {
sub, _ := source.Subscribe()
return sub