Example #1
0
func NewAppLogDrain(appGUID string) (*AppLogDrain, error) {
	d := new(AppLogDrain)

	srv, err := lineserver.NewLineServer(
		LINESERVER_PROTO,
		fmt.Sprintf("%v:0", server.LocalIPMust()))
	if err != nil {
		return nil, err
	}

	addr, err := srv.GetUDPAddr()
	if err != nil {
		return nil, err
	}

	d.appGUID = appGUID
	d.srv = srv
	d.port = addr.Port
	d.lifetime, err = time.ParseDuration(config.GetConfig().DrainLifetime)
	if err != nil {
		return nil, fmt.Errorf(
			"Invalid duration value (%v) for drain_lifetime", err)
	}
	// TODO: name should have an uniq id, to allow multiple taile
	// sessions for same app.
	d.drainName = fmt.Sprintf("%s.%s", DRAIN_PREFIX, d.appGUID)

	return d, nil
}
Example #2
0
func (cmd *stream) Run(args []string) (string, error) {
	ipaddr, err := server.LocalIP()
	if err != nil {
		return "", err
	}

	rand.Seed(time.Now().UnixNano())
	port := 7000 + rand.Intn(1000)
	addr := fmt.Sprintf("%s:%d", ipaddr, port)

	srv, err := lineserver.NewLineServer(CLI_STREAM_PROTO, addr)
	if err != nil {
		return "", err
	}
	go srv.Start()

	// Debug mode allows one to debug just the logyard related logs,
	// without any magical stripping.
	debugMode := false
	if len(args) == 1 && args[0] == "debug" {
		debugMode = true
		args = []string{
			"systail.logyard",
			"systail.apptail",
			"systail.logyard_sieve",
			"systail.systail",
		}
	}

	name := fmt.Sprintf("tmp.logyard-cli.%s-%d", ipaddr, port)

	uri, err := drain.ConstructDrainURI(
		name,
		fmt.Sprintf("%s://%s", CLI_STREAM_PROTO, addr),
		args,
		map[string]string{"format": "raw"})
	if err != nil {
		return "", err
	}
	if err = logyard.AddDrain(name, uri); err != nil {
		return "", err
	}
	log.Infof("Added drain %s", uri)

	deleteDrain := func() {
		if err := logyard.DeleteDrain(name); err != nil {
			log.Fatal(err)
		}
		fmt.Println("")
		log.Infof("Deleted drain %s", name)
	}
	defer deleteDrain()

	handleKeyboardInterrupt(func() {
		deleteDrain()
		os.Exit(1)
	})

	cli_stream.Stream(srv.Ch, cli_stream.MessagePrinterOptions{
		cmd.raw, cmd.raw || debugMode, cmd.time, cmd.nocolor, cmd.nodeid, cmd.json})

	return "", nil
}