コード例 #1
0
func setup_steno(conf *proxy.ProxyConfig) {
	level, err := steno.GetLogLevel(conf.LOGGING.LEVEL)
	if err != nil {
		panic(err)
	}

	log_path := conf.LOGGING.PATH
	if log_path != "" {
		os.MkdirAll(filepath.Dir(log_path), 0755)
	}

	sinks := make([]steno.Sink, 0)
	if log_path != "" {
		sinks = append(sinks, steno.NewFileSink(log_path))
	} else {
		sinks = append(sinks, steno.NewIOSink(os.Stdout))
	}

	stenoConfig := &steno.Config{
		Sinks: sinks,
		Codec: steno.NewJsonCodec(),
		Level: level,
	}

	steno.Init(stenoConfig)
}
コード例 #2
0
ファイル: main.go プロジェクト: jungle0755/gorouter
func InitLoggerFromConfig(c *config.Config, logCounter *vcap.LogCounter) {
	l, err := steno.GetLogLevel(c.Logging.Level)
	if err != nil {
		panic(err)
	}

	s := make([]steno.Sink, 0, 3)
	if c.Logging.File != "" {
		s = append(s, steno.NewFileSink(c.Logging.File))
	} else {
		s = append(s, steno.NewIOSink(os.Stdout))
	}

	if c.Logging.Syslog != "" {
		s = append(s, steno.NewSyslogSink(c.Logging.Syslog))
	}

	s = append(s, logCounter)

	stenoConfig := &steno.Config{
		Sinks: s,
		Codec: steno.NewJsonCodec(),
		Level: l,
	}

	steno.Init(stenoConfig)
}
コード例 #3
0
ファイル: logger.go プロジェクト: lyuyun/loggregator
func NewLogger(verbose bool, logFilePath, name string, syslogNamespace string) *gosteno.Logger {
	level := gosteno.LOG_INFO

	if verbose {
		level = gosteno.LOG_DEBUG
	}

	loggingConfig := &gosteno.Config{
		Sinks:     make([]gosteno.Sink, 1),
		Level:     level,
		Codec:     gosteno.NewJsonCodec(),
		EnableLOC: true}

	if strings.TrimSpace(logFilePath) == "" {
		loggingConfig.Sinks[0] = gosteno.NewIOSink(os.Stdout)
	} else {
		loggingConfig.Sinks[0] = gosteno.NewFileSink(logFilePath)
	}

	if syslogNamespace != "" {
		loggingConfig.Sinks = append(loggingConfig.Sinks, GetNewSyslogSink(syslogNamespace))
	}

	gosteno.Init(loggingConfig)
	logger := gosteno.NewLogger(name)
	logger.Debugf("Component %s in debug mode!", name)

	return logger
}
コード例 #4
0
ファイル: main.go プロジェクト: shageman/loggregator
func main() {
	flag.Parse()

	if *version {
		fmt.Printf("\n\nversion: %s\ngitSha: %s\n\n", versionNumber, gitSha)
		return
	}

	level := gosteno.LOG_INFO

	if *logLevel {
		level = gosteno.LOG_DEBUG
	}

	loggingConfig := &gosteno.Config{
		Sinks:     make([]gosteno.Sink, 1),
		Level:     level,
		Codec:     gosteno.NewJsonCodec(),
		EnableLOC: true}
	if strings.TrimSpace(*logFilePath) == "" {
		loggingConfig.Sinks[0] = gosteno.NewIOSink(os.Stdout)
	} else {
		loggingConfig.Sinks[0] = gosteno.NewFileSink(*logFilePath)
	}
	gosteno.Init(loggingConfig)
	logger := gosteno.NewLogger("deaagent")

	loggregatorClient := loggregatorclient.NewLoggregatorClient(*loggregatorAddress, logger, 4096)

	agent := deaagent.NewAgent(*instancesJsonFilePath, logger)
	agent.Start(loggregatorClient)
}
コード例 #5
0
ファイル: logger.go プロジェクト: jfarrell/gorouter
func SetupLoggerFromConfig(c *config.Config) {
	l, err := steno.GetLogLevel(c.Logging.Level)
	if err != nil {
		panic(err)
	}

	s := make([]steno.Sink, 0)
	if c.Logging.File != "" {
		s = append(s, steno.NewFileSink(c.Logging.File))
	} else {
		s = append(s, steno.NewIOSink(os.Stdout))
	}

	if c.Logging.Syslog != "" {
		s = append(s, steno.NewSyslogSink(c.Logging.Syslog))
	}

	stenoConfig := &steno.Config{
		Sinks: s,
		Codec: steno.NewJsonCodec(),
		Level: l,
	}

	steno.Init(stenoConfig)
	log = steno.NewLogger("router.global")
}
コード例 #6
0
ファイル: main.go プロジェクト: shageman/loggregator
func main() {
	flag.Parse()

	if *version {
		fmt.Printf("\n\nversion: %s\ngitSha: %s\n\n", versionNumber, gitSha)
		return
	}

	level := gosteno.LOG_INFO

	if *logLevel {
		level = gosteno.LOG_DEBUG
	}

	loggingConfig := &gosteno.Config{
		Sinks:     make([]gosteno.Sink, 1),
		Level:     level,
		Codec:     gosteno.NewJsonCodec(),
		EnableLOC: true}

	if strings.TrimSpace(*logFilePath) == "" {
		loggingConfig.Sinks[0] = gosteno.NewIOSink(os.Stdout)
	} else {
		loggingConfig.Sinks[0] = gosteno.NewFileSink(*logFilePath)
	}
	gosteno.Init(loggingConfig)
	logger := gosteno.NewLogger("loggregator")

	listener := loggregator.NewAgentListener(*host, logger)
	incomingData := listener.Start()

	cfSink := loggregator.NewCfSink(incomingData, logger)
	cfSink.Start()
}
コード例 #7
0
func InitLog(logFile string) {
	c := &steno.Config{
		Level:     steno.LOG_INFO,
		Codec:     steno.NewJsonCodec(),
		EnableLOC: true,
	}
	if logFile == "" {
		c.Sinks = []steno.Sink{steno.NewIOSink(os.Stdout)}
	} else {
		c.Sinks = []steno.Sink{steno.NewFileSink(logFile)}
	}
	steno.Init(c)
	obj = steno.NewLogger("")
}
コード例 #8
0
ファイル: hm9000.go プロジェクト: nagyistge/hm9000
func loadLoggerAndConfig(c *cli.Context, component string) (logger.Logger, *gosteno.Logger, *config.Config) {
	configPath := c.String("config")
	if configPath == "" {
		fmt.Printf("Config path required")
		os.Exit(1)
	}

	conf, err := config.FromFile(configPath)
	if err != nil {
		fmt.Printf("Failed to load config: %s", err.Error())
		os.Exit(1)
	}

	sinks := make([]gosteno.Sink, 0, 3)
	if conf.LogDirectory != "" {
		logName := fmt.Sprintf("hm9000_%s.log", component)
		logFile := path.Join(conf.LogDirectory, logName)

		sinks = append(sinks, gosteno.NewFileSink(logFile))
	} else {
		sinks = append(sinks, gosteno.NewIOSink(os.Stdout))
	}
	sinks = append(sinks, gosteno.NewSyslogSink("vcap.hm9000."+component))

	stenoConf := &gosteno.Config{
		Sinks: sinks,
		Level: conf.LogLevel(),
		Codec: gosteno.NewJsonCodec(),
	}
	gosteno.Init(stenoConf)
	steno := gosteno.NewLogger("vcap.hm9000." + component)
	hmLogger := logger.NewRealLogger(steno)

	debugAddr := c.String("debugAddr")
	if debugAddr != "" {
		_, err = cf_debug_server.Run(debugAddr, nil)
		if err != nil {
			hmLogger.Error("Failed to start debug server", err)
			os.Exit(1)
		}
	}

	return hmLogger, steno, conf
}
コード例 #9
0
ファイル: logger.go プロジェクト: 9cc9/dea_ng
func SetupSteno(logConfig *LogConfig) {
	level, err := steno.GetLogLevel(logConfig.Level)
	if err != nil {
		panic(err)
	}

	sinks := make([]steno.Sink, 0)
	if logConfig.File != "" {
		sinks = append(sinks, steno.NewFileSink(logConfig.File))
	} else {
		sinks = append(sinks, steno.NewIOSink(os.Stdout))
	}
	if logConfig.Syslog != "" {
		sinks = append(sinks, steno.NewSyslogSink(logConfig.Syslog))
	}

	stenoConfig := &steno.Config{
		Sinks: sinks,
		Codec: steno.NewJsonCodec(),
		Level: level,
	}

	steno.Init(stenoConfig)
}
コード例 #10
0
ファイル: config.go プロジェクト: nkuacac/pat
		panic(err)
	}

	sinks := []gosteno.Sink{}
	if params.path != "" {
		sinks = append(sinks, NewFileSink(params.path))
	} else {
		sinks = append(sinks, NewIOSink(os.Stdout))
	}

	c := &gosteno.Config{
		Sinks:     sinks,
		Level:     level,
		EnableLOC: true,
	}

	InitGoSteno(c)
}

var InitGoSteno = func(c *gosteno.Config) {
	gosteno.Init(c)
}

var NewFileSink = func(path string) gosteno.Sink {
	return gosteno.NewFileSink(path)
}

var NewIOSink = func(file *os.File) gosteno.Sink {
	return gosteno.NewIOSink(file)
}