当前位置: 首页>>代码示例>>Golang>>正文


Golang syslog.Dial函数代码示例

本文整理汇总了Golang中log/syslog.Dial函数的典型用法代码示例。如果您正苦于以下问题:Golang Dial函数的具体用法?Golang Dial怎么用?Golang Dial使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。


在下文中一共展示了Dial函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。

示例1: newWriter

func newWriter(addr string) (io.Writer, error) {
	u, err := url.Parse(addr)
	if u.Scheme != "syslog" {
		return nil, fmt.Errorf("unsupported scheme '%v' currently supported only 'syslog'", u.Scheme)
	}
	pr, err := parseSyslogPriority(u)
	if err != nil {
		return nil, err
	}

	var w io.Writer
	if u.Host != "" {
		w, err = syslog.Dial("udp", u.Host, pr, SyslogTag)
	} else if u.Path != "" {
		w, err = syslog.Dial("unixgram", u.Path, pr, SyslogTag)
	} else if u.Host == "" && u.Path == "" {
		w, err = syslog.Dial("", "", pr, SyslogTag)
	} else {
		return nil, fmt.Errorf("unsupported address format: %v", addr)
	}
	if err != nil {
		return nil, err
	}
	return &prefixWriter{p: []byte(parsePrefix(u)), w: w}, nil
}
开发者ID:huhoo,项目名称:vulcand,代码行数:25,代码来源:trace.go

示例2: StatsAndLogging

// StatsAndLogging constructs a Statter and an AuditLogger based on its config
// parameters, and return them both. Crashes if any setup fails.
// Also sets the constructed AuditLogger as the default logger, and configures
// the cfssl, mysql, and grpc packages to use our logger.
// This must be called before any gRPC code is called, because gRPC's SetLogger
// doesn't use any locking.
func StatsAndLogging(statConf StatsdConfig, logConf SyslogConfig) (metrics.Statter, blog.Logger) {
	stats, err := metrics.NewStatter(statConf.Server, statConf.Prefix)
	FailOnError(err, "Couldn't connect to statsd")

	tag := path.Base(os.Args[0])
	syslogger, err := syslog.Dial(
		"",
		"",
		syslog.LOG_INFO, // default, not actually used
		tag)
	FailOnError(err, "Could not connect to Syslog")
	syslogLevel := int(syslog.LOG_INFO)
	if logConf.SyslogLevel != 0 {
		syslogLevel = logConf.SyslogLevel
	}
	logger, err := blog.New(syslogger, logConf.StdoutLevel, syslogLevel)
	FailOnError(err, "Could not connect to Syslog")

	_ = blog.Set(logger)
	cfsslLog.SetLogger(cfsslLogger{logger})
	_ = mysql.SetLogger(mysqlLogger{logger})
	grpclog.SetLogger(grpcLogger{logger})

	return stats, logger
}
开发者ID:jfrazelle,项目名称:boulder,代码行数:31,代码来源:shell.go

示例3: Dial

// Dial establishes a connection to the log daemon by passing through
// the parameters to the syslog.Dial method.
// See http://golang.org/pkg/log/syslog/#Dial
func Dial(network, raddr string, tag string, stats statsd.Statter) (*AuditLogger, error) {
	syslogger, err := syslog.Dial(network, raddr, syslog.LOG_INFO|syslog.LOG_LOCAL0, tag)
	if err != nil {
		return nil, err
	}
	return NewAuditLogger(syslogger, stats)
}
开发者ID:jgillula,项目名称:boulder,代码行数:10,代码来源:audit-logger.go

示例4: initSyslog

// initSyslog creates a connection to syslog and stores the handler in ctx
func initSyslog(orig_logctx Logging) (logctx Logging, err error) {
	defer func() {
		if e := recover(); e != nil {
			err = fmt.Errorf("mig.initSyslog() -> %v", e)
		}
	}()

	logctx = orig_logctx
	if logctx.Host == "" {
		panic("Syslog host is missing")
	}
	if logctx.Port < 1 {
		panic("Syslog port is missing")
	}
	if logctx.Protocol == "" {
		panic("Syslog protocol is missing")
	}
	dialaddr := logctx.Host + ":" + fmt.Sprintf("%d", logctx.Port)
	logctx.syslogfd, err = syslog.Dial(logctx.Protocol, dialaddr, syslog.LOG_LOCAL3|syslog.LOG_INFO, "mig_scheduler")
	if err != nil {
		panic(err)
	}
	if err != nil {
		panic(err)
	}
	return
}
开发者ID:jeffbryner,项目名称:mig,代码行数:28,代码来源:logging.go

示例5: DialSyslogLogger

func DialSyslogLogger(network, address, tag string, priority Priority) (Logger, error) {
	if wrt, err := syslog.Dial(network, address, syslogPriority(priority), tag); err == nil {
		return &SyslogLogger{writer: wrt}, nil
	} else {
		return nil, err
	}
}
开发者ID:itpkg,项目名称:log,代码行数:7,代码来源:syslog.go

示例6: New

func New(ctx logger.Context) (logger.Logger, error) {
	tag := ctx.Config["syslog-tag"]
	if tag == "" {
		tag = ctx.ContainerID[:12]
	}

	proto, address, err := parseAddress(ctx.Config["syslog-address"])
	if err != nil {
		return nil, err
	}

	facility, err := parseFacility(ctx.Config["syslog-facility"])
	if err != nil {
		return nil, err
	}

	log, err := syslog.Dial(
		proto,
		address,
		facility,
		path.Base(os.Args[0])+"/"+tag,
	)
	if err != nil {
		return nil, err
	}

	return &Syslog{
		writer: log,
	}, nil
}
开发者ID:vito,项目名称:garden-linux-release,代码行数:30,代码来源:syslog.go

示例7: StatsAndLogging

// StatsAndLogging constructs a Statter and an AuditLogger based on its config
// parameters, and return them both. Crashes if any setup fails.
// Also sets the constructed AuditLogger as the default logger.
func StatsAndLogging(statConf StatsdConfig, logConf SyslogConfig) (metrics.Statter, blog.Logger) {
	stats, err := metrics.NewStatter(statConf.Server, statConf.Prefix)
	FailOnError(err, "Couldn't connect to statsd")

	tag := path.Base(os.Args[0])
	syslogger, err := syslog.Dial(
		"",
		"",
		syslog.LOG_INFO|syslog.LOG_LOCAL0, // default, overridden by log calls
		tag)
	FailOnError(err, "Could not connect to Syslog")
	stdoutLoglevel := int(syslog.LOG_DEBUG)
	if logConf.StdoutLevel != nil {
		stdoutLoglevel = *logConf.StdoutLevel
	}
	syslogLogLevel := int(syslog.LOG_DEBUG)
	if logConf.SyslogLevel != nil {
		syslogLogLevel = *logConf.SyslogLevel
	}
	logger, err := blog.New(syslogger, stdoutLoglevel, syslogLogLevel)
	FailOnError(err, "Could not connect to Syslog")

	_ = blog.Set(logger)
	cfsslLog.SetLogger(cfsslLogger{logger})
	_ = mysql.SetLogger(mysqlLogger{logger})

	return stats, logger
}
开发者ID:andrewrothstein,项目名称:boulder,代码行数:31,代码来源:shell.go

示例8: StatsAndLogging

// StatsAndLogging constructs a Statter and and AuditLogger based on its config
// parameters, and return them both. Crashes if any setup fails.
// Also sets the constructed AuditLogger as the default logger.
func StatsAndLogging(statConf StatsdConfig, logConf SyslogConfig) (statsd.Statter, *blog.AuditLogger) {
	stats, err := statsd.NewClient(statConf.Server, statConf.Prefix)
	FailOnError(err, "Couldn't connect to statsd")

	tag := path.Base(os.Args[0])
	syslogger, err := syslog.Dial(
		logConf.Network,
		logConf.Server,
		syslog.LOG_INFO|syslog.LOG_LOCAL0, // default, overridden by log calls
		tag)
	FailOnError(err, "Could not connect to Syslog")
	level := int(syslog.LOG_DEBUG)
	if logConf.StdoutLevel != nil {
		level = *logConf.StdoutLevel
	}
	auditlogger, err := blog.NewAuditLogger(syslogger, stats, level)
	FailOnError(err, "Could not connect to Syslog")
	// TODO(https://github.com/cloudflare/cfssl/issues/426):
	// CFSSL's log facility always prints to stdout. Ideally we should send a
	// patch that would allow us to have CFSSL use our log facility. In the
	// meantime, inhibit debug and info-level logs from CFSSL.
	cfsslLog.Level = cfsslLog.LevelWarning
	blog.SetAuditLogger(auditlogger)
	return stats, auditlogger
}
开发者ID:rf152,项目名称:boulder,代码行数:28,代码来源:shell.go

示例9: main

func main() {
	//l3, err := syslog.New(syslog.LOG_ERR, "GoExample")
	l, err := syslog.Dial("tcp", "202.207.211.187:5140", syslog.LOG_ERR, "test perf") // connection to a log daemon
	defer l.Close()
	if err != nil {
		fmt.Print(err)
		log.Fatal("error")
	}

	//l3.Emerg("emergency")
	//l3.Alert("alert")
	//l3.Crit("critical")
	//l3.Err("error")
	//l3.Warning("warning")
	//l3.Notice("notice")
	for i := 0; i < 100000; i++ {
		s := fmt.Sprintf("%d 180.76.15.34 - - [28/Jun/2015:10:49:43 +0800] \"GET / HTTP/1.1\" 200 7783 \"-\" \"Mozilla/5.0 (compatible; Baiduspider/2.0; +http://www.baidu.com/search/spider.html)\"\n", uint64(i))
		l.Info(s)

		if i%1000 == 0 {
			t := time.Now()
			fmt.Printf("%02d:%02d:%02d:%d\n", t.Hour(), t.Minute(), t.Second(), uint64(i))
		}
		time.Sleep(200000)
	}
	//l3.Debug("debug")
	//l3.Write([]byte("write"))

}
开发者ID:alliciga,项目名称:SAFF,代码行数:29,代码来源:ts01.go

示例10: main

func main() {
	address := flag.String("addr", ":5514", "syslog server")
	level := flag.String("level", "info", "syslog level")
	message := flag.String("msg", "", "syslog message")
	flag.Parse()

	logWriter, err := syslog.Dial("udp", *address, syslog.LOG_ERR, "logger")
	defer logWriter.Close()
	if err != nil {
		log.Fatal("error")
	}

	switch *level {
	case "emerg":
		logWriter.Emerg(*message)
	case "alert":
		logWriter.Alert(*message)
	case "crit":
		logWriter.Crit(*message)
	case "err":
		logWriter.Err(*message)
	case "warning":
		logWriter.Warning(*message)
	case "notice":
		logWriter.Notice(*message)
	case "info":
		logWriter.Info(*message)
	case "debug":
		logWriter.Debug(*message)
	}
}
开发者ID:haccht,项目名称:syslog_tools,代码行数:31,代码来源:mylogger.go

示例11: New

// New creates a syslog logger using the configuration passed in on
// the context. Supported context configuration variables are
// syslog-address, syslog-facility, & syslog-tag.
func New(ctx logger.Context) (logger.Logger, error) {
	tag, err := loggerutils.ParseLogTag(ctx, "{{.ID}}")
	if err != nil {
		return nil, err
	}

	proto, address, err := parseAddress(ctx.Config["syslog-address"])
	if err != nil {
		return nil, err
	}

	facility, err := parseFacility(ctx.Config["syslog-facility"])
	if err != nil {
		return nil, err
	}

	log, err := syslog.Dial(
		proto,
		address,
		facility,
		path.Base(os.Args[0])+"/"+tag,
	)
	if err != nil {
		return nil, err
	}

	return &syslogger{
		writer: log,
	}, nil
}
开发者ID:DaveDaCoda,项目名称:docker,代码行数:33,代码来源:syslog.go

示例12: InitDBLog

func InitDBLog() error {

	var err error
	if SysLog, err = syslog.Dial("udp", SLOG_ADDR+":"+SLOG_PORT, syslog.LOG_NOTICE, "goDB"); err != nil {
		return err
	}
	return nil
}
开发者ID:kelixin,项目名称:goProbe,代码行数:8,代码来源:DBLog.go

示例13: Open

func (s *syslogWriter) Open(name string) error {
	w, err := syslog.Dial(s.scheme, s.addr, syslog.LOG_LOCAL0|syslog.LOG_NOTICE, name)
	if err != nil {
		return err
	}
	s.w = w
	return nil
}
开发者ID:rainycape,项目名称:governator,代码行数:8,代码来源:syslog_writer.go

示例14: createLogger

func createLogger() *log.Logger {
	syslogWriter, err := syslog.Dial("udp", global.Config.SysLogIP, syslog.LOG_SYSLOG, "sorcery")
	if err != nil {
		panic(err)
	}

	return log.New(syslogWriter, "EventSauce: ", log.Lshortfile)
}
开发者ID:nicholasjackson,项目名称:sorcery,代码行数:8,代码来源:main.go

示例15: 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


注:本文中的log/syslog.Dial函数示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。