mirror of
https://github.com/grafana/grafana.git
synced 2025-02-14 17:43:35 -06:00
* move guts from cli to server * renaming + refactoring * add pluginsDir arg * arg fixes * add support for repo URL override * add funcs to interface * use pluginID consistently * swap args * pass mandatory grafanaVersion field * introduce logger interface * create central logger for CLI * add infra log wrapper * re-add log initer step * remove unused logger * add checks for uninstalling * improve debug blue * make sure to close file * fix linter issues * remove space * improve newline usage * refactor packaging * improve logger API * fix interface func names * close file and reformat zipslip catch * handle G305 linter warning * add helpful debug log
75 lines
1.6 KiB
Go
75 lines
1.6 KiB
Go
package logger
|
|
|
|
import (
|
|
"fmt"
|
|
"strings"
|
|
|
|
"github.com/fatih/color"
|
|
)
|
|
|
|
type CLILogger struct {
|
|
DebugMode bool
|
|
}
|
|
|
|
func New(debugMode bool) *CLILogger {
|
|
return &CLILogger{
|
|
DebugMode: debugMode,
|
|
}
|
|
}
|
|
|
|
func (l *CLILogger) Successf(format string, args ...interface{}) {
|
|
fmt.Printf(fmt.Sprintf("%s %s\n\n", color.GreenString("✔"), format), args...)
|
|
}
|
|
|
|
func (l *CLILogger) Failuref(format string, args ...interface{}) {
|
|
fmt.Printf(fmt.Sprintf("%s %s %s\n\n", color.RedString("Error"), color.RedString("✗"), format), args...)
|
|
}
|
|
|
|
func (l *CLILogger) Info(args ...interface{}) {
|
|
args = append(args, "\n\n")
|
|
fmt.Print(args...)
|
|
}
|
|
|
|
func (l *CLILogger) Infof(format string, args ...interface{}) {
|
|
fmt.Printf(addNewlines(format), args...)
|
|
}
|
|
|
|
func (l *CLILogger) Debug(args ...interface{}) {
|
|
args = append(args, "\n\n")
|
|
if l.DebugMode {
|
|
fmt.Print(color.HiBlueString(fmt.Sprint(args...)))
|
|
}
|
|
}
|
|
|
|
func (l *CLILogger) Debugf(format string, args ...interface{}) {
|
|
if l.DebugMode {
|
|
fmt.Print(color.HiBlueString(fmt.Sprintf(addNewlines(format), args...)))
|
|
}
|
|
}
|
|
|
|
func (l *CLILogger) Warn(args ...interface{}) {
|
|
args = append(args, "\n\n")
|
|
fmt.Print(args...)
|
|
}
|
|
|
|
func (l *CLILogger) Warnf(format string, args ...interface{}) {
|
|
fmt.Printf(addNewlines(format), args...)
|
|
}
|
|
|
|
func (l *CLILogger) Error(args ...interface{}) {
|
|
args = append(args, "\n\n")
|
|
fmt.Print(args...)
|
|
}
|
|
|
|
func (l *CLILogger) Errorf(format string, args ...interface{}) {
|
|
fmt.Printf(addNewlines(format), args...)
|
|
}
|
|
|
|
func addNewlines(str string) string {
|
|
var s strings.Builder
|
|
s.WriteString(str)
|
|
s.WriteString("\n\n")
|
|
|
|
return s.String()
|
|
}
|