grafana/pkg/cmd/grafana-cli/logger/loggerV2.go
Will Browne 26dfdd5af3
Plugins: Refactor plugin download/installation (#43046)
* installer -> repo

* add semver format checking

* add plugin callbacks in test

* remove newline

* post install only scans new directories

* remove unused stuff

* everything in own package

* add missing cli params

* make grafana version part of the API

* resolve conflicts

* tidy up logger

* fix cli and tidy log statements

* rename log package

* update struct name

* fix linter issue

* fs -> filestore

* reorder imports

* alias import

* fix test

* fix test

* inline var

* revert jsonc file

* make repo dep of manager

* actually inject the thing

* accept all args for compatability checks

* accept compat from store

* pass os + arch vals

* don't inject fs

* tidy up

* tidy up

* merge with main and tidy fs storage

* fix test

* fix packages

* fix comment + field name

* update fs naming

* fixed wire

* remove unused func

* fix mocks

* fix storage test

* renaming

* fix log line

* fix test

* re-order field

* tidying

* add test for update with same version

* fix wire for CLI

* remove use of ioutil

* don't pass field

* small tidy

* ignore code scanning warn

* fix testdata link

* update lgtm code
2022-08-23 11:50:50 +02:00

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()
}