Skip to content

Commit

Permalink
Merge pull request #1 from saucelabs/v1.5.8
Browse files Browse the repository at this point in the history
v1.5.8
  • Loading branch information
thalesfsp committed Nov 8, 2021
2 parents e4ecc72 + ba513f9 commit 62f2adc
Show file tree
Hide file tree
Showing 8 changed files with 92 additions and 40 deletions.
6 changes: 6 additions & 0 deletions CHANGELOG.md
Expand Up @@ -25,6 +25,12 @@ Refs. for badges:
- http://github.com/wayneashleyberry/terminal-dimensions
- https://github.com/golangci/golangci-lint

## [1.5.8] - 2021-11-08
### Changed
- All `SetXYZ` methods returns its proper interface allowing method chaining.
- `Breakpoint` is now variadic.
- Properly handle cases where sypl writes to a piped output, but it's broken.

## [1.5.7] - 2021-11-02
### Changed
- Fixed `ExampleNew_globalFields` test.
Expand Down
6 changes: 3 additions & 3 deletions interface.go
Expand Up @@ -209,7 +209,7 @@ type ISypl interface {
// the `debug` level. Arbitrary `data` can optionally be set - if set, it'll
// be printed. Errors are printed using the `error` level. Set logging level
// to `trace` for more.
Breakpoint(name string, data interface{}) ISypl
Breakpoint(name string, data ...interface{}) ISypl

// String interface.
String() string
Expand All @@ -225,7 +225,7 @@ type ISypl interface {
GetMaxLevel() map[string]level.Level

// SetMaxLevel sets the `maxLevel` of all outputs.
SetMaxLevel(l level.Level)
SetMaxLevel(l level.Level) ISypl

// AddOutputs adds one or more outputs.
AddOutputs(outputs ...output.IOutput) ISypl
Expand All @@ -234,7 +234,7 @@ type ISypl interface {
GetOutput(name string) output.IOutput

// SetOutputs sets one or more outputs. Use to update output(s).
SetOutputs(outputs ...output.IOutput)
SetOutputs(outputs ...output.IOutput) ISypl

// GetOutputs returns registered outputs.
GetOutputs() []output.IOutput
Expand Down
22 changes: 11 additions & 11 deletions message/interface.go
Expand Up @@ -36,13 +36,13 @@ type IMessage interface {
GetComponentName() string

// SetComponentName sets the component name.
SetComponentName(name string)
SetComponentName(name string) IMessage

// GetContent returns the content.
GetContent() content.IContent

// SetContent sets the content.
SetContent(c content.IContent)
SetContent(c content.IContent) IMessage

// GetDebugEnvVarRegexeses returns the Debug env var regexes matchers.
GetDebugEnvVarRegexes() *debug.Debug
Expand All @@ -54,13 +54,13 @@ type IMessage interface {
GetFields() fields.Fields

// SetFields sets the structured fields.
SetFields(fields fields.Fields)
SetFields(fields fields.Fields) IMessage

// GetFlag returns the flag.
GetFlag() flag.Flag

// SetFlag sets the flag.
SetFlag(flag flag.Flag)
SetFlag(flag flag.Flag) IMessage

// GetID returns the id.
GetID() string
Expand All @@ -72,13 +72,13 @@ type IMessage interface {
GetLevel() level.Level

// SetLevel sets the level.
SetLevel(l level.Level)
SetLevel(l level.Level) IMessage

// getLineBreaker returns linebreaker.
getLineBreaker() *lineBreaker

// setLineBreaker sets the linebreaker.
setLineBreaker(lB *lineBreaker)
setLineBreaker(lB *lineBreaker) IMessage

// GetMessage (low-level) returns the message.
GetMessage() *message
Expand All @@ -87,31 +87,31 @@ type IMessage interface {
GetOutputName() string

// SetOutputName sets the name of the output in use.
SetOutputName(outputName string)
SetOutputName(outputName string) IMessage

// GetOutputsNames returns the outputs names that should be used.
GetOutputsNames() []string

// SetOutputsNames sets the outputs names that should be used.
SetOutputsNames(outputsNames []string)
SetOutputsNames(outputsNames []string) IMessage

// GetProcessorName returns the name of the processor in use.
GetProcessorName() string

// SetProcessorName sets the name of the processor in use.
SetProcessorName(processorName string)
SetProcessorName(processorName string) IMessage

// GetProcessorsNames returns the processors names that should be used.
GetProcessorsNames() []string

// SetProcessorsNames sets the processors names that should be used.
SetProcessorsNames(processorsNames []string)
SetProcessorsNames(processorsNames []string) IMessage

// GetTimestamp returns the timestamp.
GetTimestamp() time.Time

// SetTimestamp sets the timestamp.
SetTimestamp(timestamp time.Time)
SetTimestamp(timestamp time.Time) IMessage
}

// ITag specifies what a Tag does.
Expand Down
44 changes: 33 additions & 11 deletions message/message.go
Expand Up @@ -130,8 +130,10 @@ func (m *message) getLineBreaker() *lineBreaker {
}

// setLineBreaker sets the line break status.
func (m *message) setLineBreaker(lB *lineBreaker) {
func (m *message) setLineBreaker(lB *lineBreaker) IMessage {
m.lineBreaker = lB

return m
}

// Restore known linebreaks.
Expand Down Expand Up @@ -171,8 +173,10 @@ func (m *message) GetComponentName() string {
}

// SetComponentName sets the component name.
func (m *message) SetComponentName(name string) {
func (m *message) SetComponentName(name string) IMessage {
m.componentName = name

return m
}

// GetContent returns the content.
Expand All @@ -181,8 +185,10 @@ func (m *message) GetContent() content.IContent {
}

// SetContent sets the content.
func (m *message) SetContent(c content.IContent) {
func (m *message) SetContent(c content.IContent) IMessage {
m.Content = c

return m
}

// GetDebugEnvVarRegexeses returns the Debug env var regexes matchers.
Expand All @@ -203,8 +209,10 @@ func (m *message) GetFields() fields.Fields {
}

// SetFields sets the structured fields.
func (m *message) SetFields(fields fields.Fields) {
func (m *message) SetFields(fields fields.Fields) IMessage {
m.Fields = fields

return m
}

// GetFlag returns the flag.
Expand All @@ -213,8 +221,10 @@ func (m *message) GetFlag() flag.Flag {
}

// SetFlag sets the flag.
func (m *message) SetFlag(flag flag.Flag) {
func (m *message) SetFlag(flag flag.Flag) IMessage {
m.Flag = flag

return m
}

// GetID returns the id.
Expand All @@ -233,8 +243,10 @@ func (m *message) GetLevel() level.Level {
}

// SetLevel sets the level.
func (m *message) SetLevel(l level.Level) {
func (m *message) SetLevel(l level.Level) IMessage {
m.Level = l

return m
}

// GetMessage (low-level) returns the message.
Expand All @@ -248,8 +260,10 @@ func (m *message) GetOutputName() string {
}

// SetOutputName sets the name of the output in use.
func (m *message) SetOutputName(outputName string) {
func (m *message) SetOutputName(outputName string) IMessage {
m.OutputName = outputName

return m
}

// GetOutputsNames returns the outputs names that should be used.
Expand All @@ -258,8 +272,10 @@ func (m *message) GetOutputsNames() []string {
}

// SetOutputsNames sets the outputs names that should be used.
func (m *message) SetOutputsNames(outputsNames []string) {
func (m *message) SetOutputsNames(outputsNames []string) IMessage {
m.OutputsNames = outputsNames

return m
}

// GetProcessorName returns the name of the processor in use.
Expand All @@ -268,8 +284,10 @@ func (m *message) GetProcessorName() string {
}

// SetProcessorName sets the name of the processor in use.
func (m *message) SetProcessorName(processorName string) {
func (m *message) SetProcessorName(processorName string) IMessage {
m.ProcessorName = processorName

return m
}

// GetProcessorsNames returns the processors names that should be used.
Expand All @@ -278,8 +296,10 @@ func (m *message) GetProcessorsNames() []string {
}

// SetProcessorsNames sets the processors names that should be used.
func (m *message) SetProcessorsNames(processorsNames []string) {
func (m *message) SetProcessorsNames(processorsNames []string) IMessage {
m.ProcessorsNames = processorsNames

return m
}

// GetTimestamp returns the timestamp.
Expand All @@ -288,8 +308,10 @@ func (m *message) GetTimestamp() time.Time {
}

// SetTimestamp sets the timestamp.
func (m *message) SetTimestamp(timestamp time.Time) {
func (m *message) SetTimestamp(timestamp time.Time) IMessage {
m.Timestamp = timestamp

return m
}

//////
Expand Down
1 change: 0 additions & 1 deletion output/builtin.go
Expand Up @@ -47,7 +47,6 @@ func StdErr(processors ...processor.IProcessor) IOutput {
}

// FileBased is a built-in `output`, that writes to the specified file.
// TODO: Remove `path`.
func FileBased(
name string,
maxLevel level.Level,
Expand Down
9 changes: 4 additions & 5 deletions output/interface.go
Expand Up @@ -26,8 +26,7 @@ type IOutput interface {
GetBuiltinLogger() *builtin.Builtin

// SetBuiltinLogger sets the Golang's builtin logger.
// TODO: SetXYZ should return IOutput.
SetBuiltinLogger(builtinLogger *builtin.Builtin)
SetBuiltinLogger(builtinLogger *builtin.Builtin) IOutput

// GetFormatter returns the formatter.
GetFormatter() formatter.IFormatter
Expand All @@ -39,7 +38,7 @@ type IOutput interface {
GetMaxLevel() level.Level

// SetMaxLevel sets the max level.
SetMaxLevel(l level.Level)
SetMaxLevel(l level.Level) IOutput

// AddProcessors adds one or more processors.
AddProcessors(processors ...processor.IProcessor) IOutput
Expand All @@ -48,7 +47,7 @@ type IOutput interface {
GetProcessor(name string) processor.IProcessor

// SetProcessors sets one or more processors.
SetProcessors(processors ...processor.IProcessor)
SetProcessors(processors ...processor.IProcessor) IOutput

// GetProcessors returns registered processors.
GetProcessors() []processor.IProcessor
Expand All @@ -60,7 +59,7 @@ type IOutput interface {
GetWriter() io.Writer

// SetWriter sets the writer.
SetWriter(w io.Writer)
SetWriter(w io.Writer) IOutput

// Write write the message to the defined output.
Write(m message.IMessage) error
Expand Down
24 changes: 20 additions & 4 deletions output/output.go
Expand Up @@ -5,11 +5,13 @@
package output

import (
"errors"
"fmt"
"io"
"log"
"os"
"strings"
"syscall"

"github.com/saucelabs/sypl/flag"
"github.com/saucelabs/sypl/formatter"
Expand Down Expand Up @@ -89,8 +91,10 @@ func (o *output) GetBuiltinLogger() *builtin.Builtin {
}

// SetBuiltinLogger sets the Golang's builtin logger.
func (o *output) SetBuiltinLogger(builtinLogger *builtin.Builtin) {
func (o *output) SetBuiltinLogger(builtinLogger *builtin.Builtin) IOutput {
o.builtinLogger = builtinLogger

return o
}

// GetFormatter returns the formatter.
Expand All @@ -111,8 +115,10 @@ func (o *output) GetMaxLevel() level.Level {
}

// SetMaxLevel sets the max level.
func (o *output) SetMaxLevel(l level.Level) {
func (o *output) SetMaxLevel(l level.Level) IOutput {
o.maxLevel = l

return o
}

// AddProcessors adds one or more processors.
Expand Down Expand Up @@ -140,14 +146,16 @@ func (o *output) GetProcessors() []processor.IProcessor {
}

// GetProcessors returns registered processors.
func (o *output) SetProcessors(processors ...processor.IProcessor) {
func (o *output) SetProcessors(processors ...processor.IProcessor) IOutput {
for _, processor := range processors {
for i, p := range o.processors {
if strings.EqualFold(p.GetName(), processor.GetName()) {
o.processors[i] = processor
}
}
}

return o
}

// GetProcessorsNames returns the names of the registered processors.
Expand All @@ -167,8 +175,10 @@ func (o *output) GetWriter() io.Writer {
}

// SetWriter sets the writer.
func (o *output) SetWriter(w io.Writer) {
func (o *output) SetWriter(w io.Writer) IOutput {
o.writer = w

return o
}

// Write the message to the defined output. In case of any error, it can be
Expand Down Expand Up @@ -275,6 +285,12 @@ func (o *output) write(m message.IMessage) error {
builtin.DefaultCallDepth,
m.GetContent().GetProcessed(),
); err != nil {
// It means application using Sypl was piped, but the pipe was broken so
// nothing to do.
if errors.Is(err, syscall.EPIPE) {
return nil
}

return fmt.Errorf(`"%s" output. Error: "%w"`, o.GetName(), err)
}

Expand Down

0 comments on commit 62f2adc

Please sign in to comment.