40 Star 147 Fork 3

Gitee 极速下载/grafana

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
此仓库是为了提升国内下载速度的镜像仓库,每日同步一次。 原始仓库: https://github.com/grafana/grafana
克隆/下载
syslog.go 1.76 KB
一键复制 编辑 原始数据 按行查看 历史
//+build !windows,!nacl,!plan9
package log
import (
"encoding/json"
"errors"
"log/syslog"
)
type SyslogWriter struct {
syslog *syslog.Writer
Network string `json:"network"`
Address string `json:"address"`
Facility string `json:"facility"`
Tag string `json:"tag"`
}
func NewSyslog() LoggerInterface {
return new(SyslogWriter)
}
func (sw *SyslogWriter) Init(config string) error {
if err := json.Unmarshal([]byte(config), sw); err != nil {
return err
}
prio, err := parseFacility(sw.Facility)
if err != nil {
return err
}
w, err := syslog.Dial(sw.Network, sw.Address, prio, sw.Tag)
if err != nil {
return err
}
sw.syslog = w
return nil
}
func (sw *SyslogWriter) WriteMsg(msg string, skip int, level LogLevel) error {
var err error
switch level {
case TRACE, DEBUG:
err = sw.syslog.Debug(msg)
case INFO:
err = sw.syslog.Info(msg)
case WARN:
err = sw.syslog.Warning(msg)
case ERROR:
err = sw.syslog.Err(msg)
case CRITICAL:
err = sw.syslog.Crit(msg)
case FATAL:
err = sw.syslog.Alert(msg)
default:
err = errors.New("invalid syslog level")
}
return err
}
func (sw *SyslogWriter) Destroy() {
sw.syslog.Close()
}
func (sw *SyslogWriter) Flush() {}
var facilities = map[string]syslog.Priority{
"user": syslog.LOG_USER,
"daemon": syslog.LOG_DAEMON,
"local0": syslog.LOG_LOCAL0,
"local1": syslog.LOG_LOCAL1,
"local2": syslog.LOG_LOCAL2,
"local3": syslog.LOG_LOCAL3,
"local4": syslog.LOG_LOCAL4,
"local5": syslog.LOG_LOCAL5,
"local6": syslog.LOG_LOCAL6,
"local7": syslog.LOG_LOCAL7,
}
func parseFacility(facility string) (syslog.Priority, error) {
prio, ok := facilities[facility]
if !ok {
return syslog.LOG_LOCAL0, errors.New("invalid syslog facility")
}
return prio, nil
}
func init() {
Register("syslog", NewSyslog)
}
Loading...
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
JavaScript
1
https://gitee.com/mirrors/grafana.git
git@gitee.com:mirrors/grafana.git
mirrors
grafana
grafana
v3.0.0-beta6

搜索帮助