diff --git a/.github/workflows/pr.yml b/.github/workflows/pr.yml index 144de8a..3a7b47b 100644 --- a/.github/workflows/pr.yml +++ b/.github/workflows/pr.yml @@ -8,7 +8,7 @@ jobs: - name: Setup Go uses: actions/setup-go@v1 with: - go-version: 1.13 + go-version: 1.21 id: go - name: Checkout diff --git a/.gitignore b/.gitignore index f1c181e..0780314 100644 --- a/.gitignore +++ b/.gitignore @@ -10,3 +10,5 @@ # Output of the go coverage tool, specifically when used with LiteIDE *.out + +.vscode/ diff --git a/.vscode/settings.json b/.vscode/settings.json deleted file mode 100644 index 1f83227..0000000 --- a/.vscode/settings.json +++ /dev/null @@ -1,15 +0,0 @@ -{ - "cSpell.words": [ - "Infoln", - "Logln", - "godoc", - "logrus", - "multilogger" - ], - "cSpell.ignoreWords": [ - "fatih", - "acarl", - "sirupsen", - "warningln" - ] -} \ No newline at end of file diff --git a/color/attribute.go b/color/attribute.go index 4c0ea7f..29421c2 100644 --- a/color/attribute.go +++ b/color/attribute.go @@ -43,7 +43,7 @@ func TryConvertAttributes(attributes ...interface{}) ([]Attribute, error) { } if len(result) == 0 { // If no color attribute as been provider, we consider it as an error - errors = append(errors, fmt.Errorf("No attribute specified")) + errors = append(errors, fmt.Errorf("no attribute specified")) } return result, errors.AsError() } diff --git a/color/doc.go b/color/doc.go index d01fc48..07f802d 100644 --- a/color/doc.go +++ b/color/doc.go @@ -5,13 +5,13 @@ /* Package multicolor is a complement to github.com/fatih/color. -Description +# Description It allows working with colors and attributes by using their string names. It also provides various print functions (Sprint, Sprintf, Sprintln, Print, Printf, Println, ErrorPrint, ErrorPrintf and Println) to let users provides colors and attributes before the actual text they want to print. -Use it as io.Writer +# Use it as io.Writer Color objects defined by fatih cannot be used to configure a stream. With multicolor, Color objects can be configured as out stream or error stream. @@ -36,7 +36,7 @@ configured as out stream or error stream. ErrorPrintln("There is something wrong!") } -Example +# Example Here is a complete example: @@ -70,6 +70,7 @@ Here is a complete example: The attributes name are not case significant. Any attributes defined in the constants can be used as string. For simplicity, it is allowed to forget the prefix FG to specify foreground colors. + Blue = FgBlue HiMagenta = FgHiMagenta */ diff --git a/color/format.go b/color/format.go index 72a3801..e441491 100644 --- a/color/format.go +++ b/color/format.go @@ -10,13 +10,13 @@ import ( // FormatMessage analyses the arguments to determine if Sprintf or Sprintln should be used. func FormatMessage(args ...interface{}) string { return formatMessage(sprintlnType, true, args...) } -// Sprint returns a string formated with attributes that are supplied before. +// Sprint returns a string formatted with attributes that are supplied before. func Sprint(args ...interface{}) string { return sprint(sprintType, args...) } -// Sprintf returns a string formated with attributes that are supplied before. +// Sprintf returns a string formatted with attributes that are supplied before. func Sprintf(args ...interface{}) string { return sprint(sprintfType, args...) } -// Sprintln returns a string formated with attributes that are supplied before. +// Sprintln returns a string formatted with attributes that are supplied before. func Sprintln(args ...interface{}) string { return sprint(sprintlnType, args...) } // Print call standard fmt.Printf function but using the color out stream. @@ -26,7 +26,7 @@ func Print(args ...interface{}) (int, error) { return fmt.Fprint(color.Output, S func Println(args ...interface{}) (int, error) { return fmt.Fprint(color.Output, Sprintln(args...)) } // Printf behave as Printf, it expects to have a format string after the color attributes. -func Printf(args ...interface{}) (int, error) { return fmt.Fprintf(color.Output, Sprintf(args...)) } +func Printf(args ...interface{}) (int, error) { return fmt.Fprint(color.Output, Sprintf(args...)) } // ErrorPrint call standard fmt.Printf function but using the color out stream. func ErrorPrint(args ...interface{}) (int, error) { return fmt.Fprint(color.Error, Sprint(args...)) } @@ -38,7 +38,7 @@ func ErrorPrintln(args ...interface{}) (int, error) { // ErrorPrintf call standard fmt.Printf function but using the color out stream. func ErrorPrintf(args ...interface{}) (int, error) { - return fmt.Fprintf(color.Error, Sprintf(args...)) + return fmt.Fprint(color.Error, Sprintf(args...)) } func sprint(printType printType, args ...interface{}) string { diff --git a/color/format_test.go b/color/format_test.go index d458f52..78a3401 100644 --- a/color/format_test.go +++ b/color/format_test.go @@ -1,3 +1,4 @@ +//go:build linux || darwin // +build linux darwin package multicolor @@ -102,7 +103,7 @@ func ExamplePrintf() { Printf("red", "Hello", "world!", 1, math.Pi) // Output: // HelloHello world 123 - // Hello%!!(MISSING)(EXTRA string=world!, int=1, float64=3.141592653589793) + // Hello%!(EXTRA string=world!, int=1, float64=3.141592653589793) } func ExampleErrorPrint() { @@ -147,7 +148,7 @@ func ExampleErrorPrintf() { ErrorPrintf("red", "Hello", "world!", 1, math.Pi) // Output: // HelloHello world 123 - // Hello%!!(MISSING)(EXTRA string=world!, int=1, float64=3.141592653589793) + // Hello%!(EXTRA string=world!, int=1, float64=3.141592653589793) } func TestFormatMessage(t *testing.T) { diff --git a/console_hook.go b/console_hook.go index d906506..e39bfe8 100644 --- a/console_hook.go +++ b/console_hook.go @@ -28,7 +28,7 @@ func (hook *consoleHook) clone() logrus.Hook { } func (hook *consoleHook) Fire(entry *logrus.Entry) (err error) { - return hook.fire(entry, func() error { + return hook.fire(entry, func(entry *logrus.Entry) error { const name = "ConsoleHook" if entry.Level == outputLevel { return hook.printf(name, hook.out, entry.Message) diff --git a/doc.go b/doc.go index aeeb840..0cda7ce 100644 --- a/doc.go +++ b/doc.go @@ -7,7 +7,7 @@ Package multilogger is a thin wrapper around logrus https://github.com/sirupsen/ Each output (implemented as Hook) have their own logging level. It exposes the same API as a regular logrus logger. -How to use it +# How to use it So, you can use multilogger to write logs to standard error with a minimal logging level (i.e. WarningLevel) and have the full debug log (i.e. DebugLevel or TraceLevel) written to a file. @@ -24,20 +24,21 @@ So, you can use multilogger to write logs to standard error with a minimal loggi Differences with logrus - - The multilogger object is based on a logrus.Entry instead of a logrus.Logger. - - The methods Print, Println and Printf are used to print information directly to stdout without log decoration. - Within logrus, these methods are aliases to Info, Infoln and Infof. - - It is not possible to set the global logging level with multilogger, the logging level is determined by hooks that are - added to the logging object and the resulting logging level is the highest logging level defined for individual hooks. - - Hooks are fired according to their own logging level while they were fired according to the global logging - level with logrus. - - The default formatter used by console and file hook is highly customizable. + - The multilogger object is based on a logrus.Entry instead of a logrus.Logger. + - The methods Print, Println and Printf are used to print information directly to stdout without log decoration. + Within logrus, these methods are aliases to Info, Infoln and Infof. + - It is not possible to set the global logging level with multilogger, the logging level is determined by hooks that are + added to the logging object and the resulting logging level is the highest logging level defined for individual hooks. + - Hooks are fired according to their own logging level while they were fired according to the global logging + level with logrus. + - The default formatter used by console and file hook is highly customizable. -Where is it used +# Where is it used This project is used in other Coveo projects to reduce visual clutter in CI systems while keeping debug logs available when errors arise: - gotemplate https://github.com/coveooss/gotemplate - terragrunt https://github.com/coveooss/terragrunt - tgf https://github.com/coveooss/tgf + + gotemplate https://github.com/coveooss/gotemplate + terragrunt https://github.com/coveooss/terragrunt + tgf https://github.com/coveooss/tgf */ package multilogger diff --git a/duration.go b/duration.go index 260f085..c6a2e6b 100644 --- a/duration.go +++ b/duration.go @@ -61,7 +61,7 @@ func TryGetDurationFunc(format DurationFormat, rounded, longUnit bool) (Duration minUnit = time.Minute maxUnit = day default: - return func(d time.Duration) string { return fmt.Sprintf("%v", d) }, fmt.Errorf("Unknown format %v", format) + return func(d time.Duration) string { return fmt.Sprintf("%v", d) }, fmt.Errorf("unknown format %v", format) } return func(d time.Duration) string { diff --git a/file_hook.go b/file_hook.go index b438e91..c9040d8 100644 --- a/file_hook.go +++ b/file_hook.go @@ -45,7 +45,7 @@ func (hook *fileHook) clone() logrus.Hook { } func (hook *fileHook) Fire(entry *logrus.Entry) (err error) { - return hook.fire(entry, func() error { + return hook.fire(entry, func(entry *logrus.Entry) error { name := fmt.Sprintf("FileHook %s", hook.filename) output := entry.Message if entry.Level != outputLevel { diff --git a/formatter.go b/formatter.go index 9448a12..680a887 100644 --- a/formatter.go +++ b/formatter.go @@ -21,11 +21,6 @@ const ( durationPrecisionEnvVar = "MULTILOGGER_DURATION_PRECISION" ) -type formatterI interface { - SetLogFormat(...string) *Formatter - SetColor(bool) -} - // NewFormatter creates a new formatter with color setting and takes the first defined format string as the log format. func NewFormatter(color bool, formats ...interface{}) *Formatter { f := &Formatter{color: color} diff --git a/generic_hook.go b/generic_hook.go index 7785c70..24f59f5 100644 --- a/generic_hook.go +++ b/generic_hook.go @@ -51,7 +51,7 @@ func (hook *genericHook) printf(source string, out io.Writer, format string, arg return nil } -func (hook *genericHook) fire(entry *logrus.Entry, f func() error) (err error) { +func (hook *genericHook) fire(entry *logrus.Entry, f func(entry *logrus.Entry) error) (err error) { defer func() { err = errors.Trap(err, recover()) if hook.logger != nil && err != nil { @@ -61,11 +61,11 @@ func (hook *genericHook) fire(entry *logrus.Entry, f func() error) (err error) { } }() - return f() + return f(entry) } func (hook *genericHook) Levels() []logrus.Level { return nil } -func (hook *genericHook) Fire(entry *logrus.Entry) error { return fmt.Errorf("Not implemented") } +func (hook *genericHook) Fire(entry *logrus.Entry) error { return fmt.Errorf("not implemented") } func (hook *genericHook) SetFormatter(formatter logrus.Formatter) { hook.formatter = formatter } func (hook *genericHook) Formatter() logrus.Formatter { return hook.formatter } func (hook *genericHook) SetLogger(l *Logger) { hook.logger = l } diff --git a/go.mod b/go.mod index 859dd19..07b8d13 100644 --- a/go.mod +++ b/go.mod @@ -1,13 +1,20 @@ module github.com/coveooss/multilogger -go 1.13 +go 1.21 require ( github.com/acarl005/stripansi v0.0.0-20180116102854-5a71ef0e047d - github.com/fatih/color v1.9.0 - github.com/mattn/go-colorable v0.1.7 // indirect - github.com/niemeyer/pretty v0.0.0-20200227124842-a10e7caefd8e // indirect - github.com/sirupsen/logrus v1.6.0 - github.com/stretchr/testify v1.6.1 - gopkg.in/check.v1 v1.0.0-20200227125254-8fa46927fb4f // indirect + github.com/fatih/color v1.17.0 + github.com/sirupsen/logrus v1.9.3 + github.com/stretchr/testify v1.9.0 +) + +require ( + github.com/davecgh/go-spew v1.1.1 // indirect + github.com/mattn/go-colorable v0.1.13 // indirect + github.com/mattn/go-isatty v0.0.20 // indirect + github.com/pmezard/go-difflib v1.0.0 // indirect + golang.org/x/sys v0.25.0 // indirect + gopkg.in/check.v1 v1.0.0-20201130134442-10cb98267c6c // indirect + gopkg.in/yaml.v3 v3.0.1 // indirect ) diff --git a/go.sum b/go.sum index ecfe484..00a1765 100644 --- a/go.sum +++ b/go.sum @@ -3,43 +3,34 @@ github.com/acarl005/stripansi v0.0.0-20180116102854-5a71ef0e047d/go.mod h1:asat6 github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c= github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= -github.com/fatih/color v1.9.0 h1:8xPHl4/q1VyqGIPif1F+1V3Y3lSmrq01EabUW3CoW5s= -github.com/fatih/color v1.9.0/go.mod h1:eQcE1qtQxscV5RaZvpXrrb8Drkc3/DdQ+uUYCNjL+zU= -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/fatih/color v1.17.0 h1:GlRw1BRJxkpqUCBKzKOw098ed57fEsKeNjpTe3cSjK4= +github.com/fatih/color v1.17.0/go.mod h1:YZ7TlrGPkiz6ku9fK3TLD/pl3CpsiFyu8N92HLgmosI= +github.com/kr/pretty v0.2.1 h1:Fmg33tUaq4/8ym9TJN1x7sLJnHVwhP33CNkpYV/7rwI= +github.com/kr/pretty v0.2.1/go.mod h1:ipq/a2n7PKx3OHsz4KJII5eveXtPO4qwEXGdVfWzfnI= github.com/kr/pty v1.1.1/go.mod h1:pFQYn66WHrOpPYNljwOMqo10TkYh1fy3cYio2l3bCsQ= github.com/kr/text v0.1.0 h1:45sCR5RtlFHMR4UwH9sdQ5TC8v0qDQCHnXt+kaKSTVE= github.com/kr/text v0.1.0/go.mod h1:4Jbv+DJW3UT/LiOwJeYQe1efqtUx/iVham/4vfdArNI= -github.com/mattn/go-colorable v0.1.4 h1:snbPLB8fVfU9iwbbo30TPtbLRzwWu6aJS6Xh4eaaviA= -github.com/mattn/go-colorable v0.1.4/go.mod h1:U0ppj6V5qS13XJ6of8GYAs25YV2eR4EVcfRqFIhoBtE= -github.com/mattn/go-colorable v0.1.6 h1:6Su7aK7lXmJ/U79bYtBjLNaha4Fs1Rg9plHpcH+vvnE= -github.com/mattn/go-colorable v0.1.6/go.mod h1:u6P/XSegPjTcexA+o6vUJrdnUu04hMope9wVRipJSqc= -github.com/mattn/go-colorable v0.1.7 h1:bQGKb3vps/j0E9GfJQ03JyhRuxsvdAanXlT9BTw3mdw= -github.com/mattn/go-colorable v0.1.7/go.mod h1:u6P/XSegPjTcexA+o6vUJrdnUu04hMope9wVRipJSqc= -github.com/mattn/go-isatty v0.0.8/go.mod h1:Iq45c/XA43vh69/j3iqttzPXn0bhXyGjM0Hdxcsrc5s= -github.com/mattn/go-isatty v0.0.11 h1:FxPOTFNqGkuDUGi3H/qkUbQO4ZiBa2brKq5r0l8TGeM= -github.com/mattn/go-isatty v0.0.11/go.mod h1:PhnuNfih5lzO57/f3n+odYbM4JtupLOxQOAqxQCu2WE= -github.com/mattn/go-isatty v0.0.12 h1:wuysRhFDzyxgEmMf5xjvJ2M9dZoWAXNNr5LSBS7uHXY= -github.com/mattn/go-isatty v0.0.12/go.mod h1:cbi8OIDigv2wuxKPP5vlRcQ1OAZbq2CE4Kysco4FUpU= -github.com/niemeyer/pretty v0.0.0-20200227124842-a10e7caefd8e h1:fD57ERR4JtEqsWbfPhv4DMiApHyliiK5xCTNVSPiaAs= -github.com/niemeyer/pretty v0.0.0-20200227124842-a10e7caefd8e/go.mod h1:zD1mROLANZcx1PVRCS0qkT7pwLkGfwJo4zjcN/Tysno= +github.com/mattn/go-colorable v0.1.13 h1:fFA4WZxdEF4tXPZVKMLwD8oUnCTTo08duU7wxecdEvA= +github.com/mattn/go-colorable v0.1.13/go.mod h1:7S9/ev0klgBDR4GtXTXX8a3vIGJpMovkB8vQcUbaXHg= +github.com/mattn/go-isatty v0.0.16/go.mod h1:kYGgaQfpe5nmfYZH+SKPsOc2e4SrIfOl2e/yFXSvRLM= +github.com/mattn/go-isatty v0.0.20 h1:xfD0iDuEKnDkl03q4limB+vH+GxLEtL/jb4xVJSWWEY= +github.com/mattn/go-isatty v0.0.20/go.mod h1:W+V8PltTTMOvKvAeJH7IuucS94S2C6jfK/D7dTCTo3Y= github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM= github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4= -github.com/sirupsen/logrus v1.6.0 h1:UBcNElsrwanuuMsnGSlYmtmgbb23qDR5dG+6X6Oo89I= -github.com/sirupsen/logrus v1.6.0/go.mod h1:7uNnSEd1DgxDLC74fIahvMZmmYsHGZGEOFrfsX/uA88= +github.com/sirupsen/logrus v1.9.3 h1:dueUQJ1C2q9oE3F7wvmSGAaVtTmUizReu6fjN8uqzbQ= +github.com/sirupsen/logrus v1.9.3/go.mod h1:naHLuLoDiP4jHNo9R0sCBMtWGeIprob74mVsIT4qYEQ= github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME= -github.com/stretchr/testify v1.2.2/go.mod h1:a8OnRcib4nhh0OaRAV+Yts87kKdq0PP7pXfy6kDkUVs= -github.com/stretchr/testify v1.6.1 h1:hDPOHmpOpP40lSULcqw7IrRb/u7w6RpDC9399XyoNd0= -github.com/stretchr/testify v1.6.1/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg= -golang.org/x/sys v0.0.0-20190222072716-a9d3bda3a223/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= -golang.org/x/sys v0.0.0-20190422165155-953cdadca894/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= -golang.org/x/sys v0.0.0-20191026070338-33540a1f6037 h1:YyJpGZS1sBuBCzLAR1VEpK193GlqGZbnPFnPV/5Rsb4= -golang.org/x/sys v0.0.0-20191026070338-33540a1f6037/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= -golang.org/x/sys v0.0.0-20200116001909-b77594299b42/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= -golang.org/x/sys v0.0.0-20200223170610-d5e6a3e2c0ae h1:/WDfKMnPU+m5M4xB+6x4kaepxRw6jWvR5iDRdvjHgy8= -golang.org/x/sys v0.0.0-20200223170610-d5e6a3e2c0ae/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= +github.com/stretchr/testify v1.7.0/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg= +github.com/stretchr/testify v1.9.0 h1:HtqpIVDClZ4nwg75+f6Lvsy/wHu+3BoSGCbBAcpTsTg= +github.com/stretchr/testify v1.9.0/go.mod h1:r2ic/lqez/lEtzL7wO/rwa5dbSLXVDPFyf8C91i36aY= +golang.org/x/sys v0.0.0-20220715151400-c0bba94af5f8/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= +golang.org/x/sys v0.0.0-20220811171246-fbc7d0a398ab/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= +golang.org/x/sys v0.6.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= +golang.org/x/sys v0.25.0 h1:r+8e+loiHxRqhXVl6ML1nO3l1+oFoWbnlu2Ehimmi34= +golang.org/x/sys v0.25.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA= gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= -gopkg.in/check.v1 v1.0.0-20200227125254-8fa46927fb4f h1:BLraFXnmrev5lT+xlilqcH8XK9/i0At2xKjWk4p6zsU= -gopkg.in/check.v1 v1.0.0-20200227125254-8fa46927fb4f/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= -gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c h1:dUUwHk2QECo/6vqA44rthZ8ie2QXMNeKRTHCNY2nXvo= +gopkg.in/check.v1 v1.0.0-20201130134442-10cb98267c6c h1:Hei/4ADfdWqJk1ZMxUNpqntNwaWcugrBjAiHlqqRiVk= +gopkg.in/check.v1 v1.0.0-20201130134442-10cb98267c6c/go.mod h1:JHkPIbrfpd72SG/EVd6muEfDQjcINNoR0C8j2r3qZ4Q= gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM= +gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA= +gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM= diff --git a/level.go b/level.go index b2f8a1b..6d5b73d 100644 --- a/level.go +++ b/level.go @@ -62,7 +62,7 @@ func TryParseLogLevel(level interface{}) (logrus.Level, error) { } parsedLevel, err := logrus.ParseLevel(levelString) if err != nil { - return DisabledLevel, fmt.Errorf("Unable to parse logging level: %w", err) + return DisabledLevel, fmt.Errorf("unable to parse logging level: %w", err) } return parsedLevel, nil } diff --git a/level_test.go b/level_test.go index 826e502..3cddc08 100644 --- a/level_test.go +++ b/level_test.go @@ -40,8 +40,8 @@ func TestGetAcceptedLevels(t *testing.T) { func TestParseInvalidLogLevel(t *testing.T) { level, err := TryParseLogLevel("invalid") assert.Equal(t, level, DisabledLevel) - assert.EqualError(t, err, `Unable to parse logging level: not a valid logrus Level: "invalid"`) + assert.EqualError(t, err, `unable to parse logging level: not a valid logrus Level: "invalid"`) level, err = TryParseLogLevel(1.234) assert.Equal(t, level, DisabledLevel) - assert.EqualError(t, err, `Unable to parse logging level: not a valid logrus Level: "1.234"`) + assert.EqualError(t, err, `unable to parse logging level: not a valid logrus Level: "1.234"`) } diff --git a/logger_test.go b/logger_test.go index 4447ece..1b6570a 100644 --- a/logger_test.go +++ b/logger_test.go @@ -45,7 +45,7 @@ func ExampleNew_default() { } func ExampleNew_settingLoggingLevel() { - // Logging level could be set by explicitely declaring the hook + // Logging level could be set by explicitly declaring the hook log := New("console", NewConsoleHook("", logrus.InfoLevel)) log.Println("The logging level is set to", log.GetLevel()) @@ -156,19 +156,19 @@ func ExampleLogger_AddConsole() { func ExampleLogger_AddFile() { log := getTestLogger("file") - var logfile string + var log_file string if temp, err := ioutil.TempFile("", "example"); err != nil { log.Fatal(err) } else { - logfile = temp.Name() - defer os.Remove(logfile) + log_file = temp.Name() + defer os.Remove(log_file) } - log.AddFile(logfile, false, logrus.TraceLevel) + log.AddFile(log_file, false, logrus.TraceLevel) log.Info("This is information") log.Warning("This is a warning") - content, _ := ioutil.ReadFile(logfile) + content, _ := ioutil.ReadFile(log_file) fmt.Println("Content of the log file is:") fmt.Println(string(content)) // Output: diff --git a/reutils/multimatch_test.go b/reutils/multimatch_test.go index 666afd9..b7dff8d 100644 --- a/reutils/multimatch_test.go +++ b/reutils/multimatch_test.go @@ -9,9 +9,6 @@ import ( ) func TestMultiMatch(t *testing.T) { - type args struct { - s string - } tests := []struct { name string s string