added more strategies
This commit is contained in:
29
strategy/colored.go
Normal file
29
strategy/colored.go
Normal file
@ -0,0 +1,29 @@
|
||||
package strategy
|
||||
|
||||
import (
|
||||
"git.schreifuchs.ch/schreifuchs/logger"
|
||||
"git.schreifuchs.ch/schreifuchs/logger/lvl"
|
||||
)
|
||||
|
||||
func Colored(logs <-chan *logger.Log) {
|
||||
for log := range logs {
|
||||
println(colorize(log.Level, log.Message))
|
||||
}
|
||||
}
|
||||
|
||||
// colorize colors a string for the shell matching to its level
|
||||
func colorize(l lvl.Level, str string) string {
|
||||
var color string
|
||||
|
||||
switch l {
|
||||
case lvl.Debug:
|
||||
color = "\033[32m" // green
|
||||
case lvl.Info:
|
||||
color = "\033[97m" // white
|
||||
case lvl.Warn:
|
||||
color = "\033[33m" // yellow
|
||||
case lvl.Error:
|
||||
color = "\033[31m" // red
|
||||
}
|
||||
return color + str + "\033[0m"
|
||||
}
|
@ -1 +0,0 @@
|
||||
package strategy
|
57
strategy/json.go
Normal file
57
strategy/json.go
Normal file
@ -0,0 +1,57 @@
|
||||
package strategy
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"os"
|
||||
"time"
|
||||
|
||||
"git.schreifuchs.ch/schreifuchs/logger"
|
||||
"git.schreifuchs.ch/schreifuchs/logger/lvl"
|
||||
)
|
||||
|
||||
// JSON logs to std wit the schema:
|
||||
// {"time":"","level":"","message":""}.
|
||||
func JSON(logs <-chan *logger.Log) {
|
||||
for log := range logs {
|
||||
timedLog := struct {
|
||||
Time time.Time `json:"time"`
|
||||
LVL lvl.Level `json:"level"`
|
||||
Message string `json:"message"`
|
||||
}{
|
||||
Time: time.Now(),
|
||||
LVL: log.Level,
|
||||
Message: log.Message,
|
||||
}
|
||||
|
||||
out, err := json.Marshal(timedLog)
|
||||
if err != nil {
|
||||
fmt.Println("Error while marshaling log: ", err)
|
||||
os.Exit(1)
|
||||
}
|
||||
println(string(out))
|
||||
}
|
||||
}
|
||||
|
||||
// JSON logs to std wit the schema:
|
||||
// {"time":"","level":"","message":""}.
|
||||
func JSON(logs <-chan *logger.Log) {
|
||||
for log := range logs {
|
||||
timedLog := struct {
|
||||
Time time.Time `json:"time"`
|
||||
LVL lvl.Level `json:"level"`
|
||||
Message string `json:"message"`
|
||||
}{
|
||||
Time: time.Now(),
|
||||
LVL: log.Level,
|
||||
Message: log.Message,
|
||||
}
|
||||
|
||||
out, err := json.Marshal(timedLog)
|
||||
if err != nil {
|
||||
fmt.Println("Error while marshaling log: ", err)
|
||||
os.Exit(1)
|
||||
}
|
||||
println(string(out))
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user