Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Rename text logger #105

Merged
merged 1 commit into from
Oct 14, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion cmd/new.go
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ func init() {
"Build the changelog starting from the latest tag. Using this flag will result in a changelog with one entry.\nIt can be useful for generating a changelog to be used in release notes.",
)

newCmd.Flags().StringVar(&logger, "logger", "", "The type of logger to use. Valid values are 'spinner' and 'text'. The default is 'spinner'.")
newCmd.Flags().StringVar(&logger, "logger", "", "The type of logger to use. Valid values are 'spinner' and 'console'. The default is 'spinner'.")

newCmd.MarkFlagsMutuallyExclusive("from-version", "latest")
newCmd.Flags().SortFlags = false
Expand Down
33 changes: 33 additions & 0 deletions internal/logging/console.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
package logging

import (
"os"

"github.com/rs/zerolog"
"github.com/rs/zerolog/log"
)

type consoleLogger struct {
loggerType LoggerType
}

func newConsoleLogger() Logger {
log.Logger = log.Output(zerolog.ConsoleWriter{Out: os.Stderr})
return &consoleLogger{
loggerType: CONSOLE,
}
}

func (c *consoleLogger) Infof(format string, args ...interface{}) {
log.Info().Msgf(format, args...)
}

func (c *consoleLogger) Errorf(format string, args ...interface{}) {
log.Error().Msgf(format, args...)
}

func (c *consoleLogger) Complete() {}

func (c *consoleLogger) GetType() LoggerType {
return c.loggerType
}
14 changes: 7 additions & 7 deletions internal/logging/logger.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import (
type LoggerType int64

const (
TEXT LoggerType = iota
CONSOLE LoggerType = iota
SPINNER
)

Expand All @@ -28,8 +28,8 @@ type Logger interface {
// NewLogger returns a new logger based on the type passed in.
func NewLogger(loggerType LoggerType) Logger {
switch loggerType {
case TEXT:
return newTextLogger()
case CONSOLE:
return newConsoleLogger()
case SPINNER:
return newSpinnerLogger()
default:
Expand All @@ -46,18 +46,18 @@ func GetLoggerType(name string) (LoggerType, error) {
// If we're running in a CI environment then we don't want to
// use the spinner.
if environment.IsCI() {
name = "text"
name = "console"
}
}

var loggerType LoggerType
switch name {
case "text":
loggerType = TEXT
case "console":
loggerType = CONSOLE
case "spinner":
loggerType = SPINNER
default:
return loggerType, fmt.Errorf("'%s' is not a valid logger. Valid values are 'spinner' and 'text'", name)
return loggerType, fmt.Errorf("'%s' is not a valid logger. Valid values are 'spinner' and 'console'", name)
}

return loggerType, nil
Expand Down
12 changes: 6 additions & 6 deletions internal/logging/logger_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@ func TestNewLoggerReturnsTheCorrectType(t *testing.T) {
hasError bool
}{
{
name: "returns a text logger",
want: logging.TEXT,
name: "returns a console logger",
want: logging.CONSOLE,
hasError: false,
},
{
Expand All @@ -41,9 +41,9 @@ func TestGetLoggerTypeReturnsTheCorrectType(t *testing.T) {
hasError bool
}{
{
name: "returns a text logger",
input: "text",
want: logging.TEXT,
name: "returns a console logger",
input: "console",
want: logging.CONSOLE,
hasError: false,
},
{
Expand All @@ -65,7 +65,7 @@ func TestGetLoggerTypeReturnsTheCorrectType(t *testing.T) {
got, err := logging.GetLoggerType(tt.input)
if tt.hasError {
assert.Error(t, err)
assert.Equal(t, "'invalid' is not a valid logger. Valid values are 'spinner' and 'text'", err.Error())
assert.Equal(t, "'invalid' is not a valid logger. Valid values are 'spinner' and 'console'", err.Error())
} else {
assert.NoError(t, err)
assert.Equal(t, tt.want, got)
Expand Down
33 changes: 0 additions & 33 deletions internal/logging/text.go

This file was deleted.