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


Golang syslog.NewLogger函数代码示例

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


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

示例1: main

func main() {
	var config shuttle.ShuttleConfig
	var err error

	config.ParseFlags()

	if config.PrintVersion {
		fmt.Println(shuttle.VERSION)
		os.Exit(0)
	}

	if !config.UseStdin() {
		shuttle.ErrLogger.Fatalln("No stdin detected.")
	}

	if config.LogToSyslog {
		shuttle.Logger, err = syslog.NewLogger(syslog.LOG_INFO|syslog.LOG_SYSLOG, 0)
		if err != nil {
			log.Fatalf("Unable to setup syslog logger: %s\n", err)
		}
		shuttle.ErrLogger, err = syslog.NewLogger(syslog.LOG_ERR|syslog.LOG_SYSLOG, 0)
		if err != nil {
			log.Fatalf("Unable to setup syslog error logger: %s\n", err)
		}
	}

	reader, deliverableBatches, programStats, batchWaiter, outletWaiter := MakeBasicBits(config)

	// Blocks until closed
	reader.Read(os.Stdin)

	// Shutdown everything else.
	Shutdown(reader.Outbox, programStats.Input, deliverableBatches, batchWaiter, outletWaiter)
}
开发者ID:jcheng5,项目名称:log-shuttle,代码行数:34,代码来源:main.go

示例2: NewSysLogger

func NewSysLogger() *SysLogger {
	sl := &SysLogger{
		loggers: make(map[LogLevel]*log.Logger),
	}
	sl.loggers[DEBUG], _ = syslog.NewLogger(syslog.LOG_DEBUG, log.LstdFlags)
	sl.loggers[INFO], _ = syslog.NewLogger(syslog.LOG_INFO, log.LstdFlags)
	sl.loggers[WARN], _ = syslog.NewLogger(syslog.LOG_WARNING, log.LstdFlags)
	sl.loggers[ERROR], _ = syslog.NewLogger(syslog.LOG_ERR, log.LstdFlags)
	return sl
}
开发者ID:Norbell,项目名称:dyndnscd,代码行数:10,代码来源:log.go

示例3: NewJobManager

func NewJobManager() (*JobManager, error) {
	var err error
	jm := JobManager{Shell: "/bin/sh"}
	Logger, err = syslog.NewLogger(syslog.LOG_NOTICE|syslog.LOG_CRON, 0)
	if err != nil {
		return nil, &JobberError{What: "Couldn't make Syslog logger.", Cause: err}
	}
	ErrLogger, err = syslog.NewLogger(syslog.LOG_ERR|syslog.LOG_CRON, 0)
	if err != nil {
		return nil, &JobberError{What: "Couldn't make Syslog logger.", Cause: err}
	}
	jm.loadedJobs = false
	jm.jobRunner = NewJobRunnerThread()
	return &jm, nil
}
开发者ID:se77en,项目名称:jobber,代码行数:15,代码来源:job_manager.go

示例4: getSysLogger

func getSysLogger() *log.Logger {
	logger, err := syslog.NewLogger(syslog.LOG_INFO, log.LstdFlags)
	if err != nil {
		log.Fatal(err)
	}
	return logger
}
开发者ID:rif,项目名称:golang-stuff,代码行数:7,代码来源:log.go

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

示例6: main

func main() {

	mode = flag.String("m", "tcp", "portguard work mode: tcp or udp")
	debug = flag.Bool("d", false, "debug mode, print log to stderr")
	portCacheDuration = flag.Int64("duration", 120, "port cache duration")

	flag.Usage = usage
	flag.Parse()

	if *debug {
		mainLogger = log.New(io.Writer(os.Stderr), "", log.Ldate|log.Lmicroseconds)
	} else {
		var err error
		if mainLogger, err = syslog.NewLogger(syslog.LOG_ERR|syslog.LOG_LOCAL7, log.Ldate|log.Lmicroseconds); err != nil {
			logMain(true, "open syslog failed:%s", err.Error())
		}
	}

	args := flag.Args()
	if len(args) > 0 {
		readConfigFile(args[0])
	}
	configGuard()
	configEcho()

	if *mode == "tcp" {
		tcpGuard()
	} else if *mode == "udp" {
		udpGuard()
	} else {
		fmt.Fprintf(os.Stderr, "don't support mode: %s\n", *mode)
	}
}
开发者ID:postfix,项目名称:portguard,代码行数:33,代码来源:guard.go

示例7: ToSyslog

// Send debug message to syslog facility
func ToSyslog() {
	syslogger, err := syslog.NewLogger(syslog.LOG_ERR|syslog.LOG_USER, 0)
	if err == nil {
		debugLogger = syslogger
		prefixFormat = formatMap[false]
	}
}
开发者ID:ttacon,项目名称:cluefs,代码行数:8,代码来源:debug.go

示例8: HttpServer

// Factory method for application
// Makes it possible to do integration testing.
func HttpServer() *echo.Echo {
	// Initialize global syslog logger
	if l, err := syslog.NewLogger(syslog.LOG_NOTICE|syslog.LOG_LOCAL0, 0); err != nil {
		panic("gdo: failed to initialize syslog logger: " + err.Error())
	} else {
		logger = l
	}

	// Setup middleware
	e := echo.New()
	e.Use(middleware.RequestID)               // Put that first so loggers can log request id
	e.Use(em.Logger)                          // Log to console
	e.Use(middleware.HttpLogger(logger))      // Log to syslog
	e.Use(gdm.DOClientInitializer(*dumpFlag)) // Initialize DigitalOcean API client

	// Setup routes
	SetupDropletsRoutes(e.Group("/droplets"))
	SetupDropletActionsRoutes(e.Group("/droplets/:id/actions"))
	SetupImagesRoutes(e.Group("/images"))
	SetupImageActionsRoutes(e.Group("/images/:id/actions"))
	SetupActionsRoutes(e.Group("/actions"))
	SetupKeysRoutes(e.Group("/keys"))
	SetupRegionsRoutes(e.Group("/regions"))
	SetupSizesRoutes(e.Group("/sizes"))

	// We're done
	return e
}
开发者ID:cdwilhelm,项目名称:self-service-plugins,代码行数:30,代码来源:main.go

示例9: newSyslogger

func newSyslogger(p syslog.Priority) *log.Logger {
	logger, err := syslog.NewLogger(p, 0)
	if err != nil {
		panic(err)
	}
	return logger
}
开发者ID:jimenezrick,项目名称:crap,代码行数:7,代码来源:log.go

示例10: mustLog

func mustLog(p syslog.Priority) *log.Logger {
	p = p | syslog.LOG_DAEMON
	l, err := syslog.NewLogger(p, logFlags)
	if err != nil {
		panic("Failed to set up logger: " + err.Error())
	}
	return l
}
开发者ID:postfix,项目名称:arx,代码行数:8,代码来源:server.go

示例11: initLogger

func initLogger() *log.Logger {
	if configuration.LogToSyslog {
		l, _ := syslog.NewLogger(syslog.LOG_INFO, log.LstdFlags)
		return l
	} else {
		return log.New(os.Stdout, "surl ", log.LstdFlags)
	}
}
开发者ID:vosst,项目名称:surl,代码行数:8,代码来源:surl.go

示例12: init

func init() {
	var err error
	log.SetFlags(LOG_FLAGS)
	Logger, err = syslog.NewLogger(LOG_PRIORITY, LOG_FLAGS)
	if err != nil {
		log.Fatal(err)
	}

}
开发者ID:beres,项目名称:gofaxip,代码行数:9,代码来源:logger.go

示例13: initLogger

func initLogger(slog bool) {
	if slog {
		l, err := syslog.NewLogger(syslog.LOG_INFO, 0)
		if err != nil {
			corelog.Fatalf("Can't initialize logger: %v", err)
		}
		log = l
	}
}
开发者ID:kkumar86,项目名称:cbfs,代码行数:9,代码来源:logging.go

示例14: NewRealLogger

func NewRealLogger() *RealLogger {
	logger := log.New(os.Stdout, "", log.LstdFlags)
	infoSysLogger, _ := syslog.NewLogger(syslog.LOG_INFO, log.LstdFlags)

	return &RealLogger{
		logger:        logger,
		infoSysLogger: infoSysLogger,
	}
}
开发者ID:Zhann,项目名称:hm9000,代码行数:9,代码来源:logger.go

示例15: main

func main() {
	var (
		configFile string
		dry        bool
	)
	logger, err := syslog.NewLogger(syslog.LOG_INFO, stdlog.LstdFlags)
	if err != nil {
		stdlog.Fatal(err)
	}
	log.SetLogger(logger)
	flag.StringVar(&configFile, "config", "/etc/tsuru/tsuru.conf", "tsuru config file")
	flag.BoolVar(&dry, "dry", false, "dry-run: does not start the agent (for testing purposes)")
	flag.Parse()
	err = config.ReadConfigFile(configFile)
	if err != nil {
		fatal(err)
	}
	connString, err := config.GetString("database:url")
	if err != nil {
		fatal(err)
	}
	dbName, err := config.GetString("database:name")
	if err != nil {
		fatal(err)
	}
	db.Session, err = db.Open(connString, dbName)
	if err != nil {
		fatal(err)
	}
	defer db.Session.Close()
	fmt.Printf("Connected to MongoDB server at %s.\n", connString)
	fmt.Printf("Using the database %q.\n\n", dbName)

	if !dry {
		provisioner, err := config.GetString("provisioner")
		if err != nil {
			fmt.Printf("Warning: %q didn't declare a provisioner, using default provisioner.\n", configFile)
			provisioner = "juju"
		}
		app.Provisioner, err = provision.Get(provisioner)
		if err != nil {
			fatal(err)
		}
		fmt.Printf("Using %q provisioner.\n\n", provisioner)

		qServer, err := config.GetString("queue-server")
		if err != nil {
			fatal(err)
		}
		fmt.Printf("Connected to queue server at %s.\n", qServer)
		go handleMessages()
		ticker := time.Tick(time.Minute)
		fmt.Println("tsuru collector agent started...")
		jujuCollect(ticker)
	}
}
开发者ID:elimisteve,项目名称:tsuru,代码行数:56,代码来源:main.go


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