yay/pkg/text/service.go
Jo 0a8bc1fe2e
fix(new_engine): add missing latest-commit in devel upgrade menu (#1916)
* fix missing latest-commit in devel upgrade menu

* move test grapher to inner test
2023-02-17 19:29:46 +00:00

93 lines
1.8 KiB
Go

package text
import (
"fmt"
"io"
)
type Logger struct {
name string
debug bool
w io.Writer
r io.Reader
}
func NewLogger(w io.Writer, r io.Reader, debug bool, name string) *Logger {
return &Logger{
w: w,
name: name,
debug: debug,
r: r,
}
}
func (l *Logger) Child(name string) *Logger {
return NewLogger(l.w, l.r, l.debug, name)
}
func (l *Logger) Debugln(a ...any) {
if !DebugMode {
return
}
l.Println(append([]interface{}{
Bold(yellow(fmt.Sprintf("[DEBUG:%s]", l.name))),
}, a...)...)
}
func (l *Logger) OperationInfoln(a ...any) {
l.Println(l.SprintOperationInfo(a...))
}
func (l *Logger) OperationInfo(a ...any) {
l.Print(l.SprintOperationInfo(a...))
}
func (l *Logger) SprintOperationInfo(a ...any) string {
return fmt.Sprint(append([]interface{}{Bold(Cyan(opSymbol + " ")), boldCode}, a...)...) + ResetCode
}
func (l *Logger) Info(a ...any) {
l.Print(append([]interface{}{Bold(Green(arrow + " "))}, a...)...)
}
func (l *Logger) Infoln(a ...any) {
l.Println(append([]interface{}{Bold(Green(arrow))}, a...)...)
}
func (l *Logger) Warn(a ...any) {
l.Print(l.SprintWarn(a...))
}
func (l *Logger) Warnln(a ...any) {
l.Println(l.SprintWarn(a...))
}
func (l *Logger) SprintWarn(a ...any) string {
return fmt.Sprint(append([]interface{}{Bold(yellow(smallArrow + " "))}, a...)...)
}
func (l *Logger) Error(a ...any) {
l.Print(l.SprintError(a...))
}
func (l *Logger) Errorln(a ...any) {
l.Println(l.SprintError(a...))
}
func (l *Logger) SprintError(a ...any) string {
return fmt.Sprint(append([]interface{}{Bold(Red(smallArrow + " "))}, a...)...)
}
func (l *Logger) Printf(format string, a ...any) {
fmt.Fprintf(l.w, format, a...)
}
func (l *Logger) Println(a ...any) {
fmt.Fprintln(l.w, a...)
}
func (l *Logger) Print(a ...any) {
fmt.Fprint(l.w, a...)
}