-
Notifications
You must be signed in to change notification settings - Fork 1.4k
Logger update #1213
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Logger update #1213
Conversation
logger.go
Outdated
Level log15.Lvl | ||
} | ||
|
||
func (s loggerRewrite) Write(p []byte) (n int, err error) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
need explicit deprecation message to be painfully clear to revel users when running code that uses this deprecated code
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
s
vs lr
?
logger.go
Outdated
// INFO 2017/07/25 14:53:40 db.go:768: [gorp] begin; [] (138.433µs) | ||
func terminalFormat(noColor bool) log15.Format { | ||
return log15.FormatFunc(func(r *log15.Record) []byte { | ||
var color = 0 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
add comments for what colors these correspond to
logger.go
Outdated
k, v = errorKey, formatLogfmtValue(k) | ||
} | ||
|
||
// XXX: we should probably check that all of your key bytes aren't invalid |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
XXX
? Maybe TODO
logger.go
Outdated
b := &bytes.Buffer{} | ||
lvl := strings.ToUpper(r.Lvl.String()) | ||
if noColor == false && color > 0 { | ||
// fn := findInContext("fn",r.Ctx) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
delete?
logger.go
Outdated
fmt.Fprintf(b, "[%s] [%s] %s ", lvl, r.Time.Format(termTimeFormat), r.Msg) | ||
} | ||
|
||
// try to justify the log output for short messages |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Try
server-engine.go
Outdated
@@ -154,13 +156,10 @@ func handleInternal(ctx ServerContext) { | |||
// RequestStartTime ClientIP ResponseStatus RequestLatency HTTPMethod URLPath | |||
// Sample format: | |||
// 2016/05/25 17:46:37.112 127.0.0.1 200 270.157µs GET / |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Update the comment
7f7fb80
to
b7ef138
Compare
On controller creation a logger is attached to the controller, this logger has contextual information like the clientIp, request path, etc etc. Every log message sent to this logger will add this to the log message Added ability to log to json files. If log file ends in json then the logger will write to that file Added ability to define logger.maxsize (in mega bytes) defaults to 10G Added ability to define logger.maxage (in days) defaults to 7 If either of those values are exceeded the log file is rotated - ie the old is renamed and a new one is created
@brendensoares Did a bigger update to the code base - I moved most of the logger code inside a |
On controller creation a logger is attached to the controller, this logger has contextual information like the clientIp, request path, etc etc. Every log message sent to this logger will add this to the log message Added ability to log to json files. If log file ends in json then the logger will write to that file Added ability to define logger.maxsize (in mega bytes) defaults to 10G Added ability to define logger.maxage (in days) defaults to 7 If either of those values are exceeded the log file is rotated - ie the old is renamed and a new one is created Logger implementation is contained inside of the revel/logger package Added defaults so logging was not discarded (when used by the revel harness)
9ff6c36
to
b65288f
Compare
I think |
@zuoRambo thanks for the feedback - The reason we choose to deprecate those variables is because the functionality is contained inside the revel.AppLog, I realize it may be some work to switch over existing applications to use the new logging, but with the new logging you get some extended features like JSON log records with field/values. Let me know if you have more reasons for revel.ERROR log messages to remain open |
# Conflicts: # template.go
This logger provides context logging for the controller, and it provides the ability to output in either json or text file format. Log messages and key value pairs. File rotation is also handled based on either the file size or the number of days specified in the app.config
Logging
By default a new logger is available for the application called revel.AppLog - its interface is using the log15 interface (see here) You can assign log handlers which can perform multiple functions.
NOTE The new logger expects message values in key value pairs. For example
revel.AppLog.Debug("Hi there")
is finerevel.AppLog.Debug("Hi there", 25)
will panic (only passed one argument for the context).revel.AppLog.Debug("Hi there","age",25,"sex","yes","state",254)
is fine. and will produce a log message that includes the context age,sex,state.The logger in the controller adds the ability to extend its context so you can say
c.Log = c.Log.New("user",userid)
and all subsequent logs using that controller will report the'user'=userid
in the log files. Each request instance in the controller will create a new log context so all your logs messages during the request will be unique. Revel create thec.Log
using a context that includes the ip, request path and request methodDefault operation
By default it operates the same as the old logging utility. Unless the log file ends in
json
, in that case the log output will be in json format. Log file size is limited to 10G in size but may be specified in app.conflog.maxsize
(in MB). Log file age is limited to 14 days be default unless specified in app.conflog.maxage
(in days). If either is exceeded the file is date stamped and a new file is created.Deprecated loggers
revel.ERROR
,revel.WARN
,revel.INFO
,revel.TRACE
, are deprecated. Controllers in applications should log to the context loggercontroller.Log
and jobs should log torevel.AppLog
Sample Screen Shot

TODO
app.conf