Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(178)

Side by Side Diff: common/logging/fields.go

Issue 1605363002: common/prpc, tools/cmd/cproto: prpc client (Closed) Base URL: https://chromium.googlesource.com/external/github.com/luci/luci-go@master
Patch Set: addressed comments Created 4 years, 11 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 // Copyright 2015 The Chromium Authors. All rights reserved. 1 // Copyright 2015 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 package logging 5 package logging
6 6
7 import ( 7 import (
8 "bytes" 8 "bytes"
9 "fmt" 9 "fmt"
10 "sort" 10 "sort"
(...skipping 158 matching lines...) Expand 10 before | Expand all | Expand 10 after
169 func (s fieldEntrySlice) Swap(i, j int) { 169 func (s fieldEntrySlice) Swap(i, j int) {
170 s[i], s[j] = s[j], s[i] 170 s[i], s[j] = s[j], s[i]
171 } 171 }
172 172
173 func (s fieldEntrySlice) Len() int { 173 func (s fieldEntrySlice) Len() int {
174 return len(s) 174 return len(s)
175 } 175 }
176 176
177 // SetFields adds the additional fields as context for the current Logger. The 177 // SetFields adds the additional fields as context for the current Logger. The
178 // display of these fields depends on the implementation of the Logger. The 178 // display of these fields depends on the implementation of the Logger. The
179 // new Logger will contain the combination of its current Fields, updated with 179 // new context will contain the combination of its current Fields, updated with
180 // the new ones (see Fields.Copy). Specifying the new fields as nil will 180 // the new ones (see Fields.Copy). Specifying the new fields as nil will
181 // clear the currently set fields. 181 // clear the currently set fields.
182 func SetFields(c context.Context, fields Fields) context.Context { 182 func SetFields(c context.Context, fields Fields) context.Context {
183 return context.WithValue(c, fieldsKey, GetFields(c).Copy(fields)) 183 return context.WithValue(c, fieldsKey, GetFields(c).Copy(fields))
184 } 184 }
185 185
186 // SetField is a convenience method for SetFields for a single key/value 186 // SetField is a convenience method for SetFields for a single key/value
187 // pair. 187 // pair.
188 func SetField(c context.Context, key string, value interface{}) context.Context { 188 func SetField(c context.Context, key string, value interface{}) context.Context {
189 return SetFields(c, Fields{key: value}) 189 return SetFields(c, Fields{key: value})
190 } 190 }
191 191
192 // GetFields returns the current Fields. 192 // GetFields returns the current Fields.
193 // 193 //
194 // This method is used for logger implementations with the understanding that 194 // This method is used for logger implementations with the understanding that
195 // the returned fields must not be mutated. 195 // the returned fields must not be mutated.
196 func GetFields(c context.Context) Fields { 196 func GetFields(c context.Context) Fields {
197 if ret, ok := c.Value(fieldsKey).(Fields); ok { 197 if ret, ok := c.Value(fieldsKey).(Fields); ok {
198 return ret 198 return ret
199 } 199 }
200 return nil 200 return nil
201 } 201 }
OLDNEW
« no previous file with comments | « common/errors/wrap.go ('k') | common/prpc/client.go » ('j') | common/prpc/client.go » ('J')

Powered by Google App Engine
This is Rietveld 408576698