Skip to content

Commit

Permalink
Made log.LogLevel public
Browse files Browse the repository at this point in the history
  • Loading branch information
ricardorg79 committed Aug 9, 2020
1 parent d5c214c commit 7bc5784
Show file tree
Hide file tree
Showing 3 changed files with 51 additions and 14 deletions.
37 changes: 37 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
github.com/kisielk/errcheck v1.4.0 h1:ueN6QYA+c7eDQo7ebpNdYR8mUJZThiGz9PEoJEMGPzA=
github.com/kisielk/errcheck v1.4.0/go.mod h1:pFxgyoBC7bSaBwPgfKdkLd5X25qrDl4LWUI2bnpBCr8=
github.com/tsenart/deadcode v0.0.0-20160724212837-210d2dc333e9 h1:vY5WqiEon0ZSTGM3ayVVi+twaHKHDFUVloaQ/wug9/c=
github.com/tsenart/deadcode v0.0.0-20160724212837-210d2dc333e9/go.mod h1:q+QjxYvZ+fpjMXqs+XEriussHjSYqeXVnAdSV1tkMYk=
github.com/yuin/goldmark v1.1.27/go.mod h1:3hX8gzYuyVAZsxl0MRgGTJEmQBFcNTphYh9decYSb74=
github.com/yuin/goldmark v1.1.32/go.mod h1:3hX8gzYuyVAZsxl0MRgGTJEmQBFcNTphYh9decYSb74=
golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w=
golang.org/x/crypto v0.0.0-20191011191535-87dc89f01550/go.mod h1:yigFU9vqHzYiE8UmvKecakEJjdnWj3jj499lnFckfCI=
golang.org/x/crypto v0.0.0-20200622213623-75b288015ac9/go.mod h1:LzIPMQfyMNhhGPhUkYOs5KpL4U8rLKemX1yGLhDgUto=
golang.org/x/lint v0.0.0-20200302205851-738671d3881b h1:Wh+f8QHJXR411sJR8/vRBTZ7YapZaRvUcLFFJhusH0k=
golang.org/x/lint v0.0.0-20200302205851-738671d3881b/go.mod h1:3xt1FjdF8hUf6vQPIChWIBhFzV8gjjsPE/fR3IyQdNY=
golang.org/x/mod v0.1.1-0.20191105210325-c90efee705ee/go.mod h1:QqPTAvyqsEbceGzBzNggFXnrqF1CaUcvgkdR5Ot7KZg=
golang.org/x/mod v0.2.0 h1:KU7oHjnv3XNWfa5COkzUifxZmxp1TyI7ImMXqFxLwvQ=
golang.org/x/mod v0.2.0/go.mod h1:s0Qsj1ACt9ePp/hMypM3fl4fZqREWJwdYDEqhRiZZUA=
golang.org/x/mod v0.3.0 h1:RM4zey1++hCTbCVQfnWeKs9/IEsaBLA8vTkd0WVtmH4=
golang.org/x/mod v0.3.0/go.mod h1:s0Qsj1ACt9ePp/hMypM3fl4fZqREWJwdYDEqhRiZZUA=
golang.org/x/net v0.0.0-20190404232315-eb5bcb51f2a3/go.mod h1:t9HGtf8HONx5eT2rtn7q6eTqICYqUVnKs3thJo3Qplg=
golang.org/x/net v0.0.0-20190620200207-3b0461eec859/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s=
golang.org/x/net v0.0.0-20200226121028-0de0cce0169b/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s=
golang.org/x/net v0.0.0-20200625001655-4c5254603344/go.mod h1:/O7V0waA8r7cgGh81Ro3o1hOxt32SMVPicZroKQ2sZA=
golang.org/x/sync v0.0.0-20190423024810-112230192c58/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
golang.org/x/sync v0.0.0-20190911185100-cd5d95a43a6e/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
golang.org/x/sync v0.0.0-20200625203802-6e8e738ad208/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
golang.org/x/sys v0.0.0-20190412213103-97732733099d/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.0.0-20200323222414-85ca7c5b95cd/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ=
golang.org/x/tools v0.0.0-20191119224855-298f0cb1881e/go.mod h1:b+2E5dAYhXwXZwtnZ6UAqBI28+e2cm9otk0dWdXHAEo=
golang.org/x/tools v0.0.0-20200130002326-2f3ba24bd6e7/go.mod h1:TB2adYChydJhpapKDTa4BR/hXlZSLoq2Wpct/0txZ28=
golang.org/x/tools v0.0.0-20200619180055-7c47624df98f h1:tuwaIjfUa6eI6REiNueIxvNm1popyPUnqWga83S7U0o=
golang.org/x/tools v0.0.0-20200619180055-7c47624df98f/go.mod h1:EkVYQZoAsY45+roYkvgYkIh4xh/qjgUK9TdY2XT94GE=
golang.org/x/tools v0.0.0-20200730221956-1ac65761fe2c h1:c5JjBOQWM2pRemVbog00sS+oAdi8tTR+NNRFDwUOrTQ=
golang.org/x/tools v0.0.0-20200730221956-1ac65761fe2c/go.mod h1:njjCfa9FT2d7l9Bc6FUM5FLjQPp3cFF28FI3qnDFljA=
golang.org/x/xerrors v0.0.0-20190717185122-a985d3407aa7/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
golang.org/x/xerrors v0.0.0-20191011141410-1b5146add898/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543 h1:E7g+9GITq07hpfrRu66IVDexMakfv52eLZ2CXBWiKr4=
golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
24 changes: 12 additions & 12 deletions lib.go
Original file line number Diff line number Diff line change
Expand Up @@ -46,14 +46,14 @@ const (
)

var (
logLevel = LevelInfo
LogLevel = LevelInfo
)

// SetLevel is used to set the logging level. This library only support setting
// logging level globally. The possible arguments to this function are:
// LevelFatal, LevelError, LevelWarn, LevelInfo, LevelDebug and LevelTrace.
func SetLevel(level Level) {
logLevel = level
LogLevel = level
}

// ParseLevel takes as string and return the corresponding level. The strLevel argument
Expand Down Expand Up @@ -100,7 +100,7 @@ func Fatalf(format string, v ...interface{}) {

// Error alias for Errorf
func Error(format string, v ...interface{}) {
if logLevel < LevelError {
if LogLevel < LevelError {
return
}
golog.Printf(format, v...)
Expand All @@ -110,15 +110,15 @@ func Error(format string, v ...interface{}) {
// It will call log.Printf if the log level is set Error or above.
// Arguments are handled in the manner of fmt.Printf.
func Errorf(format string, v ...interface{}) {
if logLevel < LevelError {
if LogLevel < LevelError {
return
}
golog.Printf(format, v...)
}

// Warn alias for Warnf
func Warn(format string, v ...interface{}) {
if logLevel < LevelWarn {
if LogLevel < LevelWarn {
return
}
golog.Printf(format, v...)
Expand All @@ -128,15 +128,15 @@ func Warn(format string, v ...interface{}) {
// It will call log.Printf if the log level is set Warn or above.
// Arguments are handled in the manner of fmt.Printf.
func Warnf(format string, v ...interface{}) {
if logLevel < LevelWarn {
if LogLevel < LevelWarn {
return
}
golog.Printf(format, v...)
}

// Info alias for Infof
func Info(format string, v ...interface{}) {
if logLevel < LevelInfo {
if LogLevel < LevelInfo {
return
}
golog.Printf(format, v...)
Expand All @@ -146,15 +146,15 @@ func Info(format string, v ...interface{}) {
// It will only call log.Printf if the log level is set Info or above.
// Arguments are handled in the manner of fmt.Printf.
func Infof(format string, v ...interface{}) {
if logLevel < LevelInfo {
if LogLevel < LevelInfo {
return
}
golog.Printf(format, v...)
}

// Debug alias for Debugf
func Debug(format string, v ...interface{}) {
if logLevel < LevelDebug {
if LogLevel < LevelDebug {
return
}
golog.Printf(format, v...)
Expand All @@ -164,15 +164,15 @@ func Debug(format string, v ...interface{}) {
// It will only call log.Printf if the log level is set Debug or above.
// Arguments are handled in the manner of fmt.Printf.
func Debugf(format string, v ...interface{}) {
if logLevel < LevelDebug {
if LogLevel < LevelDebug {
return
}
golog.Printf(format, v...)
}

// Trace alias for Tracef
func Trace(format string, v ...interface{}) {
if logLevel < LevelTrace {
if LogLevel < LevelTrace {
return
}
golog.Printf(format, v...)
Expand All @@ -182,7 +182,7 @@ func Trace(format string, v ...interface{}) {
// It will only call log.Printf if the log level is set Trace or above.
// Arguments are handled in the manner of fmt.Printf.
func Tracef(format string, v ...interface{}) {
if logLevel < LevelTrace {
if LogLevel < LevelTrace {
return
}
golog.Printf(format, v...)
Expand Down
4 changes: 2 additions & 2 deletions lib_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@ func TestSetLevel(t *testing.T) {
SetLevel(level)

// then
if logLevel != level {
t.Errorf("Expected %s, bug got %s", level, logLevel)
if LogLevel != level {
t.Errorf("Expected %s, bug got %s", level, LogLevel)
}
}
}
Expand Down

0 comments on commit 7bc5784

Please sign in to comment.