示例#1
0
func main() {
	c := &gosteno.Config{
		Sinks: []gosteno.Sink{
			gosteno.NewIOSink(os.Stdout),
		},
		Level:     gosteno.LOG_DEBUG,
		Codec:     gosteno.NewJsonPrettifier(0),
		EnableLOC: true,
	}
	gosteno.Init(c)

	logger := gosteno.NewLogger("atk_instances")

	conf := config.NewConfig()

	m := martini.Classic()

	key, err := atkoauth2.TokenKey(conf.TokenKeyUrl)
	if err != nil {
		logger.Error(err.Error())
		return
	}

	m.Handlers(
		atkoauth2.ResourceServer(key),
		martini.Logger(),
		render.Renderer(render.Options{IndentJSON: true}),
	)

	m.Get("/rest/orgs/:id/atkinstances", func(params martini.Params, t *jwt.Token, r render.Render) {

		cloudController := cc.NewRestCloudController(conf.ApiUrl, t.Raw)

		spaceSummaryHelper := service.NewSpaceSummaryHelper()

		srv := service.NewAtkListService(cloudController, spaceSummaryHelper)

		if len(conf.CommonService) == 0 {
			conf.CommonService = "postgres"
		}

		//TODO: check id param

		instances, err := srv.GetAllInstances(conf.ServiceLabel,
			conf.ScoringEngineLabel,
			conf.CommonService,
			params["id"])
		if err != nil {
			r.JSON(500, err.Error())
		}

		r.JSON(200, instances)
	})

	m.Run()
}
示例#2
0
func main() {
	excludedFields := steno.EXCLUDE_NONE

	h := flag.Bool("h", false, "Show help")
	a := flag.Bool("a", false, "Omit location and data in order to provide well-aligned logs")
	s := flag.Bool("s", false, "Ignore errors in parsing logs")

	flag.Usage = func() {
		fmt.Fprintf(os.Stderr, helptext)
	}

	flag.Parse()

	if *h {
		flag.Usage()
		return
	}
	if *a {
		excludedFields |= steno.EXCLUDE_FILE | steno.EXCLUDE_LINE | steno.EXCLUDE_METHOD | steno.EXCLUDE_DATA
	}
	if *s {
		ignoreParseError = true
	}

	prettifier = steno.NewJsonPrettifier(excludedFields)

	args := flag.Args()
	if len(args) > 0 {
		for _, f := range args {
			if f == "-" {
				prettifyFromIO(os.Stdin)
			} else {
				e := prettifyFromFile(f)
				if e != nil {
					fmt.Fprintln(os.Stderr, e)
				}
			}
		}
	} else {
		prettifyFromIO(os.Stdin)
	}
}
示例#3
0
func NewLogger(file *os.File, level string) (Logger, error) {
	if len(level) == 0 {
		level = "debug"
	}

	logLevel, err := steno.GetLogLevel(level)
	if err != nil {
		return nil, err
	}

	out := steno.NewIOSink(file)
	out.SetCodec(steno.NewJsonPrettifier(steno.EXCLUDE_DATA))

	cnf := &steno.Config{
		Sinks:     []steno.Sink{out},
		Level:     logLevel,
		Port:      8080, // TODO: parameterize?
		EnableLOC: false,
	}
	steno.Init(cnf)

	return steno.NewLogger("gonatsd"), nil
}