@@ -80,6 +80,153 @@ func NewSync(token, environment, codeVersion, serverHost, serverRoot string) *Cl
80
80
}
81
81
}
82
82
83
+ // Log reports an item with the given level. This function recognizes arguments with the following types:
84
+ //
85
+ // *http.Request
86
+ // error
87
+ // string
88
+ // map[string]interface{}
89
+ // int
90
+ // context.Context
91
+ //
92
+ // The string and error types are mutually exclusive.
93
+ // If an error is present then a stack trace is captured. If an int is also present then we skip
94
+ // that number of stack frames. If the map is present it is used as extra custom data in the
95
+ // item. If a string is present without an error, then we log a message without a stack
96
+ // trace. If a request is present we extract as much relevant information from it as we can. If
97
+ // a context is present, it is applied to downstream operations.
98
+ func (c * Client ) Log (level string , interfaces ... interface {}) {
99
+ var r * http.Request
100
+ var err error
101
+ var skip int
102
+ skipSet := false
103
+ var extras map [string ]interface {}
104
+ var msg string
105
+ ctx := context .TODO ()
106
+ for _ , ival := range interfaces {
107
+ switch val := ival .(type ) {
108
+ case * http.Request :
109
+ r = val
110
+ case error :
111
+ err = val
112
+ case int :
113
+ skip = val
114
+ skipSet = true
115
+ case string :
116
+ msg = val
117
+ case map [string ]interface {}:
118
+ extras = val
119
+ case context.Context :
120
+ ctx = val
121
+ default :
122
+ rollbarError (c .Transport .(* AsyncTransport ).Logger , "Unknown input type: %T" , val )
123
+ }
124
+ }
125
+ if ! skipSet {
126
+ skip = 2
127
+ }
128
+ if err != nil {
129
+ if r == nil {
130
+ c .ErrorWithStackSkipWithExtrasAndContext (ctx , level , err , skip , extras )
131
+ } else {
132
+ c .RequestErrorWithStackSkipWithExtrasAndContext (ctx , level , r , err , skip , extras )
133
+ }
134
+ } else {
135
+ if r == nil {
136
+ c .MessageWithExtrasAndContext (ctx , level , msg , extras )
137
+ } else {
138
+ c .RequestMessageWithExtrasAndContext (ctx , level , r , msg , extras )
139
+ }
140
+ }
141
+ }
142
+
143
+ // -- Reporting
144
+
145
+ // Critical reports an item with level `critical`. This function recognizes arguments with the following types:
146
+ //
147
+ // *http.Request
148
+ // error
149
+ // string
150
+ // map[string]interface{}
151
+ // int
152
+ //
153
+ // The string and error types are mutually exclusive.
154
+ // If an error is present then a stack trace is captured. If an int is also present then we skip
155
+ // that number of stack frames. If the map is present it is used as extra custom data in the
156
+ // item. If a string is present without an error, then we log a message without a stack
157
+ // trace. If a request is present we extract as much relevant information from it as we can.
158
+ func (c * Client ) Critical (interfaces ... interface {}) {
159
+ c .Log (CRIT , interfaces ... )
160
+ }
161
+
162
+ // Error reports an item with level `error`. This function recognizes arguments with the following types:
163
+ //
164
+ // *http.Request
165
+ // error
166
+ // string
167
+ // map[string]interface{}
168
+ // int
169
+ //
170
+ // The string and error types are mutually exclusive.
171
+ // If an error is present then a stack trace is captured. If an int is also present then we skip
172
+ // that number of stack frames. If the map is present it is used as extra custom data in the
173
+ // item. If a string is present without an error, then we log a message without a stack
174
+ // trace. If a request is present we extract as much relevant information from it as we can.
175
+ func (c * Client ) Error (interfaces ... interface {}) {
176
+ c .Log (ERR , interfaces ... )
177
+ }
178
+
179
+ // Warning reports an item with level `warning`. This function recognizes arguments with the following types:
180
+ //
181
+ // *http.Request
182
+ // error
183
+ // string
184
+ // map[string]interface{}
185
+ // int
186
+ //
187
+ // The string and error types are mutually exclusive.
188
+ // If an error is present then a stack trace is captured. If an int is also present then we skip
189
+ // that number of stack frames. If the map is present it is used as extra custom data in the
190
+ // item. If a string is present without an error, then we log a message without a stack
191
+ // trace. If a request is present we extract as much relevant information from it as we can.
192
+ func (c * Client ) Warning (interfaces ... interface {}) {
193
+ c .Log (WARN , interfaces ... )
194
+ }
195
+
196
+ // Info reports an item with level `info`. This function recognizes arguments with the following types:
197
+ //
198
+ // *http.Request
199
+ // error
200
+ // string
201
+ // map[string]interface{}
202
+ // int
203
+ //
204
+ // The string and error types are mutually exclusive.
205
+ // If an error is present then a stack trace is captured. If an int is also present then we skip
206
+ // that number of stack frames. If the map is present it is used as extra custom data in the
207
+ // item. If a string is present without an error, then we log a message without a stack
208
+ // trace. If a request is present we extract as much relevant information from it as we can.
209
+ func (c * Client ) Info (interfaces ... interface {}) {
210
+ c .Log (INFO , interfaces ... )
211
+ }
212
+
213
+ // Debug reports an item with level `debug`. This function recognizes arguments with the following types:
214
+ //
215
+ // *http.Request
216
+ // error
217
+ // string
218
+ // map[string]interface{}
219
+ // int
220
+ //
221
+ // The string and error types are mutually exclusive.
222
+ // If an error is present then a stack trace is captured. If an int is also present then we skip
223
+ // that number of stack frames. If the map is present it is used as extra custom data in the
224
+ // item. If a string is present without an error, then we log a message without a stack
225
+ // trace. If a request is present we extract as much relevant information from it as we can.
226
+ func (c * Client ) Debug (interfaces ... interface {}) {
227
+ c .Log (DEBUG , interfaces ... )
228
+ }
229
+
83
230
// CaptureTelemetryEvent sets the user-specified telemetry event
84
231
func (c * Client ) CaptureTelemetryEvent (eventType , eventlevel string , eventData map [string ]interface {}) {
85
232
data := map [string ]interface {}{}
0 commit comments