mirror of
https://github.com/astaxie/beego.git
synced 2024-11-22 07:40:54 +00:00
change to pointer receiver
This commit is contained in:
parent
6e638ef6c8
commit
05c125ec2d
@ -27,7 +27,7 @@ type LogFormatter interface {
|
|||||||
|
|
||||||
// PatternLogFormatter provides a quick format method
|
// PatternLogFormatter provides a quick format method
|
||||||
// for example:
|
// for example:
|
||||||
// tes := PatternLogFormatter{Pattern: "%F:%n|%w %t>> %m", WhenFormat: "2006-01-02"}
|
// tes := &PatternLogFormatter{Pattern: "%F:%n|%w %t>> %m", WhenFormat: "2006-01-02"}
|
||||||
// RegisterFormatter("tes", tes)
|
// RegisterFormatter("tes", tes)
|
||||||
// SetGlobalFormatter("tes")
|
// SetGlobalFormatter("tes")
|
||||||
type PatternLogFormatter struct {
|
type PatternLogFormatter struct {
|
||||||
@ -35,7 +35,7 @@ type PatternLogFormatter struct {
|
|||||||
WhenFormat string
|
WhenFormat string
|
||||||
}
|
}
|
||||||
|
|
||||||
func (p PatternLogFormatter) getWhenFormatter() string {
|
func (p *PatternLogFormatter) getWhenFormatter() string {
|
||||||
s := p.WhenFormat
|
s := p.WhenFormat
|
||||||
if s == "" {
|
if s == "" {
|
||||||
s = "2006/01/02 15:04:05.123" // default style
|
s = "2006/01/02 15:04:05.123" // default style
|
||||||
@ -43,7 +43,7 @@ func (p PatternLogFormatter) getWhenFormatter() string {
|
|||||||
return s
|
return s
|
||||||
}
|
}
|
||||||
|
|
||||||
func (p PatternLogFormatter) Format(lm *LogMsg) string {
|
func (p *PatternLogFormatter) Format(lm *LogMsg) string {
|
||||||
return p.ToString(lm)
|
return p.ToString(lm)
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -62,7 +62,7 @@ func GetFormatter(name string) (LogFormatter, bool) {
|
|||||||
|
|
||||||
// 'w' when, 'm' msg,'f' filename,'F' full path,'n' line number
|
// 'w' when, 'm' msg,'f' filename,'F' full path,'n' line number
|
||||||
// 'l' level number, 't' prefix of level type, 'T' full name of level type
|
// 'l' level number, 't' prefix of level type, 'T' full name of level type
|
||||||
func (p PatternLogFormatter) ToString(lm *LogMsg) string {
|
func (p *PatternLogFormatter) ToString(lm *LogMsg) string {
|
||||||
s := []rune(p.Pattern)
|
s := []rune(p.Pattern)
|
||||||
m := map[rune]string{
|
m := map[rune]string{
|
||||||
'w': lm.When.Format(p.getWhenFormatter()),
|
'w': lm.When.Format(p.getWhenFormatter()),
|
||||||
|
@ -7,7 +7,7 @@ import (
|
|||||||
)
|
)
|
||||||
|
|
||||||
func TestPatternLogFormatter(t *testing.T) {
|
func TestPatternLogFormatter(t *testing.T) {
|
||||||
tes := PatternLogFormatter{
|
tes := &PatternLogFormatter{
|
||||||
Pattern: "%F:%n|%w%t>> %m",
|
Pattern: "%F:%n|%w%t>> %m",
|
||||||
WhenFormat: "2006-01-02",
|
WhenFormat: "2006-01-02",
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user