当前位置: 首页>>代码示例>>Golang>>正文


Golang gosteno.NewLogger函数代码示例

本文整理汇总了Golang中github.com/cloudfoundry/gosteno.NewLogger函数的典型用法代码示例。如果您正苦于以下问题:Golang NewLogger函数的具体用法?Golang NewLogger怎么用?Golang NewLogger使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。


在下文中一共展示了NewLogger函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。

示例1: NewRouter

func NewRouter(cfg *config.Config, p proxy.Proxy, mbusClient yagnats.NATSConn, r *registry.RouteRegistry,
	v varz.Varz, logCounter *vcap.LogCounter, errChan chan error) (*Router, error) {

	var host string
	if cfg.Status.Port != 0 {
		host = fmt.Sprintf("%s:%d", cfg.Ip, cfg.Status.Port)
	}

	varz := &vcap.Varz{
		UniqueVarz: v,
		GenericVarz: vcap.GenericVarz{
			Type:        "Router",
			Index:       cfg.Index,
			Host:        host,
			Credentials: []string{cfg.Status.User, cfg.Status.Pass},
			LogCounts:   logCounter,
		},
	}

	healthz := &vcap.Healthz{}

	component := &vcap.VcapComponent{
		Config:  cfg,
		Varz:    varz,
		Healthz: healthz,
		InfoRoutes: map[string]json.Marshaler{
			"/routes": r,
		},
		Logger: steno.NewLogger("common.logger"),
	}

	routerErrChan := errChan
	if routerErrChan == nil {
		routerErrChan = make(chan error, 2)
	}

	router := &Router{
		config:       cfg,
		proxy:        p,
		mbusClient:   mbusClient,
		registry:     r,
		varz:         v,
		component:    component,
		serveDone:    make(chan struct{}),
		tlsServeDone: make(chan struct{}),
		idleConns:    make(map[net.Conn]struct{}),
		activeConns:  make(map[net.Conn]struct{}),
		logger:       steno.NewLogger("router"),
		errChan:      routerErrChan,
		stopping:     false,
	}

	if err := router.component.Start(); err != nil {
		return nil, err
	}

	return router, nil
}
开发者ID:idouba,项目名称:gorouter,代码行数:58,代码来源:router.go

示例2: TestDontSendEmptyData

func TestDontSendEmptyData(t *testing.T) {
	bufferSize := 4096
	loggregatorClient := l.NewLoggregatorClient("localhost:9876", gosteno.NewLogger("TestLogger"), bufferSize)

	udpAddr, err := net.ResolveUDPAddr("udp", "localhost:9876")
	if err != nil {
		t.Errorf("Expected no error, but got %v", err)
	}

	udpListener, err := net.ListenUDP("udp", udpAddr)
	defer udpListener.Close()
	if err != nil {
		t.Errorf("Expected no error, but got %v", err)
	}

	firstMessage := []byte("")
	secondMessage := []byte("hi")
	loggregatorClient.Send(firstMessage)
	loggregatorClient.Send(secondMessage)

	buffer := make([]byte, bufferSize)
	readCount, _, err := udpListener.ReadFromUDP(buffer)

	if err != nil {
		t.Errorf("Expected no error, but got %v", err)
	}

	received := string(buffer[:readCount])
	if string(secondMessage) != received {
		t.Errorf("Expected %s to equal %s", string(secondMessage), received)
	}
}
开发者ID:muhqu,项目名称:gotestit,代码行数:32,代码来源:testing_test.go

示例3: NewAtkListService

func NewAtkListService(cloudController CloudController, SpaceSummaryHelper SpaceSummaryHelper) *AtkListService {
	return &AtkListService{
		cloudController:    cloudController,
		SpaceSummaryHelper: SpaceSummaryHelper,
		logger:             gosteno.NewLogger("atk_list_service"),
	}
}
开发者ID:blkrs,项目名称:app-launcher-helper,代码行数:7,代码来源:atk_list_service.go

示例4: main

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)
}
开发者ID:shageman,项目名称:loggregator,代码行数:32,代码来源:main.go

示例5: NewProxy

func NewProxy(args ProxyArgs) Proxy {
	return &proxy{
		accessLogger: args.AccessLogger,
		traceKey:     args.TraceKey,
		ip:           args.Ip,
		logger:       steno.NewLogger("router.proxy"),
		registry:     args.Registry,
		reporter:     args.Reporter,
		transport: &http.Transport{
			Dial: func(network, addr string) (net.Conn, error) {
				conn, err := net.DialTimeout(network, addr, 5*time.Second)
				if err != nil {
					return conn, err
				}
				if args.EndpointTimeout > 0 {
					err = conn.SetDeadline(time.Now().Add(args.EndpointTimeout))
				}
				return conn, err
			},
			DisableKeepAlives:     true,
			ResponseHeaderTimeout: args.EndpointTimeout,
		},
		waitgroup: &sync.WaitGroup{},
	}
}
开发者ID:ninglipeng,项目名称:gorouter,代码行数:25,代码来源:proxy.go

示例6: NewProxy

func NewProxy(args ProxyArgs) Proxy {
	p := &proxy{
		accessLogger: args.AccessLogger,
		traceKey:     args.TraceKey,
		ip:           args.Ip,
		logger:       steno.NewLogger("router.proxy"),
		registry:     args.Registry,
		reporter:     args.Reporter,
		transport: &http.Transport{
			Dial: func(network, addr string) (net.Conn, error) {
				conn, err := net.DialTimeout(network, addr, 5*time.Second)
				if err != nil {
					return conn, err
				}
				if args.EndpointTimeout > 0 {
					err = conn.SetDeadline(time.Now().Add(args.EndpointTimeout))
				}
				return conn, err
			},
			DisableKeepAlives:  true,
			DisableCompression: true,
		},
		secureCookies: args.SecureCookies,
	}
	return p
}
开发者ID:trainchou,项目名称:gorouter,代码行数:26,代码来源:proxy.go

示例7: CreateRunningAccessLogger

func CreateRunningAccessLogger(config *config.Config) (AccessLogger, error) {
	loggregatorUrl := config.LoggregatorConfig.Url

	if config.AccessLog == "" && loggregatorUrl == "" {
		return &NullAccessLogger{}, nil
	}

	logger := steno.NewLogger("access_log")

	var err error
	var file *os.File
	if config.AccessLog != "" {
		file, err = os.OpenFile(config.AccessLog, os.O_WRONLY|os.O_APPEND|os.O_CREATE, 0666)
		if err != nil {
			logger.Errorf("Error creating accesslog file, %s: (%s)", config.AccessLog, err.Error())
			return nil, err
		}
	}

	var e emitter.Emitter
	if loggregatorUrl != "" {
		loggregatorSharedSecret := config.LoggregatorConfig.SharedSecret
		e, err = NewEmitter(loggregatorUrl, loggregatorSharedSecret, config.Index)
		if err != nil {
			logger.Errorf("Error creating loggregator emitter: (%s)", err.Error())
			return nil, err
		}
	}

	accessLogger := NewFileAndLoggregatorAccessLogger(file, e)
	go accessLogger.Run()
	return accessLogger, nil
}
开发者ID:tomzhang,项目名称:golang-devops-stuff,代码行数:33,代码来源:create_running_access_logger.go

示例8: CreateRunningAccessLogger

func CreateRunningAccessLogger(config *config.Config) (AccessLogger, error) {

	if config.AccessLog == "" && !config.Logging.LoggregatorEnabled {
		return &NullAccessLogger{}, nil
	}

	logger := steno.NewLogger("access_log")

	var err error
	var file *os.File
	if config.AccessLog != "" {
		file, err = os.OpenFile(config.AccessLog, os.O_WRONLY|os.O_APPEND|os.O_CREATE, 0666)
		if err != nil {
			logger.Errorf("Error creating accesslog file, %s: (%s)", config.AccessLog, err.Error())
			return nil, err
		}
	}

	var dropsondeSourceInstance string
	if config.Logging.LoggregatorEnabled {
		dropsondeSourceInstance = strconv.FormatUint(uint64(config.Index), 10)
	}

	accessLogger := NewFileAndLoggregatorAccessLogger(file, dropsondeSourceInstance)
	go accessLogger.Run()
	return accessLogger, nil
}
开发者ID:ninglipeng,项目名称:gorouter,代码行数:27,代码来源:create_running_access_logger.go

示例9: NewEmitter

func NewEmitter(loggregatorUrl, loggregatorSharedSecret string, index uint) (emitter.Emitter, error) {
	if !isValidUrl(loggregatorUrl) {
		return nil, fmt.Errorf("Invalid loggregator url %s", loggregatorUrl)
	}
	return emitter.NewEmitter(loggregatorUrl, "RTR", strconv.FormatUint(uint64(index), 10), loggregatorSharedSecret,
		steno.NewLogger("router.loggregator"))
}
开发者ID:tomzhang,项目名称:golang-devops-stuff,代码行数:7,代码来源:file_and_loggregator_access_logger.go

示例10: main

func main() {
	flag.Parse()

	level, err := gosteno.GetLogLevel(*logLevel)
	if err != nil {
		level = gosteno.LOG_INFO
	}
	loggingConfig := &gosteno.Config{
		Sinks: []gosteno.Sink{
			gosteno.NewIOSink(os.Stdout),
		},
		Level:     level,
		Codec:     gosteno.NewJsonCodec(),
		EnableLOC: true,
	}

	gosteno.Init(loggingConfig)
	logger := gosteno.NewLogger("statsdinjector")

	statsdMessageListener := statsdlistener.New(*statsdPort, logger)
	statsdEmitter := statsdemitter.New(*metronPort, logger)

	inputChan := make(chan *events.Envelope)

	go statsdMessageListener.Run(inputChan)
	statsdEmitter.Run(inputChan)
}
开发者ID:kei-yamazaki,项目名称:loggregator,代码行数:27,代码来源:main.go

示例11: Process

func (c *Config) Process() {
	var err error

	c.PruneStaleDropletsInterval = time.Duration(c.PruneStaleDropletsIntervalInSeconds) * time.Second
	c.DropletStaleThreshold = time.Duration(c.DropletStaleThresholdInSeconds) * time.Second
	c.PublishActiveAppsInterval = time.Duration(c.PublishActiveAppsIntervalInSeconds) * time.Second
	c.StartResponseDelayInterval = time.Duration(c.StartResponseDelayIntervalInSeconds) * time.Second
	c.EndpointTimeout = time.Duration(c.EndpointTimeoutInSeconds) * time.Second

	if c.StartResponseDelayInterval > c.DropletStaleThreshold {
		c.DropletStaleThreshold = c.StartResponseDelayInterval
		log := steno.NewLogger("config.logger")
		log.Warnf("DropletStaleThreshold (%s) cannot be less than StartResponseDelayInterval (%s); setting both equal to StartResponseDelayInterval and continuing", c.DropletStaleThreshold, c.StartResponseDelayInterval)
	}

	drain := c.DrainTimeoutInSeconds
	if drain == 0 {
		drain = c.EndpointTimeoutInSeconds
	}
	c.DrainTimeout = time.Duration(drain) * time.Second

	c.Ip, err = vcap.LocalIP()
	if err != nil {
		panic(err)
	}
}
开发者ID:johannespetzold,项目名称:gorouter,代码行数:26,代码来源:config.go

示例12: main

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()
}
开发者ID:shageman,项目名称:loggregator,代码行数:34,代码来源:main.go

示例13: NewLogger

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
}
开发者ID:lyuyun,项目名称:loggregator,代码行数:29,代码来源:logger.go

示例14: TestSend

func TestSend(t *testing.T) {
	bufferSize := 4096
	loggregatorClient := l.NewLoggregatorClient("localhost:9876", gosteno.NewLogger("TestLogger"), bufferSize)

	udpAddr, err := net.ResolveUDPAddr("udp", "localhost:9876")
	if err != nil {
		t.Errorf("Expected no error, but got %v", err)
	}

	udpListener, err := net.ListenUDP("udp", udpAddr)
	defer udpListener.Close()
	if err != nil {
		t.Errorf("Expected no error, but got %v", err)
	}

	expectedOutput := []byte("Important Testmessage")
	loggregatorClient.Send(expectedOutput)

	buffer := make([]byte, bufferSize)
	readCount, _, err := udpListener.ReadFromUDP(buffer)
	if err != nil {
		t.Errorf("Expected no error, but got %v", err)
	}

	received := string(buffer[:readCount])
	if string(expectedOutput) != received {
		t.Errorf("Expected %s to equal %s", string(expectedOutput), received)
	}
}
开发者ID:muhqu,项目名称:gotestit,代码行数:29,代码来源:testing_test.go

示例15: SetupLoggerFromConfig

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")
}
开发者ID:hfeeki,项目名称:gorouter,代码行数:26,代码来源:logger.go


注:本文中的github.com/cloudfoundry/gosteno.NewLogger函数示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。