Skip to content

Commit

Permalink
rename console logger builder + function (#43)
Browse files Browse the repository at this point in the history
  • Loading branch information
deankarn committed Jun 2, 2022
1 parent b53ceba commit e00e993
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 13 deletions.
2 changes: 1 addition & 1 deletion benchmarks/benchmark_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ var _jane = user{
// annoying because you have to manipulate the TestMain before
// running the benchmark you want.
func TestMain(m *testing.M) {
cLog := log.NewBuilder().WithGoSTDErrLogs(false).WithWriter(ioutil.Discard).Build()
cLog := log.NewConsoleBuilder().WithGoSTDErrLogs(false).WithWriter(ioutil.Discard).Build()
log.AddHandler(cLog, log.AllLevels...)
os.Exit(m.Run())
}
Expand Down
18 changes: 9 additions & 9 deletions default_logger.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,38 +18,38 @@ const (
v = "%v"
)

// Builder is used to create a new console logger
type Builder struct {
// ConsoleBuilder is used to create a new console logger
type ConsoleBuilder struct {
writer io.Writer
timestampFormat string
redirect bool
}

// NewBuilder creates a new Builder for configuring and creating a new console logger
func NewBuilder() *Builder {
return &Builder{
// NewConsoleBuilder creates a new ConsoleBuilder for configuring and creating a new console logger
func NewConsoleBuilder() *ConsoleBuilder {
return &ConsoleBuilder{
writer: os.Stderr,
timestampFormat: DefaultTimeFormat,
redirect: true,
}
}

func (b *Builder) WithGoSTDErrLogs(redirect bool) *Builder {
func (b *ConsoleBuilder) WithGoSTDErrLogs(redirect bool) *ConsoleBuilder {
b.redirect = redirect
return b
}

func (b *Builder) WithWriter(writer io.Writer) *Builder {
func (b *ConsoleBuilder) WithWriter(writer io.Writer) *ConsoleBuilder {
b.writer = writer
return b
}

func (b *Builder) WithTimestampFormat(format string) *Builder {
func (b *ConsoleBuilder) WithTimestampFormat(format string) *ConsoleBuilder {
b.timestampFormat = format
return b
}

func (b *Builder) Build() *Logger {
func (b *ConsoleBuilder) Build() *Logger {
c := &Logger{
writer: b.writer,
timestampFormat: b.timestampFormat,
Expand Down
4 changes: 2 additions & 2 deletions default_logger_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ func TestConsoleLogger(t *testing.T) {

SetExitFunc(func(int) {})

cLog := NewBuilder().WithWriter(buff).WithTimestampFormat("").Build()
cLog := NewConsoleBuilder().WithWriter(buff).WithTimestampFormat("").Build()
AddHandler(cLog, AllLevels...)
defer func() { _ = cLog.Close() }()
for i, tt := range tests {
Expand Down Expand Up @@ -90,7 +90,7 @@ func TestConsoleLogger(t *testing.T) {

func TestConsoleSTDLogCapturing(t *testing.T) {
buff := new(buffer)
cLog := NewBuilder().WithWriter(buff).WithTimestampFormat("MST").Build()
cLog := NewConsoleBuilder().WithWriter(buff).WithTimestampFormat("MST").Build()
AddHandler(cLog, AllLevels...)

stdlog.Println("STD LOG message")
Expand Down
2 changes: 1 addition & 1 deletion log.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ var (

func init() {
if term.IsTerminal(int(os.Stdin.Fd())) {
h := NewBuilder().Build()
h := NewConsoleBuilder().Build()
AddHandler(h, AllLevels...)
defaultHandler = h
}
Expand Down

0 comments on commit e00e993

Please sign in to comment.