當前位置: 首頁>>代碼示例>>Golang>>正文


Golang syslog.Priority函數代碼示例

本文整理匯總了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()
}
開發者ID:dustin,項目名稱:logexec,代碼行數:30,代碼來源:logexec.go

示例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),
	}
}
開發者ID:gh0std4ncer,項目名稱:nomad,代碼行數:10,代碼來源:parser.go

示例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")
}
開發者ID:vito,項目名稱:garden-linux-release,代碼行數:16,代碼來源:syslog.go

示例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
}
開發者ID:nanjishidu,項目名稱:log,代碼行數:25,代碼來源:syslog.go

示例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
}
開發者ID:csimplestring,項目名稱:go-log,代碼行數:9,代碼來源:syslog.go

示例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
}
開發者ID:devsaurin,項目名稱:mongo-tools,代碼行數:11,代碼來源:syslog.go

示例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
}
開發者ID:neeravkumar,項目名稱:consul-deb,代碼行數:9,代碼來源:unix.go

示例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
}
開發者ID:rightscale,項目名稱:rlog,代碼行數:59,代碼來源:syslogModule.go

示例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
}
開發者ID:ChongFeng,項目名稱:beats,代碼行數:10,代碼來源:syslog_unix.go

示例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")
	}
}
開發者ID:littleyang,項目名稱:vitess,代碼行數:10,代碼來源:syslogger_test.go

示例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
}
開發者ID:quixoten,項目名稱:vault,代碼行數:13,代碼來源:unix.go

示例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
}
開發者ID:hashicorp,項目名稱:consul-replicate,代碼行數:16,代碼來源:unix.go

示例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)
	}
}
開發者ID:jonsen,項目名稱:packetbeat,代碼行數:17,代碼來源:log_unix.go

示例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
}
開發者ID:qeedquan,項目名稱:misc_utilities,代碼行數:84,代碼來源:logger.go

示例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}
}
開發者ID:jameswei,項目名稱:timber,代碼行數:4,代碼來源:syslog_formatter.go


注:本文中的log/syslog.Priority函數示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。