本文整理匯總了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()
}
示例2: main
func main() {
log.SetHandler(cli.Default)
if err := root.Command.Execute(); err != nil {
log.Fatalf("Error: %s", err)
}
}
示例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)
}
示例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))
}
}
示例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)
}
}
示例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()
}
示例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)
}
示例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)
}
示例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))
}
}
示例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)
}
}
示例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
}
示例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")
}
}
示例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")
}
}
示例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)
})
}
示例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)
}