Skip to content

Commit

Permalink
Update dependencies (#17)
Browse files Browse the repository at this point in the history
- Fix errors reported by the go compiler
- apply go fmt
- Fix the tests
  • Loading branch information
jocgir authored Sep 30, 2024
1 parent db93f30 commit c5d4f86
Show file tree
Hide file tree
Showing 19 changed files with 82 additions and 102 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/pr.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -10,3 +10,5 @@

# Output of the go coverage tool, specifically when used with LiteIDE
*.out

.vscode/
15 changes: 0 additions & 15 deletions .vscode/settings.json

This file was deleted.

2 changes: 1 addition & 1 deletion color/attribute.go
Original file line number Diff line number Diff line change
Expand Up @@ -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()
}
7 changes: 4 additions & 3 deletions color/doc.go
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand All @@ -36,7 +36,7 @@ configured as out stream or error stream.
ErrorPrintln("There is something wrong!")
}
Example
# Example
Here is a complete example:
Expand Down Expand Up @@ -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
*/
Expand Down
10 changes: 5 additions & 5 deletions color/format.go
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand All @@ -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...)) }
Expand All @@ -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 {
Expand Down
5 changes: 3 additions & 2 deletions color/format_test.go
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
//go:build linux || darwin
// +build linux darwin

package multicolor
Expand Down Expand Up @@ -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() {
Expand Down Expand Up @@ -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) {
Expand Down
2 changes: 1 addition & 1 deletion console_hook.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
27 changes: 14 additions & 13 deletions doc.go
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand All @@ -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
2 changes: 1 addition & 1 deletion duration.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
2 changes: 1 addition & 1 deletion file_hook.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
5 changes: 0 additions & 5 deletions formatter.go
Original file line number Diff line number Diff line change
Expand Up @@ -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}
Expand Down
6 changes: 3 additions & 3 deletions generic_hook.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -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 }
21 changes: 14 additions & 7 deletions go.mod
Original file line number Diff line number Diff line change
@@ -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
)
55 changes: 23 additions & 32 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -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=
2 changes: 1 addition & 1 deletion level.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
4 changes: 2 additions & 2 deletions level_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"`)
}
12 changes: 6 additions & 6 deletions logger_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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())

Expand Down Expand Up @@ -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:
Expand Down
3 changes: 0 additions & 3 deletions reutils/multimatch_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,6 @@ import (
)

func TestMultiMatch(t *testing.T) {
type args struct {
s string
}
tests := []struct {
name string
s string
Expand Down

0 comments on commit c5d4f86

Please sign in to comment.