-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathdiagnostics.go
More file actions
92 lines (79 loc) · 2.84 KB
/
Copy pathdiagnostics.go
File metadata and controls
92 lines (79 loc) · 2.84 KB
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
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
package diagnostics
import (
"context"
"fmt"
"log"
"github.com/omniviewdev/omniview/backend/pkg/apperror"
)
// DiagnosticsClient provides a client to the UI to be able to record ui side logs,
// view ui and backend logs, as well as other diagnostic imformation.
type DiagnosticsClient struct {
UI *BackendLogger
}
func NewDiagnosticsClient(dev bool, logDir string) *DiagnosticsClient {
uiLogger, err := NewBackendLogger("ui", dev, logDir)
if err != nil {
log.Fatalf("failed to init UI logger: %v", err)
}
return &DiagnosticsClient{
UI: uiLogger,
}
}
// Debug records a debug level log to the log sink
func (c *DiagnosticsClient) Debug(msg string, fields map[string]any) {
ctx := context.TODO()
c.UI.Debug(ctx, msg, fields)
}
// Info records an info level log to the log sink
func (c *DiagnosticsClient) Info(msg string, fields map[string]any) {
ctx := context.TODO()
c.UI.Info(ctx, msg, fields)
}
// Warn records a warn level log to the log sink
func (c *DiagnosticsClient) Warn(msg string, fields map[string]any) {
ctx := context.TODO()
c.UI.Warn(ctx, msg, fields)
}
// Error records an error level log to the log sink
func (c *DiagnosticsClient) Error(msg string, fields map[string]any) {
ctx := context.TODO()
c.UI.Error(ctx, msg, fields)
}
// Log records an arbitrary log with a set level to the log sink
func (c *DiagnosticsClient) Log(level, msg string, fields map[string]any) {
ctx := context.TODO()
c.UI.Log(ctx, level, msg, fields)
}
// ReadLog returns the string contents of the log requested
func (c *DiagnosticsClient) ReadLog(logType string) (string, error) {
ctx := context.TODO()
switch logType {
case "app":
return "", apperror.NotImplemented("App log reading", "App log reading is not yet supported.")
case "ui":
return c.UI.ReadLog(ctx, "ui")
}
return "", apperror.New(apperror.TypeValidation, 422, "Unknown log type", fmt.Sprintf("Log type '%s' is not recognized. Valid types are: app, ui.", logType))
}
// StartTail starts tailing the log to the event stream
func (c *DiagnosticsClient) StartTail(logType string) error {
ctx := context.TODO()
switch logType {
case "app":
return apperror.NotImplemented("App log reading", "App log reading is not yet supported.")
case "ui":
return c.UI.StartTail(ctx, "ui")
}
return apperror.New(apperror.TypeValidation, 422, "Unknown log type", fmt.Sprintf("Log type '%s' is not recognized. Valid types are: app, ui.", logType))
}
// StopTail stops tailing the log to the event stream
func (c *DiagnosticsClient) StopTail(logType string) error {
ctx := context.TODO()
switch logType {
case "app":
return apperror.NotImplemented("App log reading", "App log reading is not yet supported.")
case "ui":
return c.UI.StopTail(ctx, "ui")
}
return apperror.New(apperror.TypeValidation, 422, "Unknown log type", fmt.Sprintf("Log type '%s' is not recognized. Valid types are: app, ui.", logType))
}