1
0
mirror of https://github.com/hrfee/jfa-go.git synced 2025-01-08 09:20:11 +00:00

Compare commits

..

No commits in common. "b29c24a405237b19999d5bd1d422e51f7210b298" and "f727e2c5b21c5da71698ba9cdcd5eef825de2a27" have entirely different histories.

5 changed files with 36 additions and 4599 deletions

1
log.go
View File

@ -39,7 +39,6 @@ func logOutput() (closeFunc func()) {
} }
} }
writer := io.MultiWriter(writers...) writer := io.MultiWriter(writers...)
// FIXME: Potential cause if last log line doesn't get printed sometimes.
os.Stdout, os.Stderr = w, w os.Stdout, os.Stderr = w, w
log.SetOutput(writer) log.SetOutput(writer)
gin.DefaultWriter, gin.DefaultErrorWriter = writer, writer gin.DefaultWriter, gin.DefaultErrorWriter = writer, writer

View File

@ -11,17 +11,16 @@ import (
c "github.com/fatih/color" c "github.com/fatih/color"
) )
// type Logger interface { type Logger interface {
// Printf(format string, v ...interface{}) Printf(format string, v ...interface{})
// Print(v ...interface{}) Print(v ...interface{})
// Println(v ...interface{}) Println(v ...interface{})
// Fatal(v ...interface{}) Fatal(v ...interface{})
// Fatalf(format string, v ...interface{}) Fatalf(format string, v ...interface{})
// SetFatalFunc(f func(err interface{})) SetFatalFunc(f func(err interface{}))
// } }
type Logger struct { type logger struct {
empty bool
logger *log.Logger logger *log.Logger
shortfile bool shortfile bool
printer *c.Color printer *c.Color
@ -47,8 +46,7 @@ func Lshortfile() string {
return file + ":" + lineString + ":" return file + ":" + lineString + ":"
} }
func NewLogger(out io.Writer, prefix string, flag int, color c.Attribute) (l *Logger) { func NewLogger(out io.Writer, prefix string, flag int, color c.Attribute) (l logger) {
l = &Logger{}
// Use reimplemented Lshortfile since wrapping the log functions messes them up // Use reimplemented Lshortfile since wrapping the log functions messes them up
if flag&log.Lshortfile != 0 { if flag&log.Lshortfile != 0 {
flag -= log.Lshortfile flag -= log.Lshortfile
@ -60,12 +58,7 @@ func NewLogger(out io.Writer, prefix string, flag int, color c.Attribute) (l *Lo
return l return l
} }
func NewEmptyLogger() (l *Logger) { l.empty = true; return } func (l logger) Printf(format string, v ...interface{}) {
func (l *Logger) Printf(format string, v ...interface{}) {
if l.empty {
return
}
var out string var out string
if l.shortfile { if l.shortfile {
out = Lshortfile() out = Lshortfile()
@ -74,10 +67,7 @@ func (l *Logger) Printf(format string, v ...interface{}) {
l.logger.Print(out) l.logger.Print(out)
} }
func (l *Logger) Print(v ...interface{}) { func (l logger) Print(v ...interface{}) {
if l.empty {
return
}
var out string var out string
if l.shortfile { if l.shortfile {
out = Lshortfile() out = Lshortfile()
@ -86,10 +76,7 @@ func (l *Logger) Print(v ...interface{}) {
l.logger.Print(out) l.logger.Print(out)
} }
func (l *Logger) Println(v ...interface{}) { func (l logger) Println(v ...interface{}) {
if l.empty {
return
}
var out string var out string
if l.shortfile { if l.shortfile {
out = Lshortfile() out = Lshortfile()
@ -98,10 +85,7 @@ func (l *Logger) Println(v ...interface{}) {
l.logger.Print(out) l.logger.Print(out)
} }
func (l *Logger) Fatal(v ...interface{}) { func (l logger) Fatal(v ...interface{}) {
if l.empty {
return
}
var out string var out string
if l.shortfile { if l.shortfile {
out = Lshortfile() out = Lshortfile()
@ -110,22 +94,29 @@ func (l *Logger) Fatal(v ...interface{}) {
l.logger.Fatal(out) l.logger.Fatal(out)
} }
func (l *Logger) Fatalf(format string, v ...interface{}) { func (l logger) Fatalf(format string, v ...interface{}) {
if l.empty {
return
}
var out string var out string
if l.shortfile { if l.shortfile {
out = Lshortfile() out = Lshortfile()
} }
out += " " + l.printer.Sprintf(format, v...) out += " " + l.printer.Sprintf(format, v...)
if l.fatalFunc != nil { if l.fatalFunc != nil {
l.logger.Print(out)
l.fatalFunc(errors.New(out)) l.fatalFunc(errors.New(out))
} else { } else {
l.logger.Fatal(out) l.logger.Fatal(out)
} }
} }
func (l *Logger) SetFatalFunc(f func(err interface{})) { func (l logger) SetFatalFunc(f func(err interface{})) {
l.fatalFunc = f l.fatalFunc = f
} }
type EmptyLogger bool
func (l EmptyLogger) Printf(format string, v ...interface{}) {}
func (l EmptyLogger) Print(v ...interface{}) {}
func (l EmptyLogger) Println(v ...interface{}) {}
func (l EmptyLogger) Fatal(v ...interface{}) {}
func (l EmptyLogger) Fatalf(format string, v ...interface{}) {}
func (l EmptyLogger) SetFatalFunc(f func(err interface{})) {}

View File

@ -98,7 +98,7 @@ type appContext struct {
telegram *TelegramDaemon telegram *TelegramDaemon
discord *DiscordDaemon discord *DiscordDaemon
matrix *MatrixDaemon matrix *MatrixDaemon
info, debug, err *logger.Logger info, debug, err logger.Logger
host string host string
port int port int
version string version string
@ -234,7 +234,7 @@ func start(asDaemon, firstCall bool) {
if debugMode { if debugMode {
app.debug = logger.NewLogger(os.Stdout, "[DEBUG] ", log.Ltime|log.Lshortfile, color.FgYellow) app.debug = logger.NewLogger(os.Stdout, "[DEBUG] ", log.Ltime|log.Lshortfile, color.FgYellow)
} else { } else {
app.debug = logger.NewEmptyLogger() app.debug = logger.EmptyLogger(false)
} }
if *PPROF { if *PPROF {
app.info.Print(warning("\n\nWARNING: Don't use pprof in production.\n\n")) app.info.Print(warning("\n\nWARNING: Don't use pprof in production.\n\n"))

4566
package-lock.json generated

File diff suppressed because it is too large Load Diff

View File

@ -29,8 +29,5 @@
"remove-markdown": "^0.3.0", "remove-markdown": "^0.3.0",
"typescript": "^4.0.3", "typescript": "^4.0.3",
"uncss": "^0.17.3" "uncss": "^0.17.3"
},
"devDependencies": {
"live-server": "^1.2.1"
} }
} }