-
Notifications
You must be signed in to change notification settings - Fork 13
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #6 from prashantgupta24/dev
improve logging
- Loading branch information
Showing
10 changed files
with
187 additions
and
64 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,75 @@ | ||
package logging | ||
|
||
import ( | ||
"github.com/sirupsen/logrus" | ||
log "github.com/sirupsen/logrus" | ||
) | ||
|
||
const ( | ||
JSONFormat = "json" | ||
TextFormat = "text" | ||
|
||
Info = "info" | ||
Debug = "debug" | ||
) | ||
|
||
func New() *log.Logger { | ||
logger := log.New() | ||
logger.Formatter = &logrus.TextFormatter{ | ||
FullTimestamp: true, | ||
} | ||
logger.SetLevel(logrus.InfoLevel) | ||
return logger | ||
} | ||
|
||
func NewLoggerLevel(logLevel string) *log.Logger { | ||
logger := log.New() | ||
logger.Formatter = &logrus.TextFormatter{ | ||
FullTimestamp: true, | ||
} | ||
|
||
switch { | ||
case logLevel == "debug": | ||
logger.SetLevel(logrus.DebugLevel) | ||
default: | ||
logger.SetLevel(logrus.InfoLevel) | ||
} | ||
return logger | ||
} | ||
|
||
func NewLoggerFormat(format string) *log.Logger { | ||
logger := log.New() | ||
|
||
switch { | ||
case format == "json": | ||
logger.Formatter = &logrus.JSONFormatter{} | ||
default: | ||
logger.Formatter = &logrus.TextFormatter{ | ||
FullTimestamp: true, | ||
} | ||
} | ||
|
||
logger.SetLevel(logrus.InfoLevel) | ||
return logger | ||
} | ||
|
||
func NewLoggerLevelFormat(logLevel string, format string) *log.Logger { | ||
logger := log.New() | ||
switch { | ||
case logLevel == "debug": | ||
logger.SetLevel(logrus.DebugLevel) | ||
default: | ||
logger.SetLevel(logrus.InfoLevel) | ||
} | ||
|
||
switch { | ||
case format == "json": | ||
logger.Formatter = &logrus.JSONFormatter{} | ||
default: | ||
logger.Formatter = &logrus.TextFormatter{ | ||
FullTimestamp: true, | ||
} | ||
} | ||
|
||
return logger | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.