當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。