本文整理汇总了Golang中github.com/apex/log.SetHandler函数的典型用法代码示例。如果您正苦于以下问题:Golang SetHandler函数的具体用法?Golang SetHandler怎么用?Golang SetHandler使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了SetHandler函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的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
示例16: main
func main() {
esClient := elastic.New("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)
log.SetHandler(multi.New(e, t))
ctx := log.WithFields(log.Fields{
"file": "something.png",
"type": "image/png",
"user": "tobi",
})
go func() {
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")
ctx.Errorf("failed to upload %s", "img.png")
}
}()
go func() {
for range time.Tick(time.Millisecond * 25) {
ctx.Info("upload")
}
}()
select {}
}
开发者ID:moul,项目名称:ssh2docker,代码行数:39,代码来源:es.go
示例17: main
func main() {
log.SetHandler(cli.Default)
log.SetLevel(log.DebugLevel)
ctx := log.WithFields(log.Fields{
"file": "something.png",
"type": "image/png",
"user": "tobi",
})
go func() {
for range time.Tick(time.Second) {
ctx.Debug("doing stuff")
}
}()
go func() {
for range time.Tick(100 * time.Millisecond) {
ctx.Info("uploading")
ctx.Info("upload complete")
}
}()
go func() {
for range time.Tick(time.Second) {
ctx.Warn("upload slow")
}
}()
go func() {
for range time.Tick(2 * time.Second) {
err := errors.New("boom")
ctx.WithError(err).Error("upload failed")
}
}()
select {}
}
开发者ID:leobcn,项目名称:log,代码行数:38,代码来源:cli.go
示例18: main
func main() {
log.SetHandler(cli.New(os.Stdout))
log.SetLevel(log.DebugLevel)
s, err := config.LoadConfig(ConfigurationFileName)
if err != nil {
log.Warnf("Unable to read configuration file: %s", err.Error())
}
d, err := store.Init(s.Location.Database, 2500)
if err != nil {
log.Fatalf("Unable to connect to data store at %s: %s", s.Location.Database, err.Error())
}
r := gin.New()
// If redirects to the secure are enabled, attach the secure middleware helper
if s.Bind.Redirect {
log.Debug("Secure redirects enabled")
r.Use(secure.RedirectToSecureByProxy(s.Domain, s.Bind.Ports.Secure, s.Bind.Proxy.Secure))
}
r.Use(gin.Logger())
r.Use(gin.Recovery())
// Add out own Middleware
r.Use(store.Connect(d))
// Connect the relevant modules to the router
alive.Init(r)
log.Debug("Starting Run()")
err = r.Run(s.Bind.Address + ":" + strconv.FormatInt(int64(s.Bind.Ports.Standard), 10))
if err != nil {
log.Fatalf("Fatal error during Run: %s", err.Error())
}
}
开发者ID:jonathanio,项目名称:apparition,代码行数:37,代码来源:main.go
示例19: main
func main() {
flag.Parse()
log.SetHandler(text.New(os.Stderr))
if *verbose {
log.SetLevel(log.DebugLevel)
} else {
log.SetLevel(log.InfoLevel)
}
if _, err := os.Stat(tpl); os.IsNotExist(err) {
log.WithError(err).Fatal("template provided does not exist")
}
ctx := log.WithFields(log.Fields{
"app": "spacegophers",
})
s := NewServer(ctx, *addr, tpl)
// serve the server
s.Serve()
}
开发者ID:wyattjoh,项目名称:spacegophers,代码行数:24,代码来源:main.go
示例20: TestDockerfileCreation
func TestDockerfileCreation(t *testing.T) {
log.SetHandler(cli.New(os.Stdout))
// The 'expected' hash
expected_hash := "033429aed5b9104f5c8d0a15ed2b9a043ce93a70"
// First we will read the sample json file
dat, err := ioutil.ReadFile("test/sample_data.json")
if err != nil {
log.WithError(err)
}
// We read the sample json data and create a new DockerInfo struct
var parsed_data DockerInfo
err = json.Unmarshal(dat, &parsed_data)
if err != nil {
log.WithError(err)
}
// Pass the DockerInfo struct into the GenerateDockerFile function
GenerateDockerFile(parsed_data, "test")
defer os.Remove("test/Dockerfile")
// Generate a sha1 hash of the generated Dockerfile and compare
f, err := ioutil.ReadFile("test/Dockerfile")
if err != nil {
log.WithError(err)
}
generated_hash := sha1.New()
generated_hash.Write([]byte(f))
bs := generated_hash.Sum(nil)
// We would like a hex-encoding string to compare with
hash_string := hex.EncodeToString(bs[:])
expect(t, hash_string, expected_hash)
}
开发者ID:istrategylabs,项目名称:franklin-build,代码行数:36,代码来源:api_test.go
注:本文中的github.com/apex/log.SetHandler函数示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论