Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit bcb9acd

Browse filesBrowse files
authored
Merge pull request revel#1213 from notzippy/logger
Logger update
2 parents 66ad49c + 27cfe0c commit bcb9acd
Copy full SHA for bcb9acd

35 files changed

+1416
-380
lines changed

‎binder.go

Copy file name to clipboardExpand all lines: binder.go
+16-14Lines changed: 16 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,8 @@ type Binder struct {
4444
Unbind func(output map[string]string, name string, val interface{})
4545
}
4646

47+
var binderLog = RevelLog.New("section", "binder")
48+
4749
// ValueBinder is adapter for easily making one-key-value binders.
4850
func ValueBinder(f func(value string, typ reflect.Type) reflect.Value) func(*Params, string, reflect.Type) reflect.Value {
4951
return func(params *Params, name string, typ reflect.Type) reflect.Value {
@@ -82,7 +84,7 @@ var (
8284
}
8385
intValue, err := strconv.ParseInt(val, 10, 64)
8486
if err != nil {
85-
WARN.Println(err)
87+
binderLog.Warn("IntBinder Conversion Error", "error", err)
8688
return reflect.Zero(typ)
8789
}
8890
pValue := reflect.New(typ)
@@ -101,7 +103,7 @@ var (
101103
}
102104
uintValue, err := strconv.ParseUint(val, 10, 64)
103105
if err != nil {
104-
WARN.Println(err)
106+
binderLog.Warn("UintBinder Conversion Error", "error", err)
105107
return reflect.Zero(typ)
106108
}
107109
pValue := reflect.New(typ)
@@ -120,7 +122,7 @@ var (
120122
}
121123
floatValue, err := strconv.ParseFloat(val, 64)
122124
if err != nil {
123-
WARN.Println(err)
125+
binderLog.Warn("FloatBinder Conversion Error", "error", err)
124126
return reflect.Zero(typ)
125127
}
126128
pValue := reflect.New(typ)
@@ -296,7 +298,7 @@ func bindStruct(params *Params, name string, typ reflect.Type) reflect.Value {
296298
if params.JSON != nil {
297299
// Try to inject the response as a json into the created result
298300
if err := json.Unmarshal(params.JSON, resultPointer.Interface()); err != nil {
299-
WARN.Println("W: bindStruct: Unable to unmarshal request:", name, err)
301+
binderLog.Warn("bindStruct Unable to unmarshal request", "name", name, "error", err)
300302
}
301303
return result
302304
}
@@ -316,11 +318,11 @@ func bindStruct(params *Params, name string, typ reflect.Type) reflect.Value {
316318
// Time to bind this field. Get it and make sure we can set it.
317319
fieldValue := result.FieldByName(fieldName)
318320
if !fieldValue.IsValid() {
319-
WARN.Println("W: bindStruct: Field not found:", fieldName)
321+
binderLog.Warn("bindStruct Field not found", "name", fieldName)
320322
continue
321323
}
322324
if !fieldValue.CanSet() {
323-
WARN.Println("W: bindStruct: Field not settable:", fieldName)
325+
binderLog.Warn("bindStruct Field not settable", "name", fieldName)
324326
continue
325327
}
326328
boundVal := Bind(params, key[:len(name)+1+fieldLen], fieldValue.Type())
@@ -353,7 +355,7 @@ func getMultipartFile(params *Params, name string) multipart.File {
353355
if err == nil {
354356
return file
355357
}
356-
WARN.Println("Failed to open uploaded file", name, ":", err)
358+
binderLog.Warn("getMultipartFile: Failed to open uploaded file", "name", name, "error", err)
357359
}
358360
return nil
359361
}
@@ -372,7 +374,7 @@ func bindFile(params *Params, name string, typ reflect.Type) reflect.Value {
372374
// Otherwise, have to store it.
373375
tmpFile, err := ioutil.TempFile("", "revel-upload")
374376
if err != nil {
375-
WARN.Println("Failed to create a temp file to store upload:", err)
377+
binderLog.Warn("bindFile: Failed to create a temp file to store upload", "name", name, "error", err)
376378
return reflect.Zero(typ)
377379
}
378380

@@ -381,13 +383,13 @@ func bindFile(params *Params, name string, typ reflect.Type) reflect.Value {
381383

382384
_, err = io.Copy(tmpFile, reader)
383385
if err != nil {
384-
WARN.Println("Failed to copy upload to temp file:", err)
386+
binderLog.Warn("bindFile: Failed to copy upload to temp file", "name", name, "error", err)
385387
return reflect.Zero(typ)
386388
}
387389

388390
_, err = tmpFile.Seek(0, 0)
389391
if err != nil {
390-
WARN.Println("Failed to seek to beginning of temp file:", err)
392+
binderLog.Warn("bindFile: Failed to seek to beginning of temp file", "name", name, "error", err)
391393
return reflect.Zero(typ)
392394
}
393395

@@ -400,7 +402,7 @@ func bindByteArray(params *Params, name string, typ reflect.Type) reflect.Value
400402
if err == nil {
401403
return reflect.ValueOf(b)
402404
}
403-
WARN.Println("Error reading uploaded file contents:", err)
405+
binderLog.Warn("bindByteArray: Error reading uploaded file contents", "name", name, "error", err)
404406
}
405407
return reflect.Zero(typ)
406408
}
@@ -425,7 +427,7 @@ func bindMap(params *Params, name string, typ reflect.Type) reflect.Value {
425427
if params.JSON != nil {
426428
// Try to inject the response as a json into the created result
427429
if err := json.Unmarshal(params.JSON, resultPtr.Interface()); err != nil {
428-
WARN.Println("W: bindMap: Unable to unmarshal request:", name, err)
430+
binderLog.Warn("bindMap: Unable to unmarshal request", "name", name, "error", err)
429431
}
430432
return result
431433
}
@@ -472,7 +474,7 @@ func Unbind(output map[string]string, name string, val interface{}) {
472474
if binder.Unbind != nil {
473475
binder.Unbind(output, name, val)
474476
} else {
475-
ERROR.Printf("revel/binder: can not unbind %s=%s", name, val)
477+
binderLog.Error("Unbind: Unable to unmarshal request", "name", name, "value", val)
476478
}
477479
}
478480
}
@@ -482,7 +484,7 @@ func binderForType(typ reflect.Type) (Binder, bool) {
482484
if !ok {
483485
binder, ok = KindBinders[typ.Kind()]
484486
if !ok {
485-
WARN.Println("revel/binder: no binder for type:", typ)
487+
binderLog.Error("binderForType: no binder for type", "type", typ)
486488
return Binder{}, false
487489
}
488490
}

‎cache/init.go

Copy file name to clipboardExpand all lines: cache/init.go
+7-5Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -11,27 +11,29 @@ import (
1111
"github.com/revel/revel"
1212
)
1313

14+
var cacheLog = revel.RevelLog.New("section","cache")
15+
1416
func init() {
1517
revel.OnAppStart(func() {
1618
// Set the default expiration time.
1719
defaultExpiration := time.Hour // The default for the default is one hour.
1820
if expireStr, found := revel.Config.String("cache.expires"); found {
1921
var err error
2022
if defaultExpiration, err = time.ParseDuration(expireStr); err != nil {
21-
panic("Could not parse default cache expiration duration " + expireStr + ": " + err.Error())
23+
cacheLog.Panic("Could not parse default cache expiration duration " + expireStr + ": " + err.Error())
2224
}
2325
}
2426

2527
// make sure you aren't trying to use both memcached and redis
2628
if revel.Config.BoolDefault("cache.memcached", false) && revel.Config.BoolDefault("cache.redis", false) {
27-
panic("You've configured both memcached and redis, please only include configuration for one cache!")
29+
cacheLog.Panic("You've configured both memcached and redis, please only include configuration for one cache!")
2830
}
2931

3032
// Use memcached?
3133
if revel.Config.BoolDefault("cache.memcached", false) {
3234
hosts := strings.Split(revel.Config.StringDefault("cache.hosts", ""), ",")
3335
if len(hosts) == 0 {
34-
panic("Memcache enabled but no memcached hosts specified!")
36+
cacheLog.Panic("Memcache enabled but no memcached hosts specified!")
3537
}
3638

3739
Instance = NewMemcachedCache(hosts, defaultExpiration)
@@ -42,10 +44,10 @@ func init() {
4244
if revel.Config.BoolDefault("cache.redis", false) {
4345
hosts := strings.Split(revel.Config.StringDefault("cache.hosts", ""), ",")
4446
if len(hosts) == 0 {
45-
panic("Redis enabled but no Redis hosts specified!")
47+
cacheLog.Panic("Redis enabled but no Redis hosts specified!")
4648
}
4749
if len(hosts) > 1 {
48-
panic("Redis currently only supports one host!")
50+
cacheLog.Panic("Redis currently only supports one host!")
4951
}
5052
password := revel.Config.StringDefault("cache.redis.password", "")
5153
Instance = NewRedisCache(hosts[0], password, defaultExpiration)

‎cache/inmemory.go

Copy file name to clipboardExpand all lines: cache/inmemory.go
+1-2Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@ import (
1010
"time"
1111

1212
"github.com/patrickmn/go-cache"
13-
"github.com/revel/revel"
1413
"sync"
1514
)
1615

@@ -39,7 +38,7 @@ func (c InMemoryCache) Get(key string, ptrValue interface{}) error {
3938
}
4039

4140
err := fmt.Errorf("revel/cache: attempt to get %s, but can not set value %v", key, v)
42-
revel.ERROR.Println(err)
41+
cacheLog.Error(err.Error())
4342
return err
4443
}
4544

‎cache/memcached.go

Copy file name to clipboardExpand all lines: cache/memcached.go
+4-4Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ import (
99
"time"
1010

1111
"github.com/bradfitz/gomemcache/memcache"
12-
"github.com/revel/revel"
12+
"github.com/revel/revel/logger"
1313
)
1414

1515
// MemcachedCache wraps the Memcached client to meet the Cache interface.
@@ -65,8 +65,8 @@ func (c MemcachedCache) Decrement(key string, delta uint64) (newValue uint64, er
6565
}
6666

6767
func (c MemcachedCache) Flush() error {
68-
err := errors.New("revel/cache: can not flush memcached")
69-
revel.ERROR.Println(err)
68+
err := errors.New("Flush: can not flush memcached")
69+
cacheLog.Error(err.Error())
7070
return err
7171
}
7272

@@ -113,6 +113,6 @@ func convertMemcacheError(err error) error {
113113
return ErrNotStored
114114
}
115115

116-
revel.ERROR.Println("revel/cache:", err)
116+
cacheLog.Error("convertMemcacheError:","error", err,"trace",logger.NewCallStack())
117117
return err
118118
}

‎cache/redis.go

Copy file name to clipboardExpand all lines: cache/redis.go
+4-1Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,10 @@ func NewRedisCache(host string, password string, defaultExpiration time.Duration
2929
toc := time.Millisecond * time.Duration(revel.Config.IntDefault("cache.redis.timeout.connect", 10000))
3030
tor := time.Millisecond * time.Duration(revel.Config.IntDefault("cache.redis.timeout.read", 5000))
3131
tow := time.Millisecond * time.Duration(revel.Config.IntDefault("cache.redis.timeout.write", 5000))
32-
c, err := redis.DialTimeout(protocol, host, toc, tor, tow)
32+
c, err := redis.Dial(protocol, host,
33+
redis.DialConnectTimeout(toc),
34+
redis.DialReadTimeout(tor),
35+
redis.DialWriteTimeout(tow))
3336
if err != nil {
3437
return nil, err
3538
}

‎cache/serialization.go

Copy file name to clipboardExpand all lines: cache/serialization.go
+8-10Lines changed: 8 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -9,17 +9,15 @@ import (
99
"encoding/gob"
1010
"reflect"
1111
"strconv"
12-
13-
"github.com/revel/revel"
1412
)
1513

1614
// Serialize transforms the given value into bytes following these rules:
1715
// - If value is a byte array, it is returned as-is.
1816
// - If value is an int or uint type, it is returned as the ASCII representation
1917
// - Else, encoding/gob is used to serialize
2018
func Serialize(value interface{}) ([]byte, error) {
21-
if bytes, ok := value.([]byte); ok {
22-
return bytes, nil
19+
if data, ok := value.([]byte); ok {
20+
return data, nil
2321
}
2422

2523
switch v := reflect.ValueOf(value); v.Kind() {
@@ -32,7 +30,7 @@ func Serialize(value interface{}) ([]byte, error) {
3230
var b bytes.Buffer
3331
encoder := gob.NewEncoder(&b)
3432
if err := encoder.Encode(value); err != nil {
35-
revel.ERROR.Printf("revel/cache: gob encoding '%s' failed: %s", value, err)
33+
cacheLog.Error("Serialize: gob encoding failed","value", value, "error", err)
3634
return nil, err
3735
}
3836
return b.Bytes(), nil
@@ -41,8 +39,8 @@ func Serialize(value interface{}) ([]byte, error) {
4139
// Deserialize transforms bytes produced by Serialize back into a Go object,
4240
// storing it into "ptr", which must be a pointer to the value type.
4341
func Deserialize(byt []byte, ptr interface{}) (err error) {
44-
if bytes, ok := ptr.(*[]byte); ok {
45-
*bytes = byt
42+
if data, ok := ptr.(*[]byte); ok {
43+
*data = byt
4644
return
4745
}
4846

@@ -52,7 +50,7 @@ func Deserialize(byt []byte, ptr interface{}) (err error) {
5250
var i int64
5351
i, err = strconv.ParseInt(string(byt), 10, 64)
5452
if err != nil {
55-
revel.ERROR.Printf("revel/cache: failed to parse int '%s': %s", string(byt), err)
53+
cacheLog.Error("Deserialize: failed to parse int","value", string(byt), "error", err)
5654
} else {
5755
p.SetInt(i)
5856
}
@@ -62,7 +60,7 @@ func Deserialize(byt []byte, ptr interface{}) (err error) {
6260
var i uint64
6361
i, err = strconv.ParseUint(string(byt), 10, 64)
6462
if err != nil {
65-
revel.ERROR.Printf("revel/cache: failed to parse uint '%s': %s", string(byt), err)
63+
cacheLog.Error("Deserialize: failed to parse uint","value", string(byt), "error", err)
6664
} else {
6765
p.SetUint(i)
6866
}
@@ -73,7 +71,7 @@ func Deserialize(byt []byte, ptr interface{}) (err error) {
7371
b := bytes.NewBuffer(byt)
7472
decoder := gob.NewDecoder(b)
7573
if err = decoder.Decode(ptr); err != nil {
76-
revel.ERROR.Printf("revel/cache: gob decoding failed: %s", err)
74+
cacheLog.Error("Deserialize: glob decoding failed","error", err)
7775
return
7876
}
7977
return

‎compress.go

Copy file name to clipboardExpand all lines: compress.go
+5-2Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,9 @@ var compressableMimes = [...]string{
3232
"application/x-javascript",
3333
}
3434

35+
// Local log instance for this class
36+
var compressLog = RevelLog.New("section", "compress")
37+
3538
// WriteFlusher interface for compress writer
3639
type WriteFlusher interface {
3740
io.Writer
@@ -75,7 +78,7 @@ func CompressFilter(c *Controller, fc []Filter) {
7578
c.Response.SetWriter(&writer)
7679
}
7780
} else {
78-
TRACE.Printf("Compression disabled for response status (%d)", c.Response.Status)
81+
compressLog.Debug("CompressFilter: Compression disabled for response ", "status", c.Response.Status)
7982
}
8083
}
8184
fc[0](c, fc[1:])
@@ -130,7 +133,7 @@ func (c *CompressResponseWriter) Close() error {
130133
c.Header.Del("Content-Length")
131134
if err := c.compressWriter.Close(); err != nil {
132135
// TODO When writing directly to stream, an error will be generated
133-
ERROR.Println("Error closing compress writer", c.compressionType, err)
136+
compressLog.Error("Close: Error closing compress writer", "type", c.compressionType, "error", err)
134137
}
135138

136139
}

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.