| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657 |
- package fairwind
- import (
- "sync"
- "syscall/js"
- )
- type Log struct {
- mutex sync.Mutex
- formatter LogFormatter
- lines []LogLine
- }
- func NewLog(formatter LogFormatter) *Log {
- return &Log{
- formatter: formatter,
- lines: []LogLine{},
- }
- }
- func (this *Log) Debug(message string, parameters ...LoggingParameter) {
- this.log(SEVERITY_DEBUG, message, parameters...)
- }
- func (this *Log) Information(message string, parameters ...LoggingParameter) {
- this.log(SEVERITY_INFORMATION, message, parameters...)
- }
- func (this *Log) Warning(message string, parameters ...LoggingParameter) {
- this.log(SEVERITY_WARNING, message, parameters...)
- }
- func (this *Log) Error(message string, parameters ...LoggingParameter) {
- this.log(SEVERITY_ERROR, message, parameters...)
- }
- func (this *Log) Critical(message string, parameters ...LoggingParameter) {
- this.log(SEVERITY_CRITICAL, message, parameters...)
- }
- func (this *Log) log(severity int, message string, parameters ...LoggingParameter) {
- this.mutex.Lock()
- defer this.mutex.Unlock()
- // TODO: detect OS
- console := js.Global().Get("console")
- line, err := this.formatter.Format(
- *NewLogLine(severity, message, parameters),
- )
- if err != nil {
- // TODO: log error OS-specific
- return
- }
- console.Call("log", line)
- }
|