Esempio n. 1
0
func tail(Log logger.Logger, filename string, numLines int) string {
	if filename == "" {
		return ""
	}

	f, err := os.Open(filename)
	if err != nil {
		Log.Warning("error opening log %q: %s", filename, err)
		return ""
	}
	b := rogReverse.NewScanner(f)
	b.Split(bufio.ScanLines)

	var lines []string
	for b.Scan() {
		lines = append(lines, b.Text())
		if len(lines) == numLines {
			break
		}
	}

	for left, right := 0, len(lines)-1; left < right; left, right = left+1, right-1 {
		lines[left], lines[right] = lines[right], lines[left]
	}

	return strings.Join(lines, "\n")
}
Esempio n. 2
0
func ctxWithRandomID(ctx context.Context, tagKey interface{},
	tagName string, log logger.Logger) context.Context {
	// Tag each request with a unique ID
	logTags := make(logger.CtxLogTags)
	logTags[tagKey] = tagName
	newCtx := logger.NewContextWithLogTags(ctx, logTags)
	id, err := MakeRandomRequestID()
	if err != nil {
		if log != nil {
			log.Warning("Couldn't generate a random request ID: %v", err)
		}
	} else {
		newCtx = context.WithValue(newCtx, tagKey, id)
	}
	return newCtx
}
Esempio n. 3
0
func (r *RemoteStatus) loop(ctx context.Context, log logger.Logger, config libkbfs.Config) {
	for {
		tctx, cancel := context.WithTimeout(ctx, 1*time.Second)
		st, ch, err := config.KBFSOps().Status(tctx)
		// No deferring inside loops, and no panics either here.
		cancel()
		if err != nil {
			log.Warning("KBFS Status failed: %v", err)
		}
		r.update(st)
		// Block on the channel or shutdown.
		select {
		case <-ctx.Done():
			return
		case <-ch:
		}
	}
}
Esempio n. 4
0
func warnNonProd(log logger.Logger, e *libkb.Env) {
	mode := e.GetRunMode()
	if mode != libkb.ProductionRunMode {
		log.Warning("Running in %s mode", mode)
	}
}