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...)
// FIXME: Potential cause if last log line doesn't get printed sometimes.
os.Stdout, os.Stderr = w, w
log.SetOutput(writer)
gin.DefaultWriter, gin.DefaultErrorWriter = writer, writer

View File

@ -11,17 +11,16 @@ import (
c "github.com/fatih/color"
)
// type Logger interface {
// Printf(format string, v ...interface{})
// Print(v ...interface{})
// Println(v ...interface{})
// Fatal(v ...interface{})
// Fatalf(format string, v ...interface{})
// SetFatalFunc(f func(err interface{}))
// }
type Logger interface {
Printf(format string, v ...interface{})
Print(v ...interface{})
Println(v ...interface{})
Fatal(v ...interface{})
Fatalf(format string, v ...interface{})
SetFatalFunc(f func(err interface{}))
}
type Logger struct {
empty bool
type logger struct {
logger *log.Logger
shortfile bool
printer *c.Color
@ -47,8 +46,7 @@ func Lshortfile() string {
return file + ":" + lineString + ":"
}
func NewLogger(out io.Writer, prefix string, flag int, color c.Attribute) (l *Logger) {
l = &Logger{}
func NewLogger(out io.Writer, prefix string, flag int, color c.Attribute) (l logger) {
// Use reimplemented Lshortfile since wrapping the log functions messes them up
if flag&log.Lshortfile != 0 {
flag -= log.Lshortfile
@ -60,12 +58,7 @@ func NewLogger(out io.Writer, prefix string, flag int, color c.Attribute) (l *Lo
return l
}
func NewEmptyLogger() (l *Logger) { l.empty = true; return }
func (l *Logger) Printf(format string, v ...interface{}) {
if l.empty {
return
}
func (l logger) Printf(format string, v ...interface{}) {
var out string
if l.shortfile {
out = Lshortfile()
@ -74,10 +67,7 @@ func (l *Logger) Printf(format string, v ...interface{}) {
l.logger.Print(out)
}
func (l *Logger) Print(v ...interface{}) {
if l.empty {
return
}
func (l logger) Print(v ...interface{}) {
var out string
if l.shortfile {
out = Lshortfile()
@ -86,10 +76,7 @@ func (l *Logger) Print(v ...interface{}) {
l.logger.Print(out)
}
func (l *Logger) Println(v ...interface{}) {
if l.empty {
return
}
func (l logger) Println(v ...interface{}) {
var out string
if l.shortfile {
out = Lshortfile()
@ -98,10 +85,7 @@ func (l *Logger) Println(v ...interface{}) {
l.logger.Print(out)
}
func (l *Logger) Fatal(v ...interface{}) {
if l.empty {
return
}
func (l logger) Fatal(v ...interface{}) {
var out string
if l.shortfile {
out = Lshortfile()
@ -110,22 +94,29 @@ func (l *Logger) Fatal(v ...interface{}) {
l.logger.Fatal(out)
}
func (l *Logger) Fatalf(format string, v ...interface{}) {
if l.empty {
return
}
func (l logger) Fatalf(format string, v ...interface{}) {
var out string
if l.shortfile {
out = Lshortfile()
}
out += " " + l.printer.Sprintf(format, v...)
if l.fatalFunc != nil {
l.logger.Print(out)
l.fatalFunc(errors.New(out))
} else {
l.logger.Fatal(out)
}
}
func (l *Logger) SetFatalFunc(f func(err interface{})) {
func (l logger) SetFatalFunc(f func(err interface{})) {
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
discord *DiscordDaemon
matrix *MatrixDaemon
info, debug, err *logger.Logger
info, debug, err logger.Logger
host string
port int
version string
@ -234,7 +234,7 @@ func start(asDaemon, firstCall bool) {
if debugMode {
app.debug = logger.NewLogger(os.Stdout, "[DEBUG] ", log.Ltime|log.Lshortfile, color.FgYellow)
} else {
app.debug = logger.NewEmptyLogger()
app.debug = logger.EmptyLogger(false)
}
if *PPROF {
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",
"typescript": "^4.0.3",
"uncss": "^0.17.3"
},
"devDependencies": {
"live-server": "^1.2.1"
}
}