Esempio n. 1
0
func main() {
	configPath := flag.String("agentConfig", "", "Agent config yaml")
	flag.Parse()

	logger := lager.NewLogger("redis-agent")
	logger.RegisterSink(lager.NewWriterSink(os.Stdout, lager.DEBUG))
	logger.RegisterSink(lager.NewWriterSink(os.Stderr, lager.ERROR))

	config, err := agentconfig.Load(*configPath)
	if err != nil {
		logger.Fatal("Error loading config file", err, lager.Data{
			"path": *configPath,
		})
	}

	templateRedisConf(config, logger)

	redisResetter := resetter.New(
		config.DefaultConfPath,
		config.ConfPath,
		portChecker{},
		commandRunner{},
		config.MonitExecutablePath,
	)

	handler := auth.NewWrapper(
		config.AuthConfiguration.Username,
		config.AuthConfiguration.Password,
	).Wrap(
		agentapi.New(redisResetter, config.ConfPath),
	)

	http.Handle("/", handler)
	logger.Fatal("http-listen", http.ListenAndServe("localhost:"+config.Port, nil))
}
Esempio n. 2
0
// NewBroker is a constructor for a Broker webapp struct
func NewBroker() (subway *Broker) {
	subway = &Broker{}
	subway.Logger = lager.NewLogger("cf-subway")
	subway.Logger.RegisterSink(lager.NewWriterSink(os.Stdout, lager.DEBUG))
	subway.Logger.RegisterSink(lager.NewWriterSink(os.Stderr, lager.ERROR))
	return subway
}
Esempio n. 3
0
func main() {
	brokerConfigPath := configPath()

	log := lager.NewLogger("redis-configmigrator")
	log.RegisterSink(lager.NewWriterSink(os.Stdout, lager.DEBUG))
	log.RegisterSink(lager.NewWriterSink(os.Stderr, lager.ERROR))

	log.Info("Config File: " + brokerConfigPath)

	config, err := brokerconfig.ParseConfig(brokerConfigPath)
	if err != nil {
		log.Fatal("Loading config file", err, lager.Data{
			"broker-config-path": brokerConfigPath,
		})
	}

	migrator := &configmigrator.ConfigMigrator{
		RedisDataDir: config.RedisConfiguration.InstanceDataDirectory,
	}

	err = migrator.Migrate()
	if err != nil {
		log.Fatal("Could not migrate data", err)
	}
}
func (f *FakeCell) SpinUp(serviceClient bbs.ServiceClient) {
	//make a test-friendly AuctionRepDelegate using the auction package's SimulationRepDelegate
	f.SimulationRep = simulationrep.New(f.stack, "Z0", rep.Resources{
		DiskMB:     100,
		MemoryMB:   100,
		Containers: 100,
	})

	//spin up an http auction server
	logger := lager.NewLogger(f.cellID)
	logger.RegisterSink(lager.NewWriterSink(GinkgoWriter, lager.INFO))

	fakeLRPStopper := new(fake_lrp_stopper.FakeLRPStopper)
	fakeExecutorClient := new(executorfakes.FakeClient)
	fakeEvacuatable := new(fake_evacuation_context.FakeEvacuatable)

	handlers := rephandlers.New(f.SimulationRep, fakeLRPStopper, fakeExecutorClient, fakeEvacuatable, logger)
	router, err := rata.NewRouter(rep.Routes, handlers)
	Expect(err).NotTo(HaveOccurred())
	f.server = httptest.NewServer(router)

	presence := models.NewCellPresence(
		f.cellID,
		f.server.URL,
		"az1",
		models.NewCellCapacity(512, 1024, 124),
		[]string{},
		[]string{})

	f.heartbeater = ifrit.Invoke(serviceClient.NewCellPresenceRunner(logger, &presence, time.Second))
}
Esempio n. 5
0
func main() {
	logger = lager.NewLogger("nats-to-syslog")
	stop = make(chan bool)
	buffer := make(chan *nats.Msg, 1000)

	trapSignals()

	var natsUri = flag.String("nats-uri", "nats://localhost:4222", "The NATS server URI")
	var natsSubject = flag.String("nats-subject", ">", "The NATS subject to subscribe to")
	var syslogEndpoint = flag.String("syslog-endpoint", "localhost:514", "The remote syslog server host:port")
	var debug = flag.Bool("debug", false, "debug logging true/false")
	flag.Parse()

	setupLogger(*debug)

	syslog := connectToSyslog(*syslogEndpoint)
	defer syslog.Close()

	natsClient := connectToNATS(*natsUri)
	defer natsClient.Close()

	go func() {
		for message := range buffer {
			sendToSyslog(message, syslog)
		}
	}()

	natsClient.Subscribe(*natsSubject, func(message *nats.Msg) {
		buffer <- message
	})
	logger.Info("subscribed-to-subject", lager.Data{"subject": *natsSubject})

	<-stop
	logger.Info("bye.")
}
Esempio n. 6
0
func main() {
	flag.Parse()

	logger := lager.NewLogger("cf-rabbitmq-broker")
	logger.RegisterSink(lager.NewWriterSink(os.Stdout, lager.INFO))
	logger.RegisterSink(lager.NewWriterSink(os.Stderr, lager.ERROR))

	rand.Seed(time.Now().UTC().UnixNano())

	config, err := rabbitbroker.ReadConfig(configPath)
	if err != nil {
		logger.Fatal("read-config", err)
	}

	client, _ := rabbithole.NewClient(
		fmt.Sprintf("http://%s:15672", config.Rabbitmq.Hosts[0]),
		config.Rabbitmq.Administrator.Username,
		config.Rabbitmq.Administrator.Password)

	serviceBroker := rabbitbroker.New(config, client, rabbitbroker.RandomCredentialsGenerator{}, logger, rabbitbroker.BindingInfoResource{ProtocolInfo: rabbitbroker.ProtocolInfoResource{}})

	credentials := brokerapi.BrokerCredentials{
		Username: config.Service.Username,
		Password: config.Service.Password,
	}

	http.Handle("/", brokerapi.New(serviceBroker, logger, credentials))

	logger.Info("starting-server")
	if err := http.ListenAndServe(":4567", nil); err != nil {
		logger.Fatal("starting-server-failed", err)
	}
}
Esempio n. 7
0
func New(writer io.Writer) *GinkgoReporter {
	logger := lager.NewLogger("ginkgo")
	logger.RegisterSink(lager.NewWriterSink(writer, lager.DEBUG))
	return &GinkgoReporter{
		writer: writer,
		logger: logger,
	}
}
Esempio n. 8
0
func NewTestLogger(component string) *TestLogger {
	logger := lager.NewLogger(component)

	testSink := NewTestSink()
	logger.RegisterSink(testSink)
	logger.RegisterSink(lager.NewWriterSink(ginkgo.GinkgoWriter, lager.DEBUG))

	return &TestLogger{logger, testSink}
}
Esempio n. 9
0
func NewTestLogger(component string) *TestLogger {
	logger := lager.NewLogger(component)

	testSink := NewTestSink()

	logger.RegisterSink(testSink)

	return &TestLogger{logger, testSink}
}
Esempio n. 10
0
func main() {
	logger := lager.NewLogger("backup")
	logger.RegisterSink(log.NewCliSink(lager.INFO))
	logger.RegisterSink(lager.NewWriterSink(os.Stdout, lager.INFO))

	var configPath string
	flag.StringVar(&configPath, "config", "", "Path to YML config file")

	flag.Parse()

	if _, err := os.Stat(configPath); os.IsNotExist(err) {
		logger.Error("snapshot-main", err, lager.Data{"event": "failed", "config_file": configPath})
		os.Exit(2)
	}

	backupConfig, err := backup.LoadBackupConfig(configPath)
	exitOnError(err, 78, logger, configPath)

	logFile, err := os.OpenFile(backupConfig.LogFilepath, os.O_RDWR|os.O_CREATE|os.O_APPEND, 0660)
	if err != nil {
		logger.Error("snapshot-main", err, lager.Data{"event": "failed", "LogFilepath": backupConfig.LogFilepath})
	}
	logger.RegisterSink(lager.NewWriterSink(logFile, lager.INFO))

	// TODO: Should this really be a pointer not a struct?
	if (backupConfig.S3Config == backup.S3Configuration{}) {
		logger.Info("snapshot-main", lager.Data{"event": "cancelled", "message": "S3 configuration not found - skipping backup"})
		os.Exit(0)
	}

	backuper, err := backup.NewInstanceBackuper(*backupConfig, logger)
	exitOnError(err, 70, logger, configPath)

	backupResults := backuper.Backup()
	hasError := false
	for _, result := range backupResults {
		if result.Err != nil {
			hasError = true
			logger.Error(
				"snapshot-main",
				result.Err,
				lager.Data{
					"event":           "failed",
					"InstanceID":      result.InstanceID,
					"RedisConfigPath": result.RedisConfigPath,
					"NodeIP":          result.NodeIP,
				},
			)
		}
	}

	if hasError {
		os.Exit(70)
	}
}
Esempio n. 11
0
// initd listens on a socket, spawns requested processes and reaps their
// exit statuses.
func main() {
	defer func() {
		if r := recover(); r != nil {
			fmt.Fprintf(os.Stderr, "initd: panicked: %s\n", r)
			os.Exit(4)
		}
	}()

	dropCaps := flag.Bool("dropCapabilities", false, "drop capabilities before running processes")
	flag.Parse()

	container_daemon.Detach("/dev/null", "/dev/null")
	logger := lager.NewLogger("initd")

	syncWriter := os.NewFile(uintptr(4), "/dev/sync_writer")
	syscall.RawSyscall(syscall.SYS_FCNTL, uintptr(4), syscall.F_SETFD, syscall.FD_CLOEXEC)
	defer syncWriter.Close()

	sync := &containerizer.PipeSynchronizer{
		Writer: syncWriter,
	}

	reaper := system.StartReaper(logger)
	defer reaper.Stop()

	daemon := &container_daemon.ContainerDaemon{
		CmdPreparer: &container_daemon.ProcessSpecPreparer{
			Users:                  container_daemon.LibContainerUser{},
			Rlimits:                &container_daemon.RlimitsManager{},
			ProcStarterPath:        "/sbin/proc_starter",
			AlwaysDropCapabilities: *dropCaps,
		},
		Spawner: &container_daemon.Spawn{
			Runner: reaper,
			PTY:    system.KrPty,
		},
	}

	socketFile := os.NewFile(uintptr(5), "/dev/host.sock")
	listener, err := unix_socket.NewListenerFromFile(socketFile)
	if err != nil {
		fail(fmt.Sprintf("initd: failed to create listener: %s\n", err), 5)
	}

	socketFile.Close()

	if err := sync.SignalSuccess(); err != nil {
		fail(fmt.Sprintf("signal host: %s", err), 6)
	}

	if err := daemon.Run(listener); err != nil {
		fail(fmt.Sprintf("run daemon: %s", err), 7)
	}
}
Esempio n. 12
0
func main() {
	logger := lager.NewLogger("checkin")
	logger.RegisterSink(lager.NewWriterSink(os.Stdout, lager.INFO))

	var opts Opts

	_, err := flags.Parse(&opts)
	if err != nil {
		logger.Error("parsing-flags", err)
		os.Exit(1)
	}

	// ts := oauth2.StaticTokenSource(
	// 	&oauth2.Token{AccessToken: opts.GitHubAccessToken},
	// )
	// tc := oauth2.NewClient(oauth2.NoContext, ts)
	// githubClient := github.NewClient(tc)

	// checker := build.NewConcourseChecker()
	// checker = build.NewStatusReporter(checker, githubClient.Repositories)

	dbConn, err := migration.Open(opts.DBDriver, opts.DBURL, migrations.Migrations)
	if err != nil {
		logger.Error("failed-to-run-migrations", err)
		os.Exit(1)
	}
	sqlDB := db.NewSQL(logger.Session("db"), dbConn)

	enqueuer := build.NewEnqueuer(sqlDB)
	apiServer := api.NewServer(opts.GitHubSecret, enqueuer)

	members := []grouper.Member{
		{
			"api",
			http_server.New(
				opts.Addr,
				apiServer,
			),
		},
	}

	group := grouper.NewParallel(os.Interrupt, members)
	running := ifrit.Invoke(sigmon.New(group))

	logger.Info("listening", lager.Data{
		"api": opts.Addr,
	})

	err = <-running.Wait()
	if err != nil {
		fmt.Fprintln(os.Stderr, err)
		os.Exit(1)
	}
}
Esempio n. 13
0
func buildLogger(logLevel string) lager.Logger {
	laggerLogLevel, ok := logLevels[strings.ToUpper(logLevel)]
	if !ok {
		log.Fatal("Invalid log level: ", logLevel)
	}

	logger := lager.NewLogger("rds-broker")
	logger.RegisterSink(lager.NewWriterSink(os.Stdout, laggerLogLevel))

	return logger
}
Esempio n. 14
0
func logger() lager.Logger {
	logger := lager.NewLogger("ltc")
	var logLevel lager.LogLevel

	if os.Getenv("LTC_LOG_LEVEL") == "DEBUG" {
		logLevel = lager.DEBUG
	} else {
		logLevel = lager.INFO
	}

	logger.RegisterSink(lager.NewWriterSink(os.Stderr, logLevel))
	return logger
}
Esempio n. 15
0
func main() {
	var port string
	serviceBroker := &myServiceBroker{}
	logger := lager.NewLogger("my-service-broker")
	credentials := brokerapi.BrokerCredentials{
		Username: "******",
		Password: "******",
	}

	port = os.Getenv("VCAP_APP_PORT")
	brokerAPI := brokerapi.New(serviceBroker, logger, credentials)
	http.Handle("/", brokerAPI)
	http.ListenAndServe("0.0.0.0:"+port, nil)
}
Esempio n. 16
0
func main() {
	flag.Parse()

	logger := lager.NewLogger("lattice-app")
	if quiet {
		logger.RegisterSink(lager.NewWriterSink(os.Stdout, lager.INFO))
	} else {
		logger.RegisterSink(lager.NewWriterSink(os.Stdout, lager.DEBUG))
	}

	ports := getServerPorts()

	logger.Info("lattice-app.starting", lager.Data{"ports": ports})
	handler, err := rata.NewRouter(routes.Routes, handlers.New(logger))
	if err != nil {
		logger.Fatal("router.creation.failed", err)
	}

	index, err := helpers.FetchIndex()
	appName := fetchAppName()
	go func() {
		t := time.NewTicker(time.Second)
		for {
			<-t.C
			if err != nil {
				fmt.Fprintf(os.Stderr, "Failed to fetch index: %s\n", err.Error())
			} else {
				fmt.Println(fmt.Sprintf("%s. Says %s. on index: %d", appName, message, index))
			}
		}
	}()

	wg := sync.WaitGroup{}
	for _, port := range ports {
		wg.Add(1)
		go func(wg *sync.WaitGroup, port string) {
			defer wg.Done()
			server := ifrit.Envoke(http_server.New(":"+port, handler))
			logger.Info("lattice-app.up", lager.Data{"port": port})
			err = <-server.Wait()
			if err != nil {
				logger.Error("shutting down server", err, lager.Data{"server port": port})
			}
			logger.Info("shutting down server", lager.Data{"server port": port})
		}(&wg, port)
	}
	wg.Wait()
	logger.Info("shutting latice app")
}
Esempio n. 17
0
func main() {
	logger := lager.NewLogger("garden-lame")
	logger.RegisterSink(lager.NewWriterSink(os.Stdout, lager.DEBUG))

	client := NewLameClient(logger)
	backend := lameBackend{logger: logger, Client: client}
	srv := server.New("tcp", ":3000", 5*time.Minute, &backend, logger)
	srv.Start()

	exit := make(chan os.Signal)
	signal.Notify(exit, syscall.SIGINT, syscall.SIGTERM, syscall.SIGHUP)

	<-exit

	srv.Stop()
}
Esempio n. 18
0
func main() {
	ipAddress := os.Getenv("REDIS_IP")

	serviceBroker := broker.New(broker.DatabaseIDs{}, ipAddress)
	logger := lager.NewLogger("redis-service-broker")
	credentials := brokerapi.BrokerCredentials{
		Username: "******",
		Password: "******",
	}

	brokerAPI := brokerapi.New(&serviceBroker, logger, credentials)
	fmt.Println("Listening on port " + os.Getenv("PORT") + " with IP " + ipAddress)
	http.Handle("/", brokerAPI)
	if err := http.ListenAndServe(":"+os.Getenv("PORT"), nil); err != nil {
		log.Fatal("ListenAndServe:", err)
	}
}
Esempio n. 19
0
func main() {
	var (
		err       error
		uaaClient client.Client
		token     *schema.Token
	)

	if len(os.Args) < 5 {
		fmt.Printf("Usage: <client-name> <client-secret> <uaa-url> <skip-verification>\n\n")
		fmt.Printf("For example: client-name client-secret https://uaa.service.cf.internal:8443 true\n")
		return
	}

	skip, err := strconv.ParseBool(os.Args[4])
	if err != nil {
		log.Fatal(err)
		os.Exit(1)
	}

	cfg := &config.Config{
		ClientName:       os.Args[1],
		ClientSecret:     os.Args[2],
		UaaEndpoint:      os.Args[3],
		SkipVerification: skip,
	}

	logger := lager.NewLogger("test")
	clock := clock.NewClock()

	uaaClient, err = client.NewClient(logger, cfg, clock)
	if err != nil {
		log.Fatal(err)
		os.Exit(1)
	}

	fmt.Printf("Connecting to: %s ...\n", cfg.UaaEndpoint)

	token, err = uaaClient.FetchToken(true)
	if err != nil {
		log.Fatal(err)
		os.Exit(1)
	}

	fmt.Printf("Response:\n\ttoken: %s\n\texpires: %d\n", token.AccessToken, token.ExpiresIn)

}
Esempio n. 20
0
func main() {
	dbCreator := database.NewCreator("username", "password", "hostname", 123)

	serviceBroker := &exampleServiceBroker{
		dbCreator: dbCreator,
		instances: map[string]string{},
	}
	logger := lager.NewLogger("cf-example-broker")
	credentials := brokerapi.BrokerCredentials{
		Username: "******",
		Password: "******",
	}

	brokerAPI := brokerapi.New(serviceBroker, logger, credentials)
	http.Handle("/", brokerAPI)
	http.ListenAndServe(":3000", nil)
}
Esempio n. 21
0
func (cmd *ATCCommand) constructLogger() (lager.Logger, *lager.ReconfigurableSink) {
	logger := lager.NewLogger("atc")

	logLevel := lager.INFO
	if cmd.Developer.DevelopmentMode {
		logLevel = lager.DEBUG
	}

	reconfigurableSink := lager.NewReconfigurableSink(lager.NewWriterSink(os.Stdout, lager.DEBUG), logLevel)
	logger.RegisterSink(reconfigurableSink)

	if cmd.Metrics.YellerAPIKey != "" {
		yellerSink := zest.NewYellerSink(cmd.Metrics.YellerAPIKey, cmd.Metrics.YellerEnvironment)
		logger.RegisterSink(yellerSink)
	}

	return logger, reconfigurableSink
}
Esempio n. 22
0
func main() {
	flag.Parse()

	logger := lager.NewLogger("houdini")
	logger.RegisterSink(lager.NewWriterSink(os.Stdout, lager.DEBUG))

	depot, err := filepath.Abs(*containersDir)
	if err != nil {
		logger.Fatal("failed-to-determine-depot-dir", err)
	}

	backend := houdini.NewBackend(depot)

	gardenServer := server.New(*listenNetwork, *listenAddr, *containerGraceTime, backend, logger)

	err = gardenServer.Start()
	if err != nil {
		logger.Fatal("failed-to-start-server", err)
	}

	logger.Info("started", lager.Data{
		"network": *listenNetwork,
		"addr":    *listenAddr,
	})

	signals := make(chan os.Signal, 1)

	go func() {
		<-signals
		gardenServer.Stop()
		os.Exit(0)
	}()

	signal.Notify(signals, syscall.SIGINT, syscall.SIGTERM, syscall.SIGHUP)

	debugListenAddr := fmt.Sprintf("%s:%d", *debugListenAddress, *debugListenPort)

	err = http.ListenAndServe(debugListenAddr, nil)
	if err != nil {
		logger.Fatal("failed-to-start-debug-server", err)
	}

	select {}
}
Esempio n. 23
0
func main() {
	var (
		err       error
		uaaClient client.Client
		key       string
	)

	if len(os.Args) < 3 {
		fmt.Printf("Usage: <uaa-url> <skip-verification>\n\n")
		fmt.Printf("For example: https://uaa.service.cf.internal:8443 true\n")
		return
	}

	skip, err := strconv.ParseBool(os.Args[2])
	if err != nil {
		log.Fatal(err)
		os.Exit(1)
	}

	cfg := &config.Config{
		UaaEndpoint:      os.Args[1],
		SkipVerification: skip,
	}

	logger := lager.NewLogger("test")
	clock := clock.NewClock()

	uaaClient, err = client.NewClient(logger, cfg, clock)
	if err != nil {
		log.Fatal(err)
		os.Exit(1)
	}

	fmt.Printf("Connecting to: %s ...\n", cfg.UaaEndpoint)

	key, err = uaaClient.FetchKey()
	if err != nil {
		log.Fatal(err)
		os.Exit(1)
	}

	fmt.Printf("Response:\n%s\n", key)

}
Esempio n. 24
0
func main() {
	logger := lager.NewLogger("lattice-app")
	if quiet {
		logger.RegisterSink(lager.NewWriterSink(os.Stdout, lager.INFO))
	} else {
		logger.RegisterSink(lager.NewWriterSink(os.Stdout, lager.DEBUG))
	}

	port := os.Getenv("PORT")
	if port == "" {
		port = "8080"
	}

	logger.Info("lattice-app.starting", lager.Data{"port": port})
	handler, err := rata.NewRouter(routes.Routes, handlers.New(logger))
	if err != nil {
		logger.Fatal("router.creation.failed", err)
	}

	index, err := helpers.FetchIndex()
	appName := helpers.FetchAppName()

	go func() {
		t := time.NewTicker(time.Second)
		for {
			<-t.C
			if err != nil {
				fmt.Fprintf(os.Stderr, "Failed to fetch index: %s\n", err.Error())
			} else {
				fmt.Println(fmt.Sprintf("%s. Says %s. on index: %d", appName, message, index))
			}
		}
	}()

	server := ifrit.Envoke(http_server.New(":"+port, handler))
	logger.Info("lattice-app.up", lager.Data{"port": port})
	err = <-server.Wait()
	if err != nil {
		logger.Error("farewell", err)
	}
	logger.Info("farewell")
}
Esempio n. 25
0
func configureLogger() lager.Logger {
	var lagerLogLevel lager.LogLevel
	switch *logLevel {
	case "debug":
		lagerLogLevel = lager.DEBUG
	case "info":
		lagerLogLevel = lager.INFO
	case "error":
		lagerLogLevel = lager.ERROR
	case "fatal":
		lagerLogLevel = lager.FATAL
	default:
		panic(fmt.Errorf("unknown log level: %s", logLevel))
	}

	logger := lager.NewLogger("delphos")
	sink := lager.NewReconfigurableSink(lager.NewWriterSink(os.Stdout, lager.DEBUG), lagerLogLevel)
	logger.RegisterSink(sink)

	return logger
}
Esempio n. 26
0
func NewLager(log *logger) Logger {
	var minLagerLogLevel lager.LogLevel
	switch log.LogLevel {
	case DEBUG:
		minLagerLogLevel = lager.DEBUG
	case INFO:
		minLagerLogLevel = lager.INFO
	case ERROR:
		minLagerLogLevel = lager.ERROR
	case FATAL:
		minLagerLogLevel = lager.FATAL
	default:
		panic(fmt.Errorf("unknown log level: %s", log.LogLevel))
	}

	logger := lager.NewLogger(log.Name)
	logger.RegisterSink(lager.NewWriterSink(log.Writer, minLagerLogLevel))
	log.Logger = logger

	return log
}
func main() {
	isProducer := flag.Bool("producer", false, "Is this process a producer?")
	flag.Parse()

	logger := lager.NewLogger(fmt.Sprintf("Process-%d", os.Getpid()))
	logger.RegisterSink(lager.NewWriterSink(os.Stdout, lager.INFO))

	creds := rabbitmq.AMQPCredentials{
		Host:     "localhost",
		Port:     5672,
		Username: "******",
		Password: "******",
	}
	queue := "producers-consumers"

	if *isProducer {
		sender, err := rabbitmq.NewSender(creds, queue)
		mustNot(err)
		ch, err := gofigure.OutboundChannel(sender)
		mustNot(err)
		logger.Info("got-write-channel")

		ch <- "Hello consumers"
		logger.Info("sent-message")
	} else {
		receiver, err := rabbitmq.NewReceiver(creds, queue)
		mustNot(err)
		ch, err := gofigure.InboundChannel(receiver)
		mustNot(err)
		logger.Info("got-read-channel")

		data := <-ch
		logger.Info(data.(string))
		logger.Info("received-message")
	}

	logger.Info("done")

	select {}
}
Esempio n. 28
0
File: main.go Progetto: savaki/tsa
func main() {
	flag.Parse()

	logger := lager.NewLogger("tsa")
	logger.RegisterSink(lager.NewWriterSink(os.Stdout, lager.DEBUG))

	if len(*forwardHost) == 0 {
		logger.Fatal("missing-flag", nil, lager.Data{"flag": "-forwardHost"})
	}

	atcEndpoint := rata.NewRequestGenerator(*atcAPIURL, atc.Routes)

	authorizedKeys, err := loadAuthorizedKeys(*authorizedKeysPath)
	if err != nil {
		logger.Fatal("failed-to-load-authorized-keys", err)
	}

	config, err := configureSSHServer(*hostKeyPath, authorizedKeys)
	if err != nil {
		logger.Fatal("failed-to-configure-ssh-server", err)
	}

	listener, err := net.Listen("tcp", fmt.Sprintf("0.0.0.0:%d", *listenPort))
	if err != nil {
		logger.Fatal("failed-to-listen-for-connection", err)
	}

	logger.Info("listening")

	server := &registrarSSHServer{
		logger:            logger,
		heartbeatInterval: *heartbeatInterval,
		atcEndpoint:       atcEndpoint,
		forwardHost:       *forwardHost,
		config:            config,
		httpClient:        http.DefaultClient,
	}

	server.Serve(listener)
}
Esempio n. 29
0
func InitializeLogger(minLogLevel LogLevel) (lager.Logger, *lager.ReconfigurableSink, error) {
	var minLagerLogLevel lager.LogLevel
	switch minLogLevel {
	case LogLevelDebug:
		minLagerLogLevel = lager.DEBUG
	case LogLevelInfo:
		minLagerLogLevel = lager.INFO
	case LogLevelError:
		minLagerLogLevel = lager.ERROR
	case LogLevelFatal:
		minLagerLogLevel = lager.FATAL
	default:
		return nil, nil, fmt.Errorf("unknown log level: %s", minLogLevel)
	}

	logger := lager.NewLogger("garagepi")

	sink := lager.NewReconfigurableSink(lager.NewWriterSink(os.Stdout, lager.DEBUG), minLagerLogLevel)
	logger.RegisterSink(sink)

	return logger, sink, nil
}
Esempio n. 30
0
func New(component string) (lager.Logger, *lager.ReconfigurableSink) {
	var minLagerLogLevel lager.LogLevel
	switch minLogLevel {
	case DEBUG:
		minLagerLogLevel = lager.DEBUG
	case INFO:
		minLagerLogLevel = lager.INFO
	case ERROR:
		minLagerLogLevel = lager.ERROR
	case FATAL:
		minLagerLogLevel = lager.FATAL
	default:
		panic(fmt.Errorf("unknown log level: %s", minLogLevel))
	}

	logger := lager.NewLogger(component)

	sink := lager.NewReconfigurableSink(lager.NewWriterSink(os.Stdout, lager.DEBUG), minLagerLogLevel)
	logger.RegisterSink(sink)

	return logger, sink
}