Improve log display, use a <pre> so it can be easily cut and pasted.
This commit is contained in:
42
log/log.go
Normal file
42
log/log.go
Normal file
@@ -0,0 +1,42 @@
|
||||
package log
|
||||
|
||||
import (
|
||||
"time"
|
||||
)
|
||||
|
||||
type LogEntryType string
|
||||
|
||||
type LogEntry struct {
|
||||
Timestamp time.Time `json:"ts"`
|
||||
Type LogEntryType `json:"type"`
|
||||
Entry string `json:"log"`
|
||||
}
|
||||
|
||||
const (
|
||||
LogTypeInfo = "info"
|
||||
LogTypeError = "error"
|
||||
LogTypeDebug = "debug"
|
||||
)
|
||||
|
||||
var LogEntries []LogEntry
|
||||
var logInput chan LogEntry
|
||||
|
||||
func init() {
|
||||
// wait for log entries
|
||||
logInput = make(chan LogEntry)
|
||||
go func() {
|
||||
for {
|
||||
aLog := <-logInput
|
||||
LogEntries = append(LogEntries, aLog)
|
||||
}
|
||||
}()
|
||||
}
|
||||
|
||||
func SendLog(entry string, entryType LogEntryType) {
|
||||
|
||||
logInput <- LogEntry{
|
||||
Timestamp: time.Now(),
|
||||
Entry: entry,
|
||||
Type: entryType,
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user