Ejemplo n.º 1
0
Archivo: debuglog.go Proyecto: bac/juju
// Run retrieves the debug log via the API.
func (c *debugLogCommand) Run(ctx *cmd.Context) (err error) {
	if c.tail {
		c.params.NoTail = false
	} else if c.notail {
		c.params.NoTail = true
	} else {
		// Set the default tail option to true if the caller is
		// using a terminal.
		c.params.NoTail = !isTerminal(ctx.Stdout)
	}

	client, err := getDebugLogAPI(c)
	if err != nil {
		return err
	}
	defer client.Close()
	messages, err := client.WatchDebugLog(c.params)
	if err != nil {
		return err
	}
	writer := ansiterm.NewWriter(ctx.Stdout)
	if c.color {
		writer.SetColorCapable(true)
	}
	for {
		msg, ok := <-messages
		if !ok {
			break
		}
		c.writeLogRecord(writer, msg)
	}

	return nil
}
Ejemplo n.º 2
0
Archivo: logging.go Proyecto: juju/cmd
// NewColorWriter will write out colored severity levels if the writer is
// outputting to a terminal.
func NewWarningWriter(writer io.Writer) loggo.Writer {
	w := &warningWriter{ansiterm.NewWriter(writer)}
	return loggo.NewMinimumLevelWriter(w, loggo.WARNING)
}
Ejemplo n.º 3
0
Archivo: writer.go Proyecto: juju/loggo
// NewColorWriter will write out colored severity levels if the writer is
// outputting to a terminal.
func NewColorWriter(writer io.Writer) Writer {
	return &colorWriter{ansiterm.NewWriter(writer)}
}