Beispiel #1
0
// InitContex initializes the app context
func InitContex() *Context {
	if _context != nil {
		panic("Context already exists")
	}

	_context = new(Context)

	if err := envconfig.Process("api", &_context.Params); err != nil {
		panic(err)
	}

	// Setup database
	session, err := mgo.Dial(_context.Params.MongoURI)
	if err != nil {
		fmt.Println("Cannot start mongo")
		panic(err)
	}
	_context.Session = session
	_context.Session.SetMode(mgo.Monotonic, true)
	_context.DB = session.DB("")

	// LogEntries
	if _context.Params.LogEntriesToken != "" {
		_context.LogEntries, err = le_go.Connect(_context.Params.LogEntriesToken)
		if err != nil {
			panic(err)
		}
	}

	return _context
}
Beispiel #2
0
func logContainer(id, token string) {
	out := make(chan string)
	errChan := make(chan error, 1)
	le, err := le_go.Connect(token)
	if err != nil {
		log.Fatal(err)
	}
	defer le.Close()
	le.SetPrefix("[" + id + "]")
	le.Println("Starting log stream")
	go dockerClient.StreamLogs(id, out, errChan)
	for {
		select {
		case line := <-out:
			le.Println(line)
		case err := <-errChan:
			if err != nil {
				le.Println(err.Error())
				log.Error(err)
			}
			log.Printf("Stopping log stream from %s", id)
			le.Println("Stopping log stream")
			return
		}
	}
}
Beispiel #3
0
func main() {
	var tokenflag string
	var levelflag string

	flag.StringVar(&tokenflag, "token", "", "-token=<logentries_token>")
	flag.StringVar(&levelflag, "level", "", "-level=<info|err|debug|...>")

	flag.Parse()

	if tokenflag == "" {
		fmt.Fprintln(os.Stderr, "Usage: lecat -token=<logentries_token> -level=<log_level>")
		flag.PrintDefaults()
		os.Exit(2)
	}

	le, err := le_go.Connect(tokenflag)
	if err != nil {
		log.Fatal(err)
	}

	defer le.Close()

	scanner := bufio.NewScanner(os.Stdin)

	for scanner.Scan() {
		le.Println(levelflag, scanner.Text())
	}
}
Beispiel #4
0
// New creates a logentries logger using the configuration passed in on
// the context. The supported context configuration variable is
// logentries-token.
func New(info logger.Info) (logger.Logger, error) {
	logrus.WithField("container", info.ContainerID).
		WithField("token", info.Config[token]).
		Debug("logging driver logentries configured")

	log, err := le_go.Connect(info.Config[token])
	if err != nil {
		return nil, err
	}
	return &logentries{
		containerID:   info.ContainerID,
		containerName: info.ContainerName,
		writer:        log,
	}, nil
}