Skip to content

Commit

Permalink
gorm log 添加换行
Browse files Browse the repository at this point in the history
  • Loading branch information
committed Oct 30, 2023
1 parent a2b5795 commit 2847bc6
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 11 deletions.
14 changes: 7 additions & 7 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,12 +1,11 @@
# Visual Studio Code
.vscode/
### JetBrains template
# Covers JetBrains IDEs: IntelliJ, RubyMine, PhpStorm, AppCode, PyCharm, CLion, Android Studio, WebStorm and Rider
# Reference: https://intellij-support.jetbrains.com/hc/en-us/articles/206544839

# Local History for Visual Studio Code
.history/

# Built Visual Studio Code Extensions
*.vsix
# User-specific stuff
.idea/

### Go template
# If you prefer the allow list template instead of the deny list, see community template:
# https://github.com/github/gitignore/blob/main/community/Golang/Go.AllowList.gitignore
#
Expand All @@ -28,3 +27,4 @@

# Go workspace file
go.work

8 changes: 4 additions & 4 deletions gormTool/logger.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,18 +13,18 @@ func (w *myWriter) LogMode(logger.LogLevel) logger.Interface {
}

func (w *myWriter) Info(_ context.Context, msg string, data ...interface{}) {
w.WriteString(fmt.Sprintf("%v [Info] %v", time.Now().Format("2006-01-02 15:04:05"), fmt.Sprintf(msg, data...)))
w.WriteString(fmt.Sprintf("%v [Info] %v\n", time.Now().Format("2006-01-02 15:04:05"), fmt.Sprintf(msg, data...)))
}

func (w *myWriter) Warn(_ context.Context, msg string, data ...interface{}) {
w.WriteString(fmt.Sprintf("%v [Warn] %v", time.Now().Format("2006-01-02 15:04:05"), fmt.Sprintf(msg, data...)))
w.WriteString(fmt.Sprintf("%v [Warn] %v\n", time.Now().Format("2006-01-02 15:04:05"), fmt.Sprintf(msg, data...)))
}

func (w *myWriter) Error(_ context.Context, msg string, data ...interface{}) {
w.WriteString(fmt.Sprintf("%v [Error] %v", time.Now().Format("2006-01-02 15:04:05"), fmt.Sprintf(msg, data...)))
w.WriteString(fmt.Sprintf("%v [Error] %v\n", time.Now().Format("2006-01-02 15:04:05"), fmt.Sprintf(msg, data...)))
}

func (w *myWriter) Trace(_ context.Context, begin time.Time, fc func() (string, int64), _ error) {
sql, rows := fc()
w.WriteString(fmt.Sprintf("%v:%v [%v] | %v", begin.Format("2006-01-02 15:04:05"), time.Since(begin), rows, sql))
w.WriteString(fmt.Sprintf("%v:%v [%v] | %v\n", begin.Format("2006-01-02 15:04:05"), time.Since(begin), rows, sql))
}

0 comments on commit 2847bc6

Please sign in to comment.