1
1
mirror of https://github.com/OJ/gobuster.git synced 2024-09-18 11:01:34 +02:00
gobuster/libgobuster/logger.go
Christian Mehlmauer ba619dd1be
3.6
2023-08-14 10:17:02 +02:00

81 lines
1.4 KiB
Go

package libgobuster
import (
"log"
"os"
"github.com/fatih/color"
)
type Logger struct {
log *log.Logger
errorLog *log.Logger
debugLog *log.Logger
infoLog *log.Logger
debug bool
}
func NewLogger(debug bool) Logger {
return Logger{
log: log.New(os.Stdout, "", 0),
errorLog: log.New(os.Stderr, color.New(color.FgRed).Sprint("[ERROR] "), 0),
debugLog: log.New(os.Stderr, color.New(color.FgBlue).Sprint("[DEBUG] "), 0),
infoLog: log.New(os.Stderr, color.New(color.FgCyan).Sprint("[INFO] "), 0),
debug: debug,
}
}
func (l Logger) Debug(v ...any) {
if !l.debug {
return
}
l.debugLog.Print(v...)
}
func (l Logger) Debugf(format string, v ...any) {
if !l.debug {
return
}
l.debugLog.Printf(format, v...)
}
func (l Logger) Info(v ...any) {
l.infoLog.Print(v...)
}
func (l Logger) Infof(format string, v ...any) {
l.infoLog.Printf(format, v...)
}
func (l Logger) Print(v ...any) {
l.log.Print(v...)
}
func (l Logger) Printf(format string, v ...any) {
l.log.Printf(format, v...)
}
func (l Logger) Println(v ...any) {
l.log.Println(v...)
}
func (l Logger) Error(v ...any) {
l.errorLog.Print(v...)
}
func (l Logger) Errorf(format string, v ...any) {
l.errorLog.Printf(format, v...)
}
func (l Logger) Fatal(v ...any) {
l.errorLog.Fatal(v...)
}
func (l Logger) Fatalf(format string, v ...any) {
l.errorLog.Fatalf(format, v...)
}
func (l Logger) Fatalln(v ...any) {
l.errorLog.Fatalln(v...)
}