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


Golang log.SetHandler函數代碼示例

本文整理匯總了Golang中github.com/apex/log.SetHandler函數的典型用法代碼示例。如果您正苦於以下問題:Golang SetHandler函數的具體用法?Golang SetHandler怎麽用?Golang SetHandler使用的例子?那麽, 這裏精選的函數代碼示例或許可以為您提供幫助。


在下文中一共展示了SetHandler函數的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。

示例1: main

func main() {
	flag.Parse()
	log.SetHandler(text.New(os.Stderr))
	log.SetLevel(log.DebugLevel)

	// set up producer
	svc := kinesis.New(session.New())
	p := producer.New(producer.Config{
		StreamName:  *stream,
		BacklogSize: 500,
		Client:      svc,
	})
	p.Start()

	// open data file
	f, err := os.Open("/tmp/users.txt")
	if err != nil {
		log.Fatal("Cannot open users.txt file")
	}
	defer f.Close()

	// loop over file data
	b := bufio.NewScanner(f)
	for b.Scan() {
		err := p.Put(b.Bytes(), "site")

		if err != nil {
			log.WithError(err).Fatal("error producing")
		}
	}

	p.Stop()
}
開發者ID:harlow,項目名稱:kinesis-connectors,代碼行數:33,代碼來源:main.go

示例2: main

func main() {
	log.SetHandler(cli.Default)

	if err := root.Command.Execute(); err != nil {
		log.Fatalf("Error: %s", err)
	}
}
開發者ID:elizar,項目名稱:apex,代碼行數:7,代碼來源:main.go

示例3: main

func main() {
	log.SetHandler(cli.Default)

	args := os.Args[1:]

	// Cobra does not (currently) allow us to pass flags for a sub-command
	// as if they were arguments, so we inject -- here after the first TF command.
	// TODO(tj): replace with a real solution and send PR to Cobra #251
	if len(os.Args) > 1 && os.Args[1] == "infra" {
		off := 1

	out:
		for i, a := range args {
			for _, cmd := range tf {
				if a == cmd {
					off = i
					break out
				}
			}
		}

		args = append(args[0:off], append([]string{"--"}, args[off:]...)...)
	}

	root.Command.SetArgs(args)

	if err := root.Command.Execute(); err != nil {
		log.Fatalf("Error: %s", err)
	}

	stats.Client.ConditionalFlush(500, 24*time.Hour)
}
開發者ID:Robh081956,項目名稱:apex,代碼行數:32,代碼來源:main.go

示例4: main

func main() {
	args, err := docopt.Parse(usage, nil, true, version, false)
	if err != nil {
		log.Fatalf("error: %s", err)
	}

	log.SetHandler(cli.Default)

	if l, err := log.ParseLevel(args["--log-level"].(string)); err == nil {
		log.SetLevel(l)
	}

	if args["help"].(bool) {
		showHelp(args["<topic>"])
		return
	}

	session := session.New(aws.NewConfig())

	project := &project.Project{
		Log:  log.Log,
		Path: ".",
	}

	if args["--dry-run"].(bool) {
		log.SetLevel(log.WarnLevel)
		project.Service = dryrun.New(session)
		project.Concurrency = 1
	} else {
		project.Service = lambda.New(session)
	}

	if dir, ok := args["--chdir"].(string); ok {
		if err := os.Chdir(dir); err != nil {
			log.Fatalf("error: %s", err)
		}
	}

	if err := project.Open(); err != nil {
		log.Fatalf("error opening project: %s", err)
	}

	switch {
	case args["list"].(bool):
		list(project)
	case args["deploy"].(bool):
		deploy(project, args["<name>"].([]string), args["--env"].([]string))
	case args["delete"].(bool):
		delete(project, args["<name>"].([]string), args["--yes"].(bool))
	case args["invoke"].(bool):
		invoke(project, args["<name>"].([]string), args["--verbose"].(bool), args["--async"].(bool))
	case args["rollback"].(bool):
		rollback(project, args["<name>"].([]string), args["<version>"])
	case args["build"].(bool):
		build(project, args["<name>"].([]string))
	case args["logs"].(bool):
		tail(project, args["<name>"].([]string), args["--filter"].(string))
	}
}
開發者ID:yuishug,項目名稱:apex,代碼行數:59,代碼來源:apex.go

示例5: main

func main() {
	log.SetHandler(cli.Default)

	if err := rootCmd.Execute(); err != nil {
		fmt.Fprintf(os.Stderr, "error: %s\n", err)
		os.Exit(1)
	}
}
開發者ID:herrhelms,項目名稱:apex,代碼行數:8,代碼來源:main.go

示例6: main

func main() {
	cli.Colors[log.DebugLevel] = 90
	cli.Colors[log.InfoLevel] = 32
	log.SetHandler(cli.New(os.Stdout))

	log.SetLevel(log.DebugLevel)

	cmd.Execute()
}
開發者ID:batulzii,項目名稱:ttntool,代碼行數:9,代碼來源:main.go

示例7: TestInfo

func TestInfo(t *testing.T) {
	h := memory.New()
	log.SetHandler(h)

	log.Infof("logged in %s", "Tobi")

	e := h.Entries[0]
	assert.Equal(t, e.Message, "logged in Tobi")
	assert.Equal(t, e.Level, log.InfoLevel)
}
開發者ID:leobcn,項目名稱:log,代碼行數:10,代碼來源:pkg_test.go

示例8: TestFielder

func TestFielder(t *testing.T) {
	h := memory.New()
	log.SetHandler(h)

	pet := &Pet{"Tobi", 3}
	log.WithFields(pet).Info("add pet")

	e := h.Entries[0]
	assert.Equal(t, log.Fields{"name": "Tobi", "age": 3}, e.Fields)
}
開發者ID:leobcn,項目名稱:log,代碼行數:10,代碼來源:pkg_test.go

示例9: init

func init() {
	//Default to console logging
	apexlog.SetHandler(cli.Default)

	//Upgrade to ElasticSearch if defined in ENV
	if os.Getenv("ES_ADDR") != "" {
		esClient := elastic.New(os.Getenv("ES_ADDR")) //"http://192.168.99.101:9200"
		esClient.HTTPClient = &http.Client{
			Timeout: 5 * time.Second,
		}

		e := es.New(&es.Config{
			Client:     esClient,
			BufferSize: 100,
		})

		t := text.New(os.Stderr)

		apexlog.SetHandler(multi.New(e, t))
	}
}
開發者ID:cyanly,項目名稱:gotrade,代碼行數:21,代碼來源:init.go

示例10: main

func main() {
	log.SetHandler(text.New(os.Stderr))

	ctx := log.WithFields(log.Fields{
		"app": "myapp",
		"env": "prod",
	})

	for range time.Tick(time.Second) {
		_ = work(ctx)
	}
}
開發者ID:leobcn,項目名稱:log,代碼行數:12,代碼來源:trace.go

示例11: hookBefore

func hookBefore(c *cli.Context) error {
	level := log.InfoLevel
	syslogLevel := syslog.LOG_INFO
	if c.Bool("verbose") {
		level = log.DebugLevel
		syslogLevel = syslog.LOG_DEBUG
	}
	log.SetLevel(level)
	log.SetHandler(text.New(os.Stderr))

	if c.String("syslog-server") != "" {
		server := strings.Split(c.String("syslog-server"), "://")

		if server[0] == "unix" {
			log.SetHandler(multi.New(text.New(os.Stderr), sysloghandler.New("", "", syslogLevel, "")))
		} else {
			if len(server) != 2 {
				log.Fatal("invalid syslog parameter")
			}
			log.SetHandler(multi.New(text.New(os.Stderr), sysloghandler.New(server[0], server[1], syslogLevel, "")))
		}
	}
	return nil
}
開發者ID:moul,項目名稱:ssh2docker,代碼行數:24,代碼來源:main.go

示例12: main

func main() {
	log.SetHandler(json.New(os.Stderr))

	ctx := log.WithFields(log.Fields{
		"file": "something.png",
		"type": "image/png",
		"user": "tobi",
	})

	for range time.Tick(time.Millisecond * 200) {
		ctx.Info("upload")
		ctx.Info("upload complete")
		ctx.Warn("upload retry")
		ctx.WithError(errors.New("unauthorized")).Error("upload failed")
	}
}
開發者ID:leobcn,項目名稱:log,代碼行數:16,代碼來源:json.go

示例13: main

func main() {
	log.SetHandler(multi.New(
		text.New(os.Stderr),
		kinesis.New("logs"),
	))

	ctx := log.WithFields(log.Fields{
		"file": "something.png",
		"type": "image/png",
		"user": "tobi",
	})

	for range time.Tick(time.Millisecond * 100) {
		ctx.Info("upload")
		ctx.Info("upload complete")
	}
}
開發者ID:leobcn,項目名稱:log,代碼行數:17,代碼來源:kinesis.go

示例14: TestServer_CheckConfig

func TestServer_CheckConfig(t *testing.T) {
	log.SetHandler(text.New(os.Stderr))

	Convey("Testing Server.CheckConfig", t, FailureContinues, func() {
		// FIXME: check with a script
		server, err := NewServer()
		So(err, ShouldBeNil)
		server.AllowedImages = []string{"alpine", "ubuntu:trusty", "abcde123"}

		So(server.CheckConfig(&ClientConfig{ImageName: "alpine"}), ShouldBeNil)
		So(server.CheckConfig(&ClientConfig{ImageName: "ubuntu:trusty"}), ShouldBeNil)
		So(server.CheckConfig(&ClientConfig{ImageName: "abcde123"}), ShouldBeNil)

		So(server.CheckConfig(&ClientConfig{ImageName: "abcde124"}), ShouldNotBeNil)
		So(server.CheckConfig(&ClientConfig{ImageName: "ubuntu:vivid"}), ShouldNotBeNil)
	})
}
開發者ID:moul,項目名稱:ssh2docker,代碼行數:17,代碼來源:auth_test.go

示例15: main

func main() {
	flag.Parse()

	if *cfgAddr == "" {
		fmt.Println("required flag not provided: --config-http-address")
		os.Exit(1)
	}

	if *dnsAddr == "" {
		fmt.Println("required flag not provided: --lookupd-dns-address")
		os.Exit(1)
	}

	log.SetHandler(text.New(os.Stderr))
	ctx := log.WithFields(log.Fields{
		"cfgAddr": *cfgAddr,
		"dnsAddr": *dnsAddr,
		"ldPort":  *ldPort,
	})

	ips, err := dnscfg.Get(dnsAddr, ldPort)
	if err != nil {
		ctx.WithError(err).Error("dns lookup")
		os.Exit(1)
	}

	if len(ips) == 0 {
		ctx.Error("no ip addresses found")
		os.Exit(1)
	}

	cfgURL := "http://" + *cfgAddr + "/config/nsqlookupd_tcp_addresses"
	err = httpcfg.Set(cfgURL, ips)
	if err != nil {
		ctx.WithError(err).Error("setting config")
	} else {
		ctx.WithField("ips", ips).Info("setting config")
	}

	go configLoop(ctx, cfgURL)

	http.ListenAndServe(":6060", nil)
}
開發者ID:lucmichalski,項目名稱:nsqd-discovery,代碼行數:43,代碼來源:main.go


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