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 27cfe0c

Browse filesBrowse files
committed
Merge branch 'develop' of git://github.com/revel/revel into logger
# Conflicts: # template.go
2 parents 92af726 + 66ad49c commit 27cfe0c
Copy full SHA for 27cfe0c

13 files changed

+219
-125
lines changed

‎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

‎fakeapp_test.go

Copy file name to clipboardExpand all lines: fakeapp_test.go
+1-4Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -140,10 +140,7 @@ func startFakeBookingApp() {
140140
Init("prod", "github.com/revel/revel/testdata", "")
141141

142142
// Disable logging.
143-
TRACE = log.New(ioutil.Discard, "", 0)
144-
INFO = TRACE
145-
WARN = TRACE
146-
ERROR = TRACE
143+
GetRootLogHandler().Disable()
147144

148145
MainTemplateLoader = NewTemplateLoader([]string{ViewsPath, filepath.Join(RevelPath, "templates")})
149146
if err := MainTemplateLoader.Refresh(); err != nil {

‎i18n.go

Copy file name to clipboardExpand all lines: i18n.go
+1-1Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -164,7 +164,7 @@ func loadMessageFile(path string, info os.FileInfo, osError error) error {
164164

165165
i18nLog.Debug("Successfully loaded messages from file", "file", info.Name())
166166
} else {
167-
i18nLog.Warn("Ignoring file %s because it did not have a valid extension", "file", info.Name())
167+
i18nLog.Warn("Ignoring file because it did not have a valid extension", "file", info.Name())
168168
}
169169

170170
return nil

‎logger.go

Copy file name to clipboardExpand all lines: logger.go
+2-5Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,6 @@ func init() {
4848
}
4949
func initLoggers() {
5050
appHandle := logger.InitializeFromConfig(BasePath, Config)
51-
appHandle.Log(&log15.Record{Msg:"test",Lvl:log15.LvlInfo})
5251

5352
// Set all the log handlers
5453
setLog(oldLog, appHandle)
@@ -80,8 +79,6 @@ func setAppLog(appLog logger.MultiLogger, appHandler *logger.CompositeMultiHandl
8079
appLogHandler = appHandler
8180
// Set the app log and the handler for all forked loggers
8281
RootLog.SetHandler(appLogHandler)
83-
//AppLog.SetHandler(appLogHandler)
84-
//RevelLog.SetHandler(appLogHandler)
8582

8683
// Set the system log handler - this sets golang writer stream to the
8784
// sysLog router
@@ -91,7 +88,7 @@ func setAppLog(appLog logger.MultiLogger, appHandler *logger.CompositeMultiHandl
9188
}
9289
}
9390

94-
// Return the application log handler
95-
func GetAppLogHandler() *logger.CompositeMultiHandler {
91+
// Return the root log handler
92+
func GetRootLogHandler() *logger.CompositeMultiHandler {
9693
return appLogHandler
9794
}

‎logger/format.go

Copy file name to clipboardExpand all lines: logger/format.go
+9-11Lines changed: 9 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -12,17 +12,17 @@ import (
1212
)
1313

1414
const (
15-
timeFormat = "2006-01-02T15:04:05-0700"
16-
termTimeFormat = "2006/01/02 15:04:05"
15+
timeFormat = "2006-01-02T15:04:05-0700"
16+
termTimeFormat = "2006/01/02 15:04:05"
1717
termSmallTimeFormat = "15:04:05"
18-
floatFormat = 'f'
19-
errorKey = "REVEL_ERROR"
18+
floatFormat = 'f'
19+
errorKey = "REVEL_ERROR"
2020
)
21+
2122
var (
2223
// Name the log level
2324
toRevel = map[log15.Lvl]string{log15.LvlDebug: "DEBUG",
2425
log15.LvlInfo: "INFO", log15.LvlWarn: "WARN", log15.LvlError: "ERROR", log15.LvlCrit: "CRIT"}
25-
2626
)
2727

2828
// Outputs to the terminal in a format like below
@@ -55,17 +55,15 @@ func TerminalFormatHandler(noColor bool, smallDate bool) LogFormat {
5555

5656
b := &bytes.Buffer{}
5757
lvl := strings.ToUpper(r.Lvl.String())
58+
caller := findInContext("caller", r.Ctx)
59+
module := findInContext("module", r.Ctx)
5860
if noColor == false && color > 0 {
59-
caller := findInContext("caller", r.Ctx)
60-
module := findInContext("module", r.Ctx)
61-
if len(module)>0 {
61+
if len(module) > 0 {
6262
fmt.Fprintf(b, "\x1b[%dm%-5s\x1b[0m %s %6s %13s: %-40s ", color, toRevel[r.Lvl], r.Time.Format(dateFormat), module, caller, r.Msg)
6363
} else {
6464
fmt.Fprintf(b, "\x1b[%dm%-5s\x1b[0m %s %13s: %-40s ", color, toRevel[r.Lvl], r.Time.Format(dateFormat), caller, r.Msg)
6565
}
6666
} else {
67-
caller := findInContext("caller", r.Ctx)
68-
module := findInContext("module", r.Ctx)
6967
fmt.Fprintf(b, "%-5s %s %6s %13s: %-40s", toRevel[r.Lvl], r.Time.Format(dateFormat), module, caller, r.Msg)
7068
fmt.Fprintf(b, "[%s] [%s] %s ", lvl, r.Time.Format(dateFormat), r.Msg)
7169
}
@@ -76,7 +74,7 @@ func TerminalFormatHandler(noColor bool, smallDate bool) LogFormat {
7674
}
7775

7876
k, ok := r.Ctx[i].(string)
79-
if k == "caller" || k == "fn" {
77+
if k == "caller" || k == "fn" || k == "module" {
8078
continue
8179
}
8280
v := formatLogfmtValue(r.Ctx[i+1])

‎logger/handlers.go

Copy file name to clipboardExpand all lines: logger/handlers.go
+22-2Lines changed: 22 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -251,8 +251,8 @@ func (h *CompositeMultiHandler) SetHandlers(handler LogHandler, options *LogOpti
251251
}
252252
func (h *CompositeMultiHandler) SetJson(writer io.Writer, options *LogOptions) {
253253
handler := CallerFileHandler(StreamHandler(writer, log15.JsonFormatEx(
254-
options.GetBoolDefault("pretty",false),
255-
options.GetBoolDefault("lineSeparated",true),
254+
options.GetBoolDefault("pretty", false),
255+
options.GetBoolDefault("lineSeparated", true),
256256
)))
257257
if options.HandlerWrap != nil {
258258
handler = options.HandlerWrap.SetChild(handler)
@@ -294,3 +294,23 @@ func (h *CompositeMultiHandler) SetTerminalFile(filePath string, options *LogOpt
294294
}
295295
h.SetTerminal(writer, options)
296296
}
297+
298+
func (h *CompositeMultiHandler) Disable(levels ...LogLevel) {
299+
if len(levels) == 0 {
300+
levels = LvlAllList
301+
}
302+
for _, level := range levels {
303+
switch level {
304+
case LvlDebug:
305+
h.DebugHandler = nil
306+
case LvlInfo:
307+
h.InfoHandler = nil
308+
case LvlWarn:
309+
h.WarnHandler = nil
310+
case LvlError:
311+
h.ErrorHandler = nil
312+
case LvlCrit:
313+
h.CriticalHandler = nil
314+
}
315+
}
316+
}

‎server.go

Copy file name to clipboardExpand all lines: server.go
+4-1Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -71,13 +71,16 @@ func Run(port int) {
7171
CurrentEngine.Event(ENGINE_STARTED, nil)
7272
// This is needed for the harness to recognize that the server is started, it looks for the word
7373
// "Listening" in the stdout stream
74-
fmt.Fprintf(os.Stdout,"Listening on.. %s:%d\n",ServerEngineInit.Address,ServerEngineInit.Port)
74+
fmt.Fprintf(os.Stdout,"Listening on.. %s\n", ServerEngineInit.Address)
7575
CurrentEngine.Start()
7676
CurrentEngine.Event(ENGINE_SHUTDOWN, nil)
7777
}
7878

7979
func InitServerEngine(port int, serverEngine string) {
8080
address := HTTPAddr
81+
if address == "" {
82+
address = "localhost"
83+
}
8184
if port == 0 {
8285
port = HTTPPort
8386
}

0 commit comments

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