Skip to content

Commit

Permalink
add option for extended logging
Browse files Browse the repository at this point in the history
  • Loading branch information
tessus committed May 23, 2023
1 parent 62a1c99 commit e33a190
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 2 deletions.
1 change: 1 addition & 0 deletions config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ type Configuration struct {
UploadedImagesDir string `default:"data/images"`
PluginsDir string `default:"data/plugins"`
Registration bool `default:"false"`
ExtendedLogFormat bool `default:"true"`
}

func configFiles() []string {
Expand Down
19 changes: 17 additions & 2 deletions router/router.go
Original file line number Diff line number Diff line change
Expand Up @@ -175,6 +175,21 @@ func Create(db *database.GormDatabase, vInfo *model.VersionInfo, conf *config.Co

var tokenRegexp = regexp.MustCompile("token=[^&]+")

var logFormat string

Check failure on line 178 in router/router.go

View workflow job for this annotation

GitHub Actions / gotify

File is not `gofumpt`-ed with `-extra` (gofumpt)
var dateTimeFormat string

func init() {
conf := config.Get()
fmt.Printf("init() ExtendedLogFormat = %t\n", conf.ExtendedLogFormat)
if conf.ExtendedLogFormat == true {
logFormat = "%v |%s %3d %s| %13v | %15s |%s %-7s %s %#v\n%s"
dateTimeFormat = "2006-01-02 15:04:05 -07:00"
} else {
logFormat = "[GIN] %v |%s %3d %s| %13v | %15s |%s %-7s %s %#v\n%s"
dateTimeFormat = "2006/01/02 - 15:04:05"
}
}

func logFormatter(param gin.LogFormatterParams) string {
var statusColor, methodColor, resetColor string
if param.IsOutputColor() {
Expand All @@ -187,8 +202,8 @@ func logFormatter(param gin.LogFormatterParams) string {
param.Latency = param.Latency - param.Latency%time.Second
}
path := tokenRegexp.ReplaceAllString(param.Path, "token=[masked]")
return fmt.Sprintf("[GIN] %v |%s %3d %s| %13v | %15s |%s %-7s %s %#v\n%s",
param.TimeStamp.Format("2006/01/02 - 15:04:05"),
return fmt.Sprintf(logFormat,
param.TimeStamp.Format(dateTimeFormat),
statusColor, param.StatusCode, resetColor,
param.Latency,
param.ClientIP,
Expand Down

0 comments on commit e33a190

Please sign in to comment.