58 lines
996 B
Go
58 lines
996 B
Go
|
|
package cmpSnipper
|
|
|
|
import (
|
|
"fmt"
|
|
"log"
|
|
"time"
|
|
"encoding/json"
|
|
)
|
|
|
|
func (app *App) LogMod(arg interface{}) string {
|
|
var str string
|
|
|
|
switch t := arg.(type) {
|
|
case nil:
|
|
str = /* "N:" + */ "null"
|
|
|
|
case string:
|
|
str = /* "S:" + */ t
|
|
|
|
case error:
|
|
str = /* "E:" + */ t.Error()
|
|
|
|
case byte:
|
|
str = /* "B:" + */ string(t)
|
|
|
|
case []byte:
|
|
str = /* "A:" + */ string(t)
|
|
|
|
case interface{}:
|
|
obyte, _ := json.MarshalIndent(arg, "", "\t")
|
|
str = /* "J:" + */ string(obyte)
|
|
|
|
default:
|
|
str = /* "U:" + */ fmt.Sprintf("Unknown type %T", t)
|
|
}
|
|
|
|
return str
|
|
}
|
|
|
|
func (app *App) Log(farg any, iargs ...interface{}) {
|
|
var str = app.LogMod(farg)
|
|
|
|
log.SetPrefix(time.Now().UTC().Format("2006-01-02 15:04:05") + ": ")
|
|
|
|
oargs := make([]interface{}, len(iargs))
|
|
|
|
for k, arg := range iargs {
|
|
oargs[k] = app.LogMod(arg)
|
|
}
|
|
|
|
log.Output(2, fmt.Sprintf(str + "\n", oargs...))
|
|
}
|
|
|
|
func (app *App) LogSetup() {
|
|
log.SetFlags( log.Lshortfile );
|
|
}
|