1
0
mirror of https://github.com/astaxie/beego.git synced 2024-12-22 12:40:50 +00:00

change to pointer receiver

This commit is contained in:
wangle 2020-09-19 20:18:09 +08:00
parent 6e638ef6c8
commit 05c125ec2d
2 changed files with 5 additions and 5 deletions

View File

@ -27,7 +27,7 @@ type LogFormatter interface {
// PatternLogFormatter provides a quick format method
// 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)
// SetGlobalFormatter("tes")
type PatternLogFormatter struct {
@ -35,7 +35,7 @@ type PatternLogFormatter struct {
WhenFormat string
}
func (p PatternLogFormatter) getWhenFormatter() string {
func (p *PatternLogFormatter) getWhenFormatter() string {
s := p.WhenFormat
if s == "" {
s = "2006/01/02 15:04:05.123" // default style
@ -43,7 +43,7 @@ func (p PatternLogFormatter) getWhenFormatter() string {
return s
}
func (p PatternLogFormatter) Format(lm *LogMsg) string {
func (p *PatternLogFormatter) Format(lm *LogMsg) string {
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
// '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)
m := map[rune]string{
'w': lm.When.Format(p.getWhenFormatter()),

View File

@ -7,7 +7,7 @@ import (
)
func TestPatternLogFormatter(t *testing.T) {
tes := PatternLogFormatter{
tes := &PatternLogFormatter{
Pattern: "%F:%n|%w%t>> %m",
WhenFormat: "2006-01-02",
}