Example #1
0
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()
}
Example #2
0
File: main.go Project: elizar/apex
func main() {
	log.SetHandler(cli.Default)

	if err := root.Command.Execute(); err != nil {
		log.Fatalf("Error: %s", err)
	}
}
Example #3
0
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)
}
Example #4
0
File: apex.go Project: yuishug/apex
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))
	}
}
Example #5
0
func main() {
	log.SetHandler(cli.Default)

	if err := rootCmd.Execute(); err != nil {
		fmt.Fprintf(os.Stderr, "error: %s\n", err)
		os.Exit(1)
	}
}
Example #6
0
func main() {
	cli.Colors[log.DebugLevel] = 90
	cli.Colors[log.InfoLevel] = 32
	log.SetHandler(cli.New(os.Stdout))

	log.SetLevel(log.DebugLevel)

	cmd.Execute()
}
Example #7
0
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)
}
Example #8
0
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)
}
Example #9
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 #10
0
File: trace.go Project: leobcn/log
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)
	}
}
Example #11
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 #12
0
File: json.go Project: leobcn/log
func main() {
	log.SetHandler(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 #13
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 #14
0
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)
	})
}
Example #15
0
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)
}
Example #16
0
func main() {
	log.SetHandler(text.New(os.Stderr))
	log.SetLevel(log.DebugLevel)

	var (
		app    = flag.String("a", "", "App name")
		bucket = flag.String("b", "", "Bucket name")
		stream = flag.String("s", "", "Stream name")
	)
	flag.Parse()

	e := &s3.Emitter{
		Bucket: *bucket,
		Region: "us-west-1",
	}

	c := connector.NewConsumer(connector.Config{
		AppName:    *app,
		StreamName: *stream,
	})

	c.Start(connector.HandlerFunc(func(b connector.Buffer) {
		body := new(bytes.Buffer)

		for _, r := range b.GetRecords() {
			body.Write(r.Data)
		}

		err := e.Emit(
			s3.Key("", b.FirstSeq(), b.LastSeq()),
			bytes.NewReader(body.Bytes()),
		)

		if err != nil {
			fmt.Printf("error %s\n", err)
			os.Exit(1)
		}
	}))

	select {} // run forever
}
Example #17
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 #18
0
File: cli.go Project: leobcn/log
func main() {
	log.SetHandler(cli.Default)
	log.SetLevel(log.DebugLevel)

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

	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 {}
}
Example #19
0
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())
	}

}
Example #20
0
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()
}
Example #21
0
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)
}
Example #22
0
func (a *app) Run(logger service.Logger) {
	var logFilePath string
	usr, err := user.Current()
	if err == nil {
		logFilePath = filepath.Join(usr.HomeDir, ".config/go-psexec/server-hidden.log")
	} else {
		logFilePath = "server-hidden.log"
	}

	rollingFile := &lumberjack.Logger{
		Filename:   logFilePath,
		MaxSize:    20, // megabytes
		MaxBackups: 20,
		MaxAge:     28, //days
	}

	apex.SetLevel(apex.DebugLevel) //Global level
	apex.SetHandler(json.New(rollingFile))

	tmpLogger := &defaultLogger{
		logger,
		apex.WithField("exe", filepath.Base(os.Args[0])),
	}
	a.logger = tmpLogger

	defer func() {
		if r := recover(); r != nil {
			a.logger.Errorf("Panic recovery in service RUN function: %T %+v", r, r)
		}
	}()

	a.logger.Infof("Running server version %s", TempVersion)

	a.gracefulTimeout = 30 * time.Second //Because a command could be busy executing

	pvtKey, err := shared.ReadPemKey(*serverPemFlag)
	if err != nil {
		logger.Errorf("Cannot read server pem file, error: %s. Exiting server.", err.Error())
		return
	}
	a.privateKey = pvtKey

	checksumsSvc := checksums.New()
	handlerServices := &HandlerServices{
		FilePathSummaries: filepath_summary.New(checksumsSvc),
	}

	a.h = &handler{logger, a.privateKey, handlerServices}

	allowedKeys, err := shared.LoadAllowedPublicKeysFile(*allowedPublicKeysFileFlag)
	if err != nil {
		logger.Errorf("Cannot read allowed public keys, error: %s. Exiting server.", err.Error())
		return
	}
	if len(allowedKeys) == 0 {
		logger.Errorf("Allowed public key file '%s' was read but contains no keys. Exiting server.", *allowedPublicKeysFileFlag)
		return
	}

	a.setAllowedPublicKeys(allowedKeys)

	watcher, err := shared.StartWatcher(*allowedPublicKeysFileFlag, a)
	if err != nil {

	} else {
		a.watcherPublicKeys = watcher
	}

	e := echo.New()
	if a.debugMode {
		e.SetDebug(true)
	}

	e.Use(middleware.Recover())
	if a.accessLogger {
		loggerCfg := middleware.DefaultLoggerConfig
		loggerCfg.Output = tmpLogger
		e.Use(middleware.LoggerWithConfig(loggerCfg))
	}

	t := &htmlTemplateRenderer{}
	e.SetRenderer(t)

	// Unrestricted group
	e.POST("/token", a.h.handleGenerateTokenFunc)
	e.GET("/webui", a.h.handleWebUIFunc)

	// Restricted group
	r := e.Group("/auth")
	r.Use(GetClientPubkey())
	r.GET("/ping", a.h.handlePingFunc)
	r.GET("/version", a.h.handleVersionFunc)
	r.POST("/stream", a.h.handleStreamFunc)
	r.POST("/start", a.h.handleStartFunc)
	r.POST("/upload-tar", a.h.handleUploadTarFunc)
	r.GET("/download-tar", a.h.handleDownloadTarFunc)
	r.POST("/delete", a.h.handleDeleteFunc)
	r.POST("/move", a.h.handleMoveFunc)
	r.POST("/copy", a.h.handleCopyFunc)
	r.POST("/symlink", a.h.handleSymlinkFunc)
	r.GET("/stats", a.h.handleStatsFunc)
	r.GET("/path-summary", a.h.handlePathSummaryFunc)
	r.GET("/get-temp-dir", a.h.handleGetTempDirFunc)
	r.GET("/get-os-type", a.h.handleGetOsTypeFunc)

	a.logger.Infof("Now serving on '%s'", *addressFlag)

	server := standard.New(*addressFlag)
	server.SetHandler(e)
	server.SetLogger(e.Logger())
	if e.Debug() {
		e.Logger().Debug("running in debug mode")
	}

	a.srv = &graceful.Server{
		Timeout: a.gracefulTimeout,
		Server:  server.Server,
	}

	a.registerInterruptSignal()

	err = a.srv.ListenAndServe()
	if err != nil {
		if !strings.Contains(err.Error(), "closed network connection") {
			logger.Errorf("Unable to ListenAndServe, error: %s", err.Error())
			time.Sleep(time.Second) //Sleep a second to give log time to write out
		}
	}
}
Example #23
0
File: main.go Project: tobyjoe/grab
func init() {
	log.SetHandler(cli.Default)
}
Example #24
0
// Discard all log entries, for benchmarking purposes
func Discard() {
	apexlog.SetHandler(discard.Default)
}
Example #25
0
func init() {
	log.SetHandler(discard.New())
}
Example #26
0
import (
	"os"
	"time"

	. "github.com/onsi/ginkgo"
	// . "github.com/onsi/gomega"

	"github.com/apex/log"
	"github.com/apex/log/handlers/text"
	"github.com/joho/godotenv"
)

var _ = Describe("Motivewave", func() {

	log.SetHandler(text.New(os.Stdout))
	log.SetLevel(log.InfoLevel)

	godotenv.Load()
	path := os.Getenv("PATH_MWML")

	Describe("Selectors", func() {
		log.SetLevel(log.InfoLevel)
		mw := &mwQuery{}
		_ = mw.importMotiveWaveXML(path)
		markup, _ := mw.parse()

		It("Ongoing", func() {

			price := &Point{T: time.Now()}