本文整理汇总了Golang中log/syslog.Priority函数的典型用法代码示例。如果您正苦于以下问题:Golang Priority函数的具体用法?Golang Priority怎么用?Golang Priority使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了Priority函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。
示例1: startCmd
func startCmd(cmdName string, args ...string) (*exec.Cmd, error) {
var err error
lvl := syslog.Priority(stdoutLevel) | syslog.Priority(facility)
stdoutLog, err = syslog.New(lvl, tag)
if err != nil {
log.Fatalf("Error initializing stdout syslog: %v", err)
}
lvl = syslog.Priority(stderrLevel) | syslog.Priority(facility)
stderrLog, err = syslog.New(lvl, tag)
if err != nil {
log.Fatalf("Error initializing stderr syslog: %v", err)
}
cmd := exec.Command(cmdName, args...)
cmd.Stdin = os.Stdin
stdoutPipe, err := cmd.StdoutPipe()
if err != nil {
log.Fatalf("Error initializing stdout pipe: %v", err)
}
stderrPipe, err := cmd.StderrPipe()
if err != nil {
log.Fatalf("Error initializing stderr pipe: %v", err)
}
wg.Add(2)
go logPipe(stdoutLog, stdoutPipe)
go logPipe(stderrLog, stderrPipe)
return cmd, cmd.Start()
}
示例2: newPriority
// newPriority creates a new default priority
func (d *DockerLogParser) newPriority(p int) Priority {
// The Priority value is calculated by first multiplying the Facility
// number by 8 and then adding the numerical value of the Severity.
return Priority{
Pri: p,
Facility: syslog.Priority(p / 8),
Severity: syslog.Priority(p % 8),
}
}
示例3: parseFacility
func parseFacility(facility string) (syslog.Priority, error) {
if facility == "" {
return syslog.LOG_DAEMON, nil
}
if syslogFacility, valid := facilities[facility]; valid {
return syslogFacility, nil
}
fInt, err := strconv.Atoi(facility)
if err == nil && 0 <= fInt && fInt <= 23 {
return syslog.Priority(fInt << 3), nil
}
return syslog.Priority(0), errors.New("invalid syslog facility")
}
示例4: LoadConfig
func (c *sysLogger) LoadConfig(config map[string]interface{}) error {
if level, ok := config["level"]; ok {
c.level = level.(int)
} else {
c.level = LevelDebug
}
if sysLevel, ok := config["sysLevel"]; ok {
c.sysLevel = LocalLevel[sysLevel.(int)]
} else {
c.sysLevel = syslog.LOG_LOCAL6
}
var Flags int
if flags, ok := config["flags"]; ok {
Flags = flags.(int)
} else {
Flags = 9
}
var err error
c.logger, err = syslog.NewLogger(syslog.LOG_NOTICE|syslog.Priority(c.sysLevel), Flags)
if err != nil {
return errors.New("syslog newLogger error")
}
return nil
}
示例5: SyslogSink
// SyslogSink returns a sink that outputs to the local syslog daemon.
func SyslogSink(p Priority, tag, format string, fields []string) (*syslogSink, error) {
prio := syslog.Priority(p) | syslog.LOG_USER
w, err := syslog.New(prio, tag)
if err != nil {
return nil, err
}
return &syslogSink{w, p, format, fields}, nil
}
示例6: NewSyslogOutput
// NewSyslogOutput returns a TextOutput object that writes to syslog using
// the given facility and tag. The log level will be determined by the log
// event.
func NewSyslogOutput(facility SyslogPriority, tag string) (
TextOutput, error) {
w, err := syslog.New(syslog.Priority(facility), tag)
if err != nil {
return nil, err
}
return &SyslogOutput{w: w}, nil
}
示例7: NewLogger
// NewLogger is used to construct a new Syslogger
func NewLogger(p Priority, tag string) (Syslogger, error) {
priority := syslog.Priority(p) | syslog.LOG_DAEMON
l, err := syslog.New(priority, tag)
if err != nil {
return nil, err
}
return &builtinLogger{l}, nil
}
示例8: connectToSyslog
// establishes the connection to syslog.
func (conf *syslogModuleConfig) connectToSyslog(
network,
raddr string,
facility int,
tag string) error {
facilityName, err := FacilityValueToName(facility)
if err != nil {
return err
}
var priority goSyslog.Priority = goSyslog.Priority(facility<<3) | goSyslog.LOG_INFO
conf.network = network
conf.raddr = raddr
conf.facility = facility
conf.tag = tag
conf.syslogConn, err = goSyslog.Dial(network, raddr, priority, tag)
if err != nil {
log.Printf("Could not open connection to syslog, reason: " + err.Error())
return err
}
if conf.syslogConn == nil {
log.Printf("Could not retrieve connection to syslog")
return fmt.Errorf("Could not retrieve connection to syslog")
}
conf.syslogConn.Debug(
fmt.Sprintf(
"rlog syslog (re)connected with facility=%d(%s), tag=\"%s\"",
facility,
facilityName,
tag))
conf.syslogConn.Debug(
fmt.Sprintf(
"rlog syslog network=\"%s\", raddr=\"%s\", heartBeatFilePath=\"%s\"",
network,
raddr,
conf.heartBeatFilePath))
// FIX: heartbeat for debugging only.
if conf.heartBeatFilePath != "" {
parentDir, _ := filepath.Split(conf.heartBeatFilePath)
if parentDir != "" {
var dirMode os.FileMode = 0775 // user/group-only read/write/traverse, world read/traverse
err = os.MkdirAll(parentDir, dirMode)
if err != nil {
return err
}
}
err = conf.writeHeartBeat("Starting heartbeat...", true)
if err != nil {
return err
}
}
return nil
}
示例9: openSyslog
func openSyslog(level Priority, prefix string) *log.Logger {
logger, err := syslog.NewLogger(syslog.Priority(level), log.Lshortfile)
if err != nil {
fmt.Println("Error opening syslog: ", err)
return nil
}
logger.SetPrefix(prefix)
return logger
}
示例10: TestInvalidSeverity
func TestInvalidSeverity(t *testing.T) {
fw := &fakeWriter{}
writer = fw
event.Dispatch(&TestEvent{priority: syslog.Priority(123), message: "log me"})
if fw.message == "log me" {
t.Errorf("message was logged despite invalid severity")
}
}
示例11: NewLogger
// NewLogger is used to construct a new Syslogger
func NewLogger(p Priority, facility, tag string) (Syslogger, error) {
fPriority, err := facilityPriority(facility)
if err != nil {
return nil, err
}
priority := syslog.Priority(p) | fPriority
l, err := newBuiltin(priority, tag)
if err != nil {
return nil, err
}
return &builtinLogger{l}, nil
}
示例12: DialLogger
// DialLogger is used to construct a new Syslogger that establishes connection to remote syslog server
func DialLogger(network, raddr string, p Priority, facility, tag string) (Syslogger, error) {
fPriority, err := facilityPriority(facility)
if err != nil {
return nil, err
}
priority := syslog.Priority(p) | fPriority
l, err := dialBuiltin(network, raddr, priority, tag)
if err != nil {
return nil, err
}
return &builtinLogger{l}, nil
}
示例13: LogInit
func LogInit(level Priority, prefix string, toSyslog bool, debugSelectors []string) {
_log.toSyslog = toSyslog
_log.level = syslog.Priority(level)
_log.selectors = make(map[string]bool)
for _, selector := range debugSelectors {
_log.selectors[selector] = true
}
if _log.toSyslog {
for prio := syslog.LOG_EMERG; prio <= syslog.LOG_DEBUG; prio++ {
_log.syslog[prio] = openSyslog(prio, prefix)
}
} else {
_log.logger = log.New(os.Stdout, prefix, log.Lshortfile)
}
}
示例14: lookup
func lookup(str string) (syslog.Priority, error) {
n, err := strconv.ParseInt(str, 64, 0)
if err == nil {
return syslog.Priority(n), nil
}
facility, priority := "user", "notice"
if i := strings.IndexRune(str, '.'); i > 0 {
facility, priority = str[:i], str[i+1:]
} else {
priority = str
}
facility = strings.ToLower(facility)
priority = strings.ToLower(priority)
var p syslog.Priority
switch facility {
case "kern":
p |= syslog.LOG_KERN
case "user":
p |= syslog.LOG_USER
case "mail":
p |= syslog.LOG_MAIL
case "daemon":
p |= syslog.LOG_DAEMON
case "auth":
p |= syslog.LOG_AUTH
case "syslog":
p |= syslog.LOG_SYSLOG
case "lpr":
p |= syslog.LOG_LPR
case "news":
p |= syslog.LOG_NEWS
case "uucp":
p |= syslog.LOG_UUCP
case "cron":
p |= syslog.LOG_CRON
case "authpriv":
p |= syslog.LOG_AUTHPRIV
case "ftp":
p |= syslog.LOG_FTP
case "local0":
p |= syslog.LOG_LOCAL0
case "local1":
p |= syslog.LOG_LOCAL1
case "local2":
p |= syslog.LOG_LOCAL2
case "local3":
p |= syslog.LOG_LOCAL3
case "local4":
p |= syslog.LOG_LOCAL4
case "local5":
p |= syslog.LOG_LOCAL5
case "local6":
p |= syslog.LOG_LOCAL6
case "local7":
p |= syslog.LOG_LOCAL7
default:
return 0, fmt.Errorf("invalid facility %q", facility)
}
switch priority {
case "emerg":
p |= syslog.LOG_EMERG
case "alert":
p |= syslog.LOG_ALERT
case "crit":
p |= syslog.LOG_CRIT
case "err":
p |= syslog.LOG_ERR
case "warning":
p |= syslog.LOG_WARNING
case "notice":
p |= syslog.LOG_NOTICE
case "info":
p |= syslog.LOG_INFO
case "debug":
p |= syslog.LOG_DEBUG
default:
return 0, fmt.Errorf("invalid priority %q", priority)
}
return p, nil
}
示例15: NewSyslogFormatter
func NewSyslogFormatter(format string) *SyslogFormatter {
hostname, _ := os.Hostname()
return &SyslogFormatter{NewPatFormatter(format), os.Getpid(), hostname, os.Args[0], syslog.Priority(1 << 3), DefaultSeverityMap}
}