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


Golang syslog.New函数代码示例

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


在下文中一共展示了New函数的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: NewSysLogger

func NewSysLogger(conf Config) (Logger, error) {
	debugW, err := syslog.New(syslog.LOG_MAIL|syslog.LOG_DEBUG, appname)
	if err != nil {
		return nil, err
	}

	infoW, err := syslog.New(syslog.LOG_MAIL|syslog.LOG_INFO, appname)
	if err != nil {
		return nil, err
	}

	warnW, err := syslog.New(syslog.LOG_MAIL|syslog.LOG_WARNING, appname)
	if err != nil {
		return nil, err
	}

	errorW, err := syslog.New(syslog.LOG_MAIL|syslog.LOG_ERR, appname)
	if err != nil {
		return nil, err
	}

	sev, err := SeverityFromString(conf.Severity)
	if err != nil {
		return nil, err
	}

	return &sysLogger{sev, debugW, infoW, warnW, errorW}, nil
}
开发者ID:huhoo,项目名称:vulcand,代码行数:28,代码来源:syslog.go

示例3: main

func main() {
	flag.Usage = usage
	flag.Parse()
	flag.Visit(func(f *flag.Flag) {
		switch f.Name {
		case "C":
			setLogLevel(*level)
		}
	})

	var err error
	logger, err = syslog.New(0, "")
	ck(err)

	if *kern {
		logger.Notice("KLOGD: started with Kernel ring buffer as log source\n")
		kctl(1, 0)
	} else {
		fd, err = os.Open("/proc/kmsg")
		ck(err)
		logger.Notice("KLOGD: started with /proc/kmsg as log source\n")
	}

	logger.Close()
	logger, err = syslog.New(syslog.LOG_KERN, "Kernel")
	ck(err)

	sigCh := make(chan os.Signal)
	var sigs []os.Signal
	for i := syscall.Signal(-1); i != syscall.SIGCHLD; i++ {
		sigs = append(sigs, i)
	}
	signal.Notify(sigCh, sigs...)

	readCh := make(chan string)
	go reader(readCh)

loop:
	for {
		select {
		case <-sigCh:
			break loop
		case str := <-readCh:
			log(str)
		}
	}

	logger.Notice("KLOGD: Daemon exiting......\n")
	if *kern {
		kctl(7, 0)
		kctl(0, 0)
	} else {
		setLogLevel(7)
		fd.Close()
	}
	os.Exit(1)
}
开发者ID:qeedquan,项目名称:misc_utilities,代码行数:57,代码来源:klogd.go

示例4: Handle

func (handler *SyslogHandler) Handle(record *Record) error {

	if handler.writter == nil {
		writter, err := syslog.New(handler.Facility|handler.Severity, handler.Tag)

		if err != nil {
			return err
		}
		handler.writter = writter
	}

	msg := handler.Formatter.Format(record)

	switch record.Level {
	case EMERGENCY:
		return handler.writter.Emerg(msg)
	case ALERT:
		return handler.writter.Alert(msg)
	case CRITICAL:
		return handler.writter.Crit(msg)
	case ERROR:
		return handler.writter.Err(msg)
	case WARNING:
		return handler.writter.Warning(msg)
	case NOTICE:
		return handler.writter.Notice(msg)
	case INFO:
		return handler.writter.Info(msg)
	default:
		return handler.writter.Debug(msg)
	}
}
开发者ID:delicb,项目名称:logging,代码行数:32,代码来源:syslog_handler.go

示例5: main

func main() {
	// options
	var bind, backend, logTo string
	var buffer uint
	var daemon bool
	flag.StringVar(&bind, "bind", ":8002", "locate ip and port")
	flag.StringVar(&backend, "backend", "127.0.0.1:8003", "backend server ip and port")
	flag.StringVar(&logTo, "logTo", "stdout", "stdout or syslog")
	flag.UintVar(&buffer, "buffer", 4096, "buffer size")
	flag.BoolVar(&daemon, "daemon", false, "run as daemon process")
	flag.Parse()

	log.SetOutput(os.Stdout)
	if logTo == "syslog" {
		w, err := syslog.New(syslog.LOG_INFO, "portproxy")
		if err != nil {
			log.Fatal(err)
		}
		log.SetOutput(w)
	}

	if daemon == true {
		godaemon.MakeDaemon(&godaemon.DaemonAttr{})
	}

	p := New(bind, backend, uint32(buffer))
	log.Println("portproxy started.")
	go p.Start()
	waitSignal()
}
开发者ID:chenzhe07,项目名称:portproxy,代码行数:30,代码来源:main.go

示例6: main

func main() {
	var faddr, baddr, cryptoMethod, secret, logTo string
	var clientMode bool
	flag.StringVar(&logTo, "logto", "stdout", "stdout or syslog")
	flag.StringVar(&faddr, "listen", ":9001", "host:port qtunnel listen on")
	flag.StringVar(&baddr, "backend", "127.0.0.1:6400", "host:port of the backend")
	flag.StringVar(&cryptoMethod, "crypto", "rc4", "encryption method")
	flag.StringVar(&secret, "secret", "secret", "password used to encrypt the data")
	flag.BoolVar(&clientMode, "clientmode", false, "if running at client mode")
	flag.Parse()

	log.SetOutput(os.Stdout)
	if logTo == "syslog" {
		w, err := syslog.New(syslog.LOG_INFO, "qtunnel")
		if err != nil {
			log.Fatal(err)
		}
		log.SetOutput(w)
	}

	t := tunnel.NewTunnel(faddr, baddr, clientMode, cryptoMethod, secret, 4096)
	log.Println("qtunnel started.")
	go t.Start()
	waitSignal()
}
开发者ID:xiaobodu,项目名称:qtunnel,代码行数:25,代码来源:main.go

示例7: main

func main() {
	kingpin.Version("2.1.0")
	kingpin.Parse()

	sl, err := syslog.New(syslog.LOG_NOTICE|syslog.LOG_LOCAL0, "[varnish-purge-proxy]")
	defer sl.Close()
	if err != nil {
		log.Println("Error writing to syslog")
	} else {
		log.SetFlags(0)
		log.SetOutput(sl)
	}

	if len(*tags) == 0 {
		fmt.Println("No tags specified")
		return
	}

	region, err = ec2metadata.New(session.New()).Region()
	if err != nil {
		log.Printf("Unable to retrieve the region from the EC2 instance %v\n", err)
	}

	// Set up access to ec2
	svc := ec2.New(session.New(), &aws.Config{Region: &region})

	go serveHTTP(*port, *listen, svc)

	select {}
}
开发者ID:BashtonLtd,项目名称:varnish-purge-proxy,代码行数:30,代码来源:varnish-purge-proxy.go

示例8: SetupLogging

func SetupLogging() {
	syslg, err := syslog.New(syslog.LOG_ERR|syslog.LOG_DAEMON, "paperless")
	if err != nil {
		log.Fatal("Creating a syslog logger failed")
	}
	log.SetOutput(syslg)
}
开发者ID:kopoli,项目名称:paperless,代码行数:7,代码来源:logging.go

示例9: main

func main() {

	bind := flag.String("bind", "0.0.0.0:8080", "address to bind http server to")
	useSyslog := flag.Bool("syslog", false, "log to syslog")
	flag.Parse()

	if *useSyslog {
		logwriter, err := syslog.New(syslog.LOG_NOTICE, "todo")
		if err == nil {
			log.SetOutput(logwriter)
		}
	}

	log.Print("constructing service")
	svc, err := todo.NewTodoService(*bind)
	if err != nil {
		log.Println(err)
		os.Exit(1)
	}

	log.Print("migrating")

	if err = svc.Migrate(); err != nil {
		log.Println(err)
		os.Exit(1)
	}

	log.Print("running service")
	if err := svc.Run(); err != nil {
		log.Println(err)
		os.Exit(1)
	}
}
开发者ID:benschw,项目名称:vault-todo,代码行数:33,代码来源:main.go

示例10: main

// MAIN
func main() {
	parseCommandLine()

	t, err := tail.TailFile(accessLog, tail.Config{Follow: true, ReOpen: true, MustExist: false})
	if err != nil {
		panic(err)
	}

	hits := make(chan *loghit.LogHit)
	defer close(hits)
	errors := make(chan error)
	defer close(errors)

	for i := 0; i < *parserRoutines; i++ {
		go parseLines(t.Lines, hits, errors)
	}

	for i := 0; i < *posterRoutines; i++ {
		go postStats(*statPrefix, ezKey, hits)
	}

	logWriter, err := syslog.New(syslog.LOG_ERR, "nginx2stathat")
	if err != nil {
		panic(err)
	}

	for err := range errors {
		logWriter.Err(err.Error())
	}
}
开发者ID:hgfischer,项目名称:nginx2stathat,代码行数:31,代码来源:nginx2stathat.go

示例11: init

func init() {
	LogWriter, SyslogError = syslog.New(syslog.LOG_INFO, "paxrat")
	if SyslogError != nil {
		// TODO: We should continue running and log to STDOUT instead using same LogWriter interface
		fmt.Println(SyslogError)
		os.Exit(0) // Exit cleanly for dpkg
	}
	InotifyFlags = (inotify.IN_DONT_FOLLOW | inotify.IN_ATTRIB |
		inotify.IN_CREATE | inotify.IN_DELETE_SELF | inotify.IN_MOVE_SELF |
		inotify.IN_MOVED_TO)
	InotifyDirFlags = (inotify.IN_DONT_FOLLOW | inotify.IN_CREATE |
		inotify.IN_DELETE_SELF | inotify.IN_MOVE_SELF | inotify.IN_MOVED_TO)
	Conf = new(Config)
	flag.StringVar(&configvar, "c", "/etc/paxrat/paxrat.conf",
		"Pax flags configuration file")
	flag.BoolVar(&testvar, "t", false,
		"Test the config file and then exit")
	flag.BoolVar(&xattrvar, "x", false,
		"Force use of xattr to set PaX flags")
	flag.BoolVar(&watchvar, "w", false,
		"Run paxrat in watch mode")
	flag.StringVar(&flagsvar, "s", "",
		"Set PaX flags for a single binary (must also specify binary)")
	flag.BoolVar(&nonrootvar, "n", false,
		"Set nonroot variable for a single binary (needed to set flags on a non-root owned binary)")
	flag.BoolVar(&nodivertvar, "d", false,
		"Disable checking for dpkg-divert original path (generally this should be enabled)")
	flag.StringVar(&binaryvar, "b", "",
		"Path to a binary for use with set option")
	flag.StringVar(&replacementvar, "r", "",
		"Replacement string to use in binary path JSON (ex: $REPLACEMENT in binary path)")
}
开发者ID:subgraph,项目名称:paxrat,代码行数:32,代码来源:paxrat.go

示例12: main

func main() {
	var prio, tag string
	flag.StringVar(&prio, "p", "user.notice", "set priority")
	user, err := user.Current()
	if err == nil {
		tag = user.Username
	}
	flag.StringVar(&tag, "t", tag, "use tag to prefix every message")
	flag.Usage = usage
	flag.Parse()

	value, err := lookup(prio)
	ck(err)

	logger, err := syslog.New(value, tag)
	ck(err)

	var buf []byte
	if flag.NArg() < 1 {
		buf, err = ioutil.ReadAll(os.Stdin)
		ck(err)
	} else {
		buf = []byte(strings.Join(flag.Args(), " "))
	}

	_, err = logger.Write(buf)
	ek(err)
	ek(logger.Close())
	os.Exit(status)
}
开发者ID:qeedquan,项目名称:misc_utilities,代码行数:30,代码来源:logger.go

示例13: MessageLogger

// MessageLogger log a message to system log
func MessageLogger(syslogType syslog.Priority, message string) {
	if (runtime.GOOS != "nacl") && (runtime.GOOS != "plan9") && (runtime.GOOS != "windows") { // If we are using a syslog supported OS
		syslogLogger, _ := syslog.New(syslogType, "Metis") // Create a new syslogLogger that logs as error as LOG_USER
		syslogLogger.Write([]byte(message))                // Write the message
		syslogLogger.Close()                               // Close the logger
	}
}
开发者ID:StroblIndustries,项目名称:metis-pkg,代码行数:8,代码来源:utils.go

示例14: init

func init() {

	f, err := os.OpenFile("/var/log/hello.log", os.O_RDWR|os.O_CREATE|os.O_APPEND, 0666)
	if err != nil {
		fmt.Println("error opening file: %v", err)
	}
	defer f.Close()

	log.SetOutput(f)
	log.Println("This is a test log entry")

	//log2Syslog
	logwriter, e := syslog.New(syslog.LOG_NOTICE, "hello")
	if e == nil {
		log.SetOutput(logwriter)
		log.Print("Initialization Complete!")
	}
	mWriter := io.MultiWriter(f, logwriter)

	data := []byte("Hello World MultiWriter!")

	n, err := mWriter.Write(data)

	if err == nil {
		fmt.Printf("Multi write %d bytes to two files simultaneously.\n", n)
	}

}
开发者ID:ismadeandres,项目名称:h,代码行数:28,代码来源:hello.go

示例15: newSyslogLogger

func newSyslogLogger() Logger {
	w, err := syslog.New(syslog.LOG_INFO, "tsuru")
	if err != nil {
		log.Fatal(err)
	}
	return &syslogLogger{w}
}
开发者ID:pombredanne,项目名称:tsuru,代码行数:7,代码来源:syslog_logger.go


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