-
-
Notifications
You must be signed in to change notification settings - Fork 760
/
resolver_subscription_logging.go
63 lines (54 loc) · 1.16 KB
/
resolver_subscription_logging.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
package api
import (
"context"
"github.com/stashapp/stash/internal/log"
"github.com/stashapp/stash/internal/manager"
)
func getLogLevel(logType string) LogLevel {
switch logType {
case "progress":
return LogLevelProgress
case "trace":
return LogLevelTrace
case "debug":
return LogLevelDebug
case "info":
return LogLevelInfo
case "warn":
return LogLevelWarning
case "error":
return LogLevelError
default:
return LogLevelDebug
}
}
func logEntriesFromLogItems(logItems []log.LogItem) []*LogEntry {
ret := make([]*LogEntry, len(logItems))
for i, entry := range logItems {
ret[i] = &LogEntry{
Time: entry.Time,
Level: getLogLevel(entry.Type),
Message: entry.Message,
}
}
return ret
}
func (r *subscriptionResolver) LoggingSubscribe(ctx context.Context) (<-chan []*LogEntry, error) {
ret := make(chan []*LogEntry, 100)
stop := make(chan int, 1)
logger := manager.GetInstance().Logger
logSub := logger.SubscribeToLog(stop)
go func() {
for {
select {
case logEntries := <-logSub:
ret <- logEntriesFromLogItems(logEntries)
case <-ctx.Done():
stop <- 0
close(ret)
return
}
}
}()
return ret, nil
}