Skip to content

Commit

Permalink
fix wrapping lines in log messages
Browse files Browse the repository at this point in the history
  • Loading branch information
kovetskiy committed Sep 21, 2020
1 parent b99fdc2 commit 0b10293
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 42 deletions.
4 changes: 1 addition & 3 deletions archive.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,9 @@ import (
"sync"
"syscall"

"github.com/reconquest/hierr-go"
"github.com/reconquest/lineflushwriter-go"
"github.com/reconquest/prefixwriter-go"
"github.com/reconquest/hierr-go"
)

func startArchiveReceivers(
Expand Down Expand Up @@ -162,7 +162,6 @@ func writeFileToArchive(
preserveUID, preserveGID bool,
) error {
fileInfo, err := os.Stat(fileName)

if err != nil {
return hierr.Errorf(
err,
Expand Down Expand Up @@ -281,7 +280,6 @@ func getFilesList(relative bool, sources ...string) ([]file, error) {
return nil
},
)

if err != nil {
return nil, err
}
Expand Down
47 changes: 8 additions & 39 deletions log.go
Original file line number Diff line number Diff line change
@@ -1,18 +1,12 @@
package main

import (
"bytes"
"fmt"
"os"
"strings"

"github.com/kovetskiy/lorg"
"github.com/reconquest/hierr-go"
"github.com/reconquest/loreley"
)

var (
loggerFormattingBasicLength = 0
)

func setLoggerOutputFormat(logger *lorg.Log, format outputFormat) {
Expand Down Expand Up @@ -41,28 +35,16 @@ func setLoggerVerbosity(level verbosity, logger *lorg.Log) {
}

func setLoggerStyle(logger *lorg.Log, style lorg.Formatter) {
testLogger := lorg.NewLog()

testLogger.SetFormat(style)

buffer := &bytes.Buffer{}
testLogger.SetOutput(buffer)

testLogger.Debug(``)

loggerFormattingBasicLength = len(strings.TrimSuffix(
loreley.TrimStyles(buffer.String()),
"\n",
))

logger.SetFormat(style)
logger.SetIndentLines(true)

logger.SetShiftIndent(28)
}

func tracef(format string, args ...interface{}) {
args = serializeErrors(args)

logger.Tracef(`%s`, wrapLines(format, args...))
logger.Tracef(format, args...)

drawStatus()
}
Expand All @@ -74,7 +56,7 @@ func traceln(args ...interface{}) {
func debugf(format string, args ...interface{}) {
args = serializeErrors(args)

logger.Debugf(`%s`, wrapLines(format, args...))
logger.Debugf(format, args...)

drawStatus()
}
Expand All @@ -86,7 +68,7 @@ func debugln(args ...interface{}) {
func infof(format string, args ...interface{}) {
args = serializeErrors(args)

logger.Infof(`%s`, wrapLines(format, args...))
logger.Infof(format, args...)

drawStatus()
}
Expand All @@ -102,7 +84,7 @@ func warningf(format string, args ...interface{}) {
return
}

logger.Warningf(`%s`, wrapLines(format, args...))
logger.Warningf(format, args...)

drawStatus()
}
Expand All @@ -114,7 +96,7 @@ func warningln(args ...interface{}) {
func errorf(format string, args ...interface{}) {
args = serializeErrors(args)

logger.Errorf(`%s`, wrapLines(format, args...))
logger.Errorf(format, args...)
}

func errorln(args ...interface{}) {
Expand All @@ -126,7 +108,7 @@ func fatalf(format string, args ...interface{}) {

clearStatus()

logger.Fatalf(`%s`, wrapLines(format, args...))
logger.Fatalf(format, args...)

exit(1)
}
Expand All @@ -135,19 +117,6 @@ func fatalln(args ...interface{}) {
fatalf("%s", fmt.Sprint(serializeErrors(args)...))
}

func wrapLines(format string, values ...interface{}) string {
contents := fmt.Sprintf(format, values...)
contents = strings.TrimSuffix(contents, "\n")
contents = strings.Replace(
contents,
"\n",
"\n"+strings.Repeat(" ", loggerFormattingBasicLength),
-1,
)

return contents
}

func serializeErrors(args []interface{}) []interface{} {
for i, arg := range args {
if err, ok := arg.(error); ok {
Expand Down

0 comments on commit 0b10293

Please sign in to comment.