forked from fluxcd/flux
-
Notifications
You must be signed in to change notification settings - Fork 0
/
logging.go
148 lines (128 loc) · 3.85 KB
/
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
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
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
package remote
import (
"context"
"github.com/go-kit/kit/log"
"github.com/weaveworks/flux/api"
"github.com/weaveworks/flux/api/v10"
"github.com/weaveworks/flux/api/v11"
"github.com/weaveworks/flux/api/v6"
"github.com/weaveworks/flux/api/v9"
"github.com/weaveworks/flux/job"
"github.com/weaveworks/flux/update"
)
var _ api.Server = &ErrorLoggingServer{}
var _ api.UpstreamServer = &ErrorLoggingUpstreamServer{}
type ErrorLoggingServer struct {
server api.Server
logger log.Logger
}
func NewErrorLoggingServer(s api.Server, l log.Logger) *ErrorLoggingServer {
return &ErrorLoggingServer{s, l}
}
func (p *ErrorLoggingServer) Export(ctx context.Context) (config []byte, err error) {
defer func() {
if err != nil {
// Omit config as it could be large
p.logger.Log("method", "Export", "error", err)
}
}()
return p.server.Export(ctx)
}
func (p *ErrorLoggingServer) ListServices(ctx context.Context, maybeNamespace string) (_ []v6.ControllerStatus, err error) {
defer func() {
if err != nil {
p.logger.Log("method", "ListServices", "error", err)
}
}()
return p.server.ListServices(ctx, maybeNamespace)
}
func (p *ErrorLoggingServer) ListServicesWithOptions(ctx context.Context, opts v11.ListServicesOptions) (_ []v6.ControllerStatus, err error) {
defer func() {
if err != nil {
p.logger.Log("method", "ListServicesWithOptions", "error", err)
}
}()
return p.server.ListServicesWithOptions(ctx, opts)
}
func (p *ErrorLoggingServer) ListImages(ctx context.Context, spec update.ResourceSpec) (_ []v6.ImageStatus, err error) {
defer func() {
if err != nil {
p.logger.Log("method", "ListImages", "error", err)
}
}()
return p.server.ListImages(ctx, spec)
}
func (p *ErrorLoggingServer) ListImagesWithOptions(ctx context.Context, opts v10.ListImagesOptions) (_ []v6.ImageStatus, err error) {
defer func() {
if err != nil {
p.logger.Log("method", "ListImagesWithOptions", "error", err)
}
}()
return p.server.ListImagesWithOptions(ctx, opts)
}
func (p *ErrorLoggingServer) JobStatus(ctx context.Context, jobID job.ID) (_ job.Status, err error) {
defer func() {
if err != nil {
p.logger.Log("method", "JobStatus", "error", err)
}
}()
return p.server.JobStatus(ctx, jobID)
}
func (p *ErrorLoggingServer) SyncStatus(ctx context.Context, ref string) (_ []string, err error) {
defer func() {
if err != nil {
p.logger.Log("method", "SyncStatus", "error", err)
}
}()
return p.server.SyncStatus(ctx, ref)
}
func (p *ErrorLoggingServer) UpdateManifests(ctx context.Context, u update.Spec) (_ job.ID, err error) {
defer func() {
if err != nil {
p.logger.Log("method", "UpdateManifests", "error", err)
}
}()
return p.server.UpdateManifests(ctx, u)
}
func (p *ErrorLoggingServer) GitRepoConfig(ctx context.Context, regenerate bool) (_ v6.GitConfig, err error) {
defer func() {
if err != nil {
p.logger.Log("method", "GitRepoConfig", "error", err)
}
}()
return p.server.GitRepoConfig(ctx, regenerate)
}
type ErrorLoggingUpstreamServer struct {
*ErrorLoggingServer
server api.UpstreamServer
}
func NewErrorLoggingUpstreamServer(s api.UpstreamServer, l log.Logger) *ErrorLoggingUpstreamServer {
return &ErrorLoggingUpstreamServer{
NewErrorLoggingServer(s, l),
s,
}
}
func (p *ErrorLoggingUpstreamServer) Ping(ctx context.Context) (err error) {
defer func() {
if err != nil {
p.logger.Log("method", "Ping", "error", err)
}
}()
return p.server.Ping(ctx)
}
func (p *ErrorLoggingUpstreamServer) Version(ctx context.Context) (v string, err error) {
defer func() {
if err != nil {
p.logger.Log("method", "Version", "error", err, "version", v)
}
}()
return p.server.Version(ctx)
}
func (p *ErrorLoggingUpstreamServer) NotifyChange(ctx context.Context, change v9.Change) (err error) {
defer func() {
if err != nil {
p.logger.Log("method", "NotifyChange", "error", err)
}
}()
return p.server.NotifyChange(ctx, change)
}