func init() { logger := gosteno.NewLogger("TestLogger") listener := agentlistener.NewAgentListener("localhost:3456", logger) dataChannel := listener.Start() messageRouter := sinkserver.NewMessageRouter(10, false, nil, logger) go messageRouter.Start() httpServer := sinkserver.NewHttpServer(messageRouter, 30*time.Second, testhelpers.UnmarshallerMaker("secret"), 100, logger) go httpServer.Start(dataChannel, "localhost:8081") time.Sleep(50 * time.Millisecond) }
func main() { seed := time.Now().UnixNano() rand.Seed(seed) flag.Parse() if *version { fmt.Printf("version: %s\ngitSha: %s\nsourceUrl: https://github.com/cloudfoundry/loggregator/tree/%s\n\n", versionNumber, gitSha, gitSha) return } runtime.GOMAXPROCS(runtime.NumCPU()) config := &Config{IncomingPort: 3456, OutgoingPort: 8080} err := cfcomponent.ReadConfigInto(config, *configFile) if err != nil { panic(err) } logger := cfcomponent.NewLogger(*logLevel, *logFilePath, "loggregator", config.Config) logger.Info("Startup: Setting up the loggregator server") err = config.validate(logger) if err != nil { panic(err) } listener := agentlistener.NewAgentListener(fmt.Sprintf("0.0.0.0:%d", config.IncomingPort), logger) incomingData := listener.Start() messageRouter := sinkserver.NewMessageRouter(config.MaxRetainedLogMessages, logger) unmarshaller := func(data []byte) (*logmessage.Message, error) { return logmessage.ParseEnvelope(data, config.SharedSecret) } httpServer := sinkserver.NewHttpServer(messageRouter, 30*time.Second, unmarshaller, logger) cfc, err := cfcomponent.NewComponent( logger, "LoggregatorServer", config.Index, &LoggregatorServerHealthMonitor{}, config.VarzPort, []string{config.VarzUser, config.VarzPass}, []instrumentation.Instrumentable{listener, messageRouter}, ) if err != nil { panic(err) } cr := collectorregistrar.NewCollectorRegistrar(config.MbusClient, logger) err = cr.RegisterWithCollector(cfc) if err != nil { logger.Warnf("Unable to register with collector. Err: %v.", err) } go func() { err := cfc.StartMonitoringEndpoints() if err != nil { panic(err) } }() go messageRouter.Start() go httpServer.Start(incomingData, fmt.Sprintf("0.0.0.0:%d", config.OutgoingPort)) killChan := make(chan os.Signal) signal.Notify(killChan, os.Kill) for { select { case <-cfcomponent.RegisterGoRoutineDumpSignalChannel(): cfcomponent.DumpGoRoutine() case <-killChan: break } } }