Skip to content

Commit

Permalink
feat: improve log output and add pretty json
Browse files Browse the repository at this point in the history
  • Loading branch information
aeneasr committed May 20, 2020
1 parent e55212d commit 8785324
Show file tree
Hide file tree
Showing 4 changed files with 49 additions and 5 deletions.
4 changes: 2 additions & 2 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,10 @@ require (
github.com/gobuffalo/packr v1.22.0
github.com/gobuffalo/pop/v5 v5.0.11
github.com/google/uuid v1.1.0
github.com/jackc/pgconn v1.5.0
github.com/jackc/pgx/v4 v4.4.1
github.com/jmoiron/sqlx v1.2.0
github.com/julienschmidt/httprouter v1.2.0
github.com/lib/pq v1.3.0
github.com/luna-duclos/instrumentedsql v1.1.2
github.com/mattn/goveralls v0.0.2
github.com/mitchellh/go-homedir v1.1.0
Expand All @@ -30,7 +30,7 @@ require (
github.com/pkg/profile v1.2.1
github.com/rs/cors v1.6.0
github.com/rubenv/sql-migrate v0.0.0-20190212093014-1007f53448d7
github.com/sirupsen/logrus v1.5.0
github.com/sirupsen/logrus v1.6.0
github.com/spf13/cast v1.3.1
github.com/spf13/cobra v0.0.7
github.com/stretchr/testify v1.5.1
Expand Down
4 changes: 4 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -535,6 +535,8 @@ github.com/konsorten/go-windows-terminal-sequences v1.0.1 h1:mweAR1A6xJ3oS2pRaGi
github.com/konsorten/go-windows-terminal-sequences v1.0.1/go.mod h1:T0+1ngSBFLxvqU3pZ+m/2kptfBszLMUkC4ZK/EgS/cQ=
github.com/konsorten/go-windows-terminal-sequences v1.0.2 h1:DB17ag19krx9CFsz4o3enTrPXyIXCl+2iCXH/aMAp9s=
github.com/konsorten/go-windows-terminal-sequences v1.0.2/go.mod h1:T0+1ngSBFLxvqU3pZ+m/2kptfBszLMUkC4ZK/EgS/cQ=
github.com/konsorten/go-windows-terminal-sequences v1.0.3 h1:CE8S1cTafDpPvMhIxNJKvHsGVBgn1xWYf1NbHQhywc8=
github.com/konsorten/go-windows-terminal-sequences v1.0.3/go.mod h1:T0+1ngSBFLxvqU3pZ+m/2kptfBszLMUkC4ZK/EgS/cQ=
github.com/kr/logfmt v0.0.0-20140226030751-b84e30acd515/go.mod h1:+0opPa2QZZtGFBFZlji/RkVcI2GknAs/DXo4wKdlNEc=
github.com/kr/pretty v0.1.0 h1:L/CwN0zerZDmRFUapSPitk6f+Q3+0za1rQkzVuMiMFI=
github.com/kr/pretty v0.1.0/go.mod h1:dAy3ld7l9f0ibDNOQOHHMYYIIbhfbHSm3C4ZsoJORNo=
Expand Down Expand Up @@ -774,6 +776,8 @@ github.com/sirupsen/logrus v1.4.2 h1:SPIRibHv4MatM3XXNO2BJeFLZwZ2LvZgfQ5+UNI2im4
github.com/sirupsen/logrus v1.4.2/go.mod h1:tLMulIdttU9McNUspp0xgXVQah82FyeX6MwdIuYE2rE=
github.com/sirupsen/logrus v1.5.0 h1:1N5EYkVAPEywqZRJd7cwnRtCb6xJx7NH3T3WUTF980Q=
github.com/sirupsen/logrus v1.5.0/go.mod h1:+F7Ogzej0PZc/94MaYx/nvG9jOFMD2osvC3s+Squfpo=
github.com/sirupsen/logrus v1.6.0 h1:UBcNElsrwanuuMsnGSlYmtmgbb23qDR5dG+6X6Oo89I=
github.com/sirupsen/logrus v1.6.0/go.mod h1:7uNnSEd1DgxDLC74fIahvMZmmYsHGZGEOFrfsX/uA88=
github.com/smartystreets/assertions v0.0.0-20180927180507-b2de0cb4f26d h1:zE9ykElWQ6/NYmHa3jpm/yHnI4xSofP+UP6SpjHcSeM=
github.com/smartystreets/assertions v0.0.0-20180927180507-b2de0cb4f26d/go.mod h1:OnSkiWE9lh6wB0YB77sQom3nweQdgAjqCqsofrRNTgc=
github.com/smartystreets/goconvey v0.0.0-20180222194500-ef6db91d284a/go.mod h1:XDJAKZRPZ1CvBcN2aX5YOUTYGHki24fSF0Iv48Ibg0s=
Expand Down
15 changes: 12 additions & 3 deletions logrusx/logrus.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,11 +22,20 @@ func New() *logrus.Logger {
}
l.Level = ll

if stringsx.Coalesce(
switch stringsx.Coalesce(
viper.GetString("log.format"),
viper.GetString("LOG_FORMAT"),
) == "json" {
l.Formatter = new(logrus.JSONFormatter)
){
case "json":
l.Formatter = &logrus.JSONFormatter{}
case "json_pretty":
l.Formatter = &logrus.JSONFormatter{
PrettyPrint: true,
}
default:
l.Formatter = &logrus.TextFormatter{
DisableQuote: true,
}
}

return l
Expand Down
31 changes: 31 additions & 0 deletions logrusx/logrusx.schema.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
{
"$id": "https://github.com/ory/x/logrusx/config.schema.json",
"$schema": "http://json-schema.org/draft-07/schema#",
"title": "Logger Configuration",
"type": "object",
"properties": {
"level": {
"title": "Log Level",
"type": "string",
"enum": [
"trace",
"debug",
"info",
"warning",
"error",
"fatal",
"panic"
]
},
"format": {
"title": "Log Level",
"type": "string",
"enum": [
"json",
"json_pretty",
"text"
]
}
},
"additionalProperties": false
}

0 comments on commit 8785324

Please sign in to comment.