Example #1
0
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
}
Example #2
0
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": "******",
	})

	for range time.Tick(time.Millisecond * 100) {
		ctx.Info("upload")
		ctx.Info("upload complete")
	}
}
Example #3
0
File: multi.go Project: leobcn/log
func main() {
	log.SetHandler(multi.New(
		text.New(os.Stderr),
		json.New(os.Stderr),
	))

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

	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")
	}
}
Example #4
0
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))
	}
}
Example #5
0
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": "******",
	})

	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 {}
}
Example #6
0
		}

		if esServer := viper.GetString("elasticsearch"); esServer != "" {
			esClient := elastic.New(esServer)
			esClient.HTTPClient = &http.Client{
				Timeout: 5 * time.Second,
			}
			logHandlers = append(logHandlers, levelHandler.New(esHandler.New(&esHandler.Config{
				Client:     esClient,
				Prefix:     cmd.Name(),
				BufferSize: 10,
			}), logLevel))
		}

		ctx = &log.Logger{
			Handler: multiHandler.New(logHandlers...),
		}

		// Set the API/gRPC logger
		ttnlog.Set(apex.Wrap(ctx))
		grpclog.SetLogger(grpc.Wrap(ttnlog.Get()))

		ctx.WithFields(log.Fields{
			"ComponentID":              viper.GetString("id"),
			"Description":              viper.GetString("description"),
			"Discovery Server Address": viper.GetString("discovery-address"),
			"Auth Servers":             viper.GetStringMapString("auth-servers"),
			"Monitors":                 viper.GetStringMapString("monitor-servers"),
		}).Info("Initializing The Things Network")
	},
	PersistentPostRun: func(cmd *cobra.Command, args []string) {