-
-
Save perigrin/4e3a9ce2fdfe9b520de745ea0ce11063 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
/* | |
A simple logging module based upon the advice of Dave Cheney | |
* https://dave.cheney.net/2015/11/05/lets-talk-about-logging | |
* https://dave.cheney.net/2017/01/23/the-package-level-logger-anti-pattern | |
*/ | |
package log | |
import ( | |
"io" | |
"github.com/rs/zerolog" | |
) | |
type Logger interface { | |
Debug(string) | |
Info(string) | |
} | |
// A Default Log Object that impelemnts the Logger interface | |
type Log struct { | |
logger zerolog.Logger | |
} | |
func New(out io.Writer) *Log { | |
consoleWriter := zerolog.ConsoleWriter{Out: out} | |
zerolog.SetGlobalLevel(zerolog.InfoLevel) | |
return &Log{zerolog.New(consoleWriter).With().Timestamp().Logger()} | |
} | |
func (l *Log) Level(lvl string) *Log { | |
l.logger = l.logger.Level(lvl) | |
} | |
// Outputs runtime information for *developers* to debug the status of | |
// the program | |
func (l *Log) Debug(message string) { | |
l.logger.Info().Msg(message) | |
} | |
// IOutputs runtime information for *users* to better diagnose what's going on | |
// with the underlying program state | |
func (l *Log) Info(message string) { | |
l.logger.Info().Msg(message) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment