func (s *WSWriter) WriteMsg(when time.Time, msg string, level int) error {
	if level > s.Level {
		return nil
	}
	msg = when.String() + " " + msg
	select {
	case s.msgs <- msg:
	default:
		return fmt.Errorf("msg %s was discarded by WSWriter, cause s.msgs channel full, current size %d", len(s.msgs))
	}
	return nil
}
WriteMsg write message to msg channel
package logs
import (
	"encoding/json"
	"fmt"
	"golang.org/x/net/websocket"
	"net/http"
	"time"
)
const (
	DEFAULT_WSCHANNEL_SIZE = 10000
)
type WSWriter struct {
	Level       int `json:"level"`
	ChannelSize int `json:"channelSize"`
	msgs        chan string
}
func newWSWriter() Logger {
	return &WSWriter{Level: LevelTrace}
}
func (s *WSWriter) Init(jsonConfig string) error {
	if len(jsonConfig) != 0 {
		if err := json.Unmarshal([]byte(jsonConfig), s); err != nil {
			return err
		}
		s.msgs = make(chan string, s.ChannelSize)
	} else {
		s.msgs = make(chan string, DEFAULT_WSCHANNEL_SIZE)
	}
	http.Handle("/wslogs", websocket.Handler(s.wshandler()))
	return nil
}
func (s *WSWriter) wshandler() websocket.Handler {
	return func(ws *websocket.Conn) {
		for {
			select {
			case msg := <-s.msgs:
				if err := websocket.Message.Send(ws, msg); err != nil {
					fmt.Println(err)
					s.msgs <- msg
				}
			}
		}
	}
}