Skip to content

Commit

Permalink
refactor: Move exported types into a separate file.
Browse files Browse the repository at this point in the history
  • Loading branch information
Tuxdude committed Feb 21, 2022
1 parent 9e42bd6 commit 61b4042
Show file tree
Hide file tree
Showing 3 changed files with 44 additions and 37 deletions.
19 changes: 0 additions & 19 deletions levels.go
Original file line number Diff line number Diff line change
@@ -1,21 +1,5 @@
package zzzlog

// Logging levels.
const (
// LvlFatal represents the Fatal log level.
LvlFatal Level = iota
// LvlError represents the Error log level.
LvlError
// LvlWarn represents the Warn log level.
LvlWarn
// LvlInfo represents the Info log level.
LvlInfo
// LvlDebug represents the Debug log level.
LvlDebug
// LvlTrace represents the Trace log level.
LvlTrace
)

var (
orderedLevels = []Level{
LvlFatal,
Expand All @@ -34,6 +18,3 @@ var (
LvlTrace: "TRACE",
}
)

// Level represents the logging level.
type Level uint8
18 changes: 0 additions & 18 deletions logger.go
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
// Package zzzlog provides a minimalistic level logging library based on
// the zzzlogi level logging interface.
package zzzlog

import (
Expand All @@ -15,14 +13,6 @@ const (
timestampFormat = "2006-01-02T15:04:05.000Z0700"
)

// Config contains the configuration for the logger.
type Config struct {
// Dest is the logging destination for the logs.
Dest io.Writer
// Level determines the maximum logging level.
MaxLevel Level
}

// loggerImpl is the implementation of the level logger based on
// zzzlogi.Logger interface.
type loggerImpl struct {
Expand All @@ -43,14 +33,6 @@ type configInternal struct {
levelColors levelColorMap
}

// NewLogger instantiates a Logger.
func NewLogger(userConfig *Config) zzzlogi.Logger {
c := defaultLoggingConfig()
c.dest = userConfig.Dest
c.maxLevel = userConfig.MaxLevel
return newLoggerForConfig(c)
}

// newLoggerForConfig builds a logger based on the specified config.
func newLoggerForConfig(config *configInternal) zzzlogi.Logger {
logger := &loggerImpl{
Expand Down
44 changes: 44 additions & 0 deletions zzzlog.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
// Package zzzlog provides a minimalistic level logging library based on
// the zzzlogi level logging interface.
package zzzlog

import (
"io"

"github.com/tuxdude/zzzlogi"
)

// Logging levels used by the zzzlog logger.
const (
// LvlFatal represents the Fatal log level.
LvlFatal Level = iota
// LvlError represents the Error log level.
LvlError
// LvlWarn represents the Warn log level.
LvlWarn
// LvlInfo represents the Info log level.
LvlInfo
// LvlDebug represents the Debug log level.
LvlDebug
// LvlTrace represents the Trace log level.
LvlTrace
)

// Level represents the logging level used by the zzzlog logger.
type Level uint8

// Config contains the configuration for the logger.
type Config struct {
// Dest is the logging destination for the logs.
Dest io.Writer
// Level determines the maximum logging level.
MaxLevel Level
}

// NewLogger instantiates a Logger.
func NewLogger(userConfig *Config) zzzlogi.Logger {
c := defaultLoggingConfig()
c.dest = userConfig.Dest
c.maxLevel = userConfig.MaxLevel
return newLoggerForConfig(c)
}

0 comments on commit 61b4042

Please sign in to comment.