2023-02-17 20:01:26 +01:00
|
|
|
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
|
|
|
|
}
|
|
|
|
|
2023-02-17 20:29:46 +01:00
|
|
|
l.Println(append([]interface{}{
|
2023-02-17 20:01:26 +01:00
|
|
|
Bold(yellow(fmt.Sprintf("[DEBUG:%s]", l.name))),
|
|
|
|
}, a...)...)
|
|
|
|
}
|
|
|
|
|
|
|
|
func (l *Logger) OperationInfoln(a ...any) {
|
2023-02-17 20:29:46 +01:00
|
|
|
l.Println(l.SprintOperationInfo(a...))
|
2023-02-17 20:01:26 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
func (l *Logger) OperationInfo(a ...any) {
|
2023-02-17 20:29:46 +01:00
|
|
|
l.Print(l.SprintOperationInfo(a...))
|
2023-02-17 20:01:26 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
func (l *Logger) SprintOperationInfo(a ...any) string {
|
|
|
|
return fmt.Sprint(append([]interface{}{Bold(Cyan(opSymbol + " ")), boldCode}, a...)...) + ResetCode
|
|
|
|
}
|
|
|
|
|
|
|
|
func (l *Logger) Info(a ...any) {
|
2023-02-17 20:29:46 +01:00
|
|
|
l.Print(append([]interface{}{Bold(Green(arrow + " "))}, a...)...)
|
2023-02-17 20:01:26 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
func (l *Logger) Infoln(a ...any) {
|
2023-02-17 20:29:46 +01:00
|
|
|
l.Println(append([]interface{}{Bold(Green(arrow))}, a...)...)
|
2023-02-17 20:01:26 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
func (l *Logger) Warn(a ...any) {
|
2023-02-17 20:29:46 +01:00
|
|
|
l.Print(l.SprintWarn(a...))
|
2023-02-17 20:01:26 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
func (l *Logger) Warnln(a ...any) {
|
2023-02-17 20:29:46 +01:00
|
|
|
l.Println(l.SprintWarn(a...))
|
2023-02-17 20:01:26 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
func (l *Logger) SprintWarn(a ...any) string {
|
|
|
|
return fmt.Sprint(append([]interface{}{Bold(yellow(smallArrow + " "))}, a...)...)
|
|
|
|
}
|
|
|
|
|
|
|
|
func (l *Logger) Error(a ...any) {
|
2023-02-17 20:29:46 +01:00
|
|
|
l.Print(l.SprintError(a...))
|
2023-02-17 20:01:26 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
func (l *Logger) Errorln(a ...any) {
|
2023-02-17 20:29:46 +01:00
|
|
|
l.Println(l.SprintError(a...))
|
2023-02-17 20:01:26 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
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...)
|
|
|
|
}
|
2023-02-17 20:29:46 +01:00
|
|
|
|
|
|
|
func (l *Logger) Println(a ...any) {
|
|
|
|
fmt.Fprintln(l.w, a...)
|
|
|
|
}
|
|
|
|
|
|
|
|
func (l *Logger) Print(a ...any) {
|
|
|
|
fmt.Fprint(l.w, a...)
|
|
|
|
}
|