Skip to content

Navigation Menu

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 183fdec

Browse filesBrowse files
committed
improvements found by testing
Added nfilter to logging Fixed bug in handlers change logger to use error.Stack instead of a new call stack
1 parent a39fdb3 commit 183fdec
Copy full SHA for 183fdec

File tree

4 files changed

+78
-35
lines changed
Filter options

4 files changed

+78
-35
lines changed

‎.codebeatsettings

Copy file name to clipboardExpand all lines: .codebeatsettings
+3Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
11
{
22
"GOLANG": {
3+
"ABC":[15, 25, 50, 70],
4+
"BLOCK_NESTING":[5, 6, 7, 8],
5+
"CYCLO":[20, 30, 45, 60],
36
"TOO_MANY_IVARS": [15, 18, 20, 25],
47
"TOO_MANY_FUNCTIONS": [20, 30, 40, 50],
58
"TOTAL_COMPLEXITY": [150, 250, 400, 500],

‎logger/handlers.go

Copy file name to clipboardExpand all lines: logger/handlers.go
+16-2Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -78,8 +78,18 @@ func NilHandler() LogHandler {
7878
})
7979
}
8080

81-
// Rather then chaining multiple filter handlers, process all here
81+
// Match all values in map to log
8282
func MatchMapHandler(matchMap map[string]interface{}, a LogHandler) LogHandler {
83+
return matchMapHandler(matchMap, false, a)
84+
}
85+
86+
// Match !(Match all values in map to log) The inverse of MatchMapHandler
87+
func NotMatchMapHandler(matchMap map[string]interface{}, a LogHandler) LogHandler {
88+
return matchMapHandler(matchMap, true, a)
89+
}
90+
91+
// Rather then chaining multiple filter handlers, process all here
92+
func matchMapHandler(matchMap map[string]interface{}, inverse bool, a LogHandler) LogHandler {
8393
return log15.FuncHandler(func(r *log15.Record) error {
8494
checkMap := map[string]bool{}
8595
// Copy the map to a bool
@@ -89,6 +99,10 @@ func MatchMapHandler(matchMap map[string]interface{}, a LogHandler) LogHandler {
8999
}
90100
}
91101
if len(checkMap) == len(matchMap) {
102+
if !inverse {
103+
return a.Log(r)
104+
}
105+
} else if inverse {
92106
return a.Log(r)
93107
}
94108
return nil
@@ -232,7 +246,7 @@ func (h *CompositeMultiHandler) SetHandler(handler LogHandler, replace bool, lev
232246
if ll, found := (*source).(*ListLogHandler); found {
233247
ll.Add(handler)
234248
} else {
235-
*source = NewListLogHandler(h.CriticalHandler, handler)
249+
*source = NewListLogHandler(*source, handler)
236250
}
237251
} else {
238252
*source = handler

‎logger/utils.go

Copy file name to clipboardExpand all lines: logger/utils.go
+58-31Lines changed: 58 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -44,13 +44,19 @@ func GetLogger(name string, logger MultiLogger) (l *log.Logger) {
4444
func InitializeFromConfig(basePath string, config *config.Context) (c *CompositeMultiHandler) {
4545
// If the configuration has an all option we can skip some
4646
c, _ = NewCompositeMultiHandler()
47+
48+
// Filters are assigned first, non filtered items override filters
4749
initAllLog(c, basePath, config)
4850
initLogLevels(c, basePath, config)
49-
initRequestLog(c, basePath, config)
50-
// Check to see if critical handler needs to be assigned to the error handler
5151
if c.CriticalHandler == nil && c.ErrorHandler != nil {
5252
c.CriticalHandler = c.ErrorHandler
5353
}
54+
initFilterLog(c, basePath, config)
55+
if c.CriticalHandler == nil && c.ErrorHandler != nil {
56+
c.CriticalHandler = c.ErrorHandler
57+
}
58+
initRequestLog(c, basePath, config)
59+
5460
return c
5561
}
5662

@@ -62,19 +68,57 @@ func initAllLog(c *CompositeMultiHandler, basePath string, config *config.Contex
6268
log.Printf("Adding standard handler for levels to >%s< ", output)
6369
initHandlerFor(c, output, basePath, NewLogOptions(config, true, nil, LvlAllList...))
6470
}
65-
optionList := config.Options("log.all.filter")
66-
for _, option := range optionList {
67-
splitOptions := strings.Split(option, ".")
68-
keyMap := map[string]interface{}{}
69-
for x := 3; x < len(splitOptions); x += 2 {
70-
keyMap[splitOptions[x]] = splitOptions[x+1]
71-
}
71+
}
72+
}
7273

73-
log.Printf("Adding key map handler to all %s output %s", option, config.StringDefault(option, ""))
74-
phandler := NewParentLogHandler(func(child LogHandler) LogHandler {
75-
return MatchMapHandler(keyMap, child)
76-
})
77-
initHandlerFor(c, config.StringDefault(option, ""), basePath, NewLogOptions(config, false, phandler))
74+
// Init the filter options
75+
// log.all.filter ....
76+
// log.error.filter ....
77+
func initFilterLog(c *CompositeMultiHandler, basePath string, config *config.Context) {
78+
if config != nil {
79+
// The commands to use
80+
logFilterList := []struct {
81+
LogPrefix, LogSuffix string
82+
parentHandler func(map[string]interface{}) ParentLogHandler
83+
}{{
84+
"log.", ".filter",
85+
func(keyMap map[string]interface{}) ParentLogHandler {
86+
return NewParentLogHandler(func(child LogHandler) LogHandler {
87+
return MatchMapHandler(keyMap, child)
88+
})
89+
90+
},
91+
}, {
92+
"log.", ".nfilter",
93+
func(keyMap map[string]interface{}) ParentLogHandler {
94+
return NewParentLogHandler(func(child LogHandler) LogHandler {
95+
return NotMatchMapHandler(keyMap, child)
96+
})
97+
},
98+
}}
99+
100+
for _, logFilter := range logFilterList {
101+
// Init for all filters
102+
for _, name := range []string{"all", "debug", "info", "warn", "error", "crit",
103+
"trace", // TODO trace is deprecated
104+
} {
105+
optionList := config.Options(logFilter.LogPrefix + name + logFilter.LogSuffix)
106+
for _, option := range optionList {
107+
splitOptions := strings.Split(option, ".")
108+
keyMap := map[string]interface{}{}
109+
for x := 3; x < len(splitOptions); x += 2 {
110+
keyMap[splitOptions[x]] = splitOptions[x+1]
111+
}
112+
phandler := logFilter.parentHandler(keyMap)
113+
log.Printf("Adding key map handler %s %s output %s", option, name, config.StringDefault(option, ""))
114+
115+
if name == "all" {
116+
initHandlerFor(c, config.StringDefault(option, ""), basePath, NewLogOptions(config, false, phandler))
117+
} else {
118+
initHandlerFor(c, config.StringDefault(option, ""), basePath, NewLogOptions(config, false, phandler, toLevel[name]))
119+
}
120+
}
121+
}
78122
}
79123
}
80124
}
@@ -90,23 +134,6 @@ func initLogLevels(c *CompositeMultiHandler, basePath string, config *config.Con
90134
log.Printf("Adding standard handler %s output %s", name, output)
91135
initHandlerFor(c, output, basePath, NewLogOptions(config, true, nil, toLevel[name]))
92136
}
93-
// Now check to see if we have any module specific loggers
94-
// Names should be module.name or module.name.context.name
95-
optionList := config.Options("log." + name + ".filter")
96-
for _, option := range optionList {
97-
splitOptions := strings.Split(option, ".")
98-
keyMap := map[string]interface{}{}
99-
for x := 3; x < len(splitOptions); x += 2 {
100-
keyMap[splitOptions[x]] = splitOptions[x+1]
101-
}
102-
103-
phandler := NewParentLogHandler(func(child LogHandler) LogHandler {
104-
return MatchMapHandler(keyMap, child)
105-
})
106-
log.Printf("Adding key map handler %s %s output %s", option, name, config.StringDefault(option, ""))
107-
initHandlerFor(c, config.StringDefault(option, ""), basePath, NewLogOptions(config, false, phandler, toLevel[name]))
108-
}
109-
110137
// Gets the list of options with said prefix
111138
} else {
112139
initHandlerFor(c, "stderr", basePath, NewLogOptions(config, true, nil, toLevel[name]))

‎panic.go

Copy file name to clipboardExpand all lines: panic.go
+1-2Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@
55
package revel
66

77
import (
8-
"github.com/revel/revel/logger"
98
"net/http"
109
"runtime/debug"
1110
)
@@ -25,7 +24,7 @@ func PanicFilter(c *Controller, fc []Filter) {
2524
// It cleans up the stack trace, logs it, and displays an error page.
2625
func handleInvocationPanic(c *Controller, err interface{}) {
2726
error := NewErrorFromPanic(err)
28-
utilLog.Error("PanicFilter: Caught panic", "error", err, "trace", logger.NewCallStack())
27+
utilLog.Error("PanicFilter: Caught panic", "error", err, "stack", error.Stack)
2928
if error == nil && DevMode {
3029
// Only show the sensitive information in the debug stack trace in development mode, not production
3130
c.Response.SetStatus(http.StatusInternalServerError)

0 commit comments

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