Skip to content

Commit 2d6c558

Browse files
committed
avoid debug formating as possible
1 parent f91b836 commit 2d6c558

File tree

14 files changed

+415
-420
lines changed

14 files changed

+415
-420
lines changed

cmd/csv2table/csv2table.go

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ func main() {
5151
// Handle non-flag filename argument
5252
if flag.NArg() > 0 {
5353
*fileName = flag.Arg(0)
54-
logger.Info("Using filename from argument: %s", *fileName)
54+
logger.Infof("Using filename from argument: %s", *fileName)
5555
}
5656

5757
// Determine input source
@@ -62,7 +62,7 @@ func main() {
6262
logger.Info("Reading CSV from STDIN (pipe mode).")
6363
inputReader = os.Stdin
6464
} else if *fileName != "" {
65-
logger.Info("Reading CSV from file: %s", *fileName)
65+
logger.Infof("Reading CSV from file: %s", *fileName)
6666
file, errFile := os.Open(*fileName)
6767
if errFile != nil {
6868
logger.Fatal("failed to open file '%s': %w", *fileName, errFile)
@@ -158,7 +158,7 @@ func process(r io.Reader) error {
158158
case "none":
159159
selectedSymbols = tw.NewSymbols(tw.StyleNone)
160160
default:
161-
logger.Warn(fmt.Sprintf("Unknown symbol style '%s', using default (Light).", *symbolStyle))
161+
logger.Warnf("Unknown symbol style '%s', using default (Light).", *symbolStyle)
162162
selectedSymbols = tw.NewSymbols(tw.StyleLight)
163163
}
164164

@@ -226,7 +226,7 @@ func process(r io.Reader) error {
226226
fallthrough
227227
default:
228228
if *rendererType != "" && strings.ToLower(*rendererType) != "blueprint" {
229-
logger.Warn(fmt.Sprintf("Unknown renderer type '%s', using Blueprint.", *rendererType))
229+
logger.Warnf("Unknown renderer type '%s', using Blueprint.", *rendererType)
230230
}
231231
selectedRenderer = renderer.NewBlueprint(baseRendition)
232232
}
@@ -243,7 +243,7 @@ func process(r io.Reader) error {
243243
// If termSize fails or is 0, calculatedMaxWidth remains 0 (content-based width)
244244
}
245245
if calculatedMaxWidth > 0 {
246-
logger.Info(fmt.Sprintf("Calculated table max width: %d", calculatedMaxWidth))
246+
logger.Infof("Calculated table max width: %d", calculatedMaxWidth)
247247
}
248248

249249
tableOpts := []tablewriter.Option{
@@ -315,7 +315,7 @@ func process(r io.Reader) error {
315315
if maxCols == 0 && len(headerData) > 0 { // Only header was present
316316
maxCols = len(headerData)
317317
}
318-
logger.Info(fmt.Sprintf("Inferred max columns: %d", maxCols))
318+
logger.Infof("Inferred max columns: %d", maxCols)
319319

320320
// Normalize header
321321
if *header && len(headerData) > 0 {

config.go

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -671,7 +671,7 @@ func WithAutoHide(state tw.State) Option {
671671
return func(target *Table) {
672672
target.config.Behavior.AutoHide = state
673673
if target.logger != nil {
674-
target.logger.Debug("Option: WithAutoHide applied to Table: %v", state)
674+
target.logger.Debugf("Option: WithAutoHide applied to Table: %v", state)
675675
}
676676
}
677677
}
@@ -684,7 +684,7 @@ func WithBorders(borders tw.Border) Option {
684684
cfg := target.renderer.Config()
685685
cfg.Borders = borders
686686
if target.logger != nil {
687-
target.logger.Debug("Option: WithBorders applied to Table: %+v", borders)
687+
target.logger.Debugf("Option: WithBorders applied to Table: %+v", borders)
688688
}
689689
}
690690
}
@@ -699,7 +699,7 @@ func WithColumnMax(width int) Option {
699699
}
700700
target.config.Stream.Widths.Global = width
701701
if target.logger != nil {
702-
target.logger.Debug("Option: WithColumnMax applied to Table: %v", width)
702+
target.logger.Debugf("Option: WithColumnMax applied to Table: %v", width)
703703
}
704704
}
705705
}
@@ -713,7 +713,7 @@ func WithTableMax(width int) Option {
713713
}
714714
target.config.MaxWidth = width
715715
if target.logger != nil {
716-
target.logger.Debug("Option: WithTableMax applied to Table: %v", width)
716+
target.logger.Debugf("Option: WithTableMax applied to Table: %v", width)
717717
}
718718
}
719719
}
@@ -729,7 +729,7 @@ func WithColumnWidths(widths map[int]int) Option {
729729
}
730730
target.config.Stream.Widths.PerColumn = widths
731731
if target.logger != nil {
732-
target.logger.Debug("Option: WithColumnWidths applied to Table: %v", widths)
732+
target.logger.Debugf("Option: WithColumnWidths applied to Table: %v", widths)
733733
}
734734
}
735735
}
@@ -776,7 +776,7 @@ func WithFooterMergeMode(mergeMode int) Option {
776776
}
777777
target.config.Footer.Formatting.MergeMode = mergeMode
778778
if target.logger != nil {
779-
target.logger.Debug("Option: WithFooterMergeMode applied to Table: %v", mergeMode)
779+
target.logger.Debugf("Option: WithFooterMergeMode applied to Table: %v", mergeMode)
780780
}
781781
}
782782
}
@@ -797,7 +797,7 @@ func WithHeaderAlignment(align tw.Align) Option {
797797
}
798798
target.config.Header.Formatting.Alignment = align
799799
if target.logger != nil {
800-
target.logger.Debug("Option: WithHeaderAlignment applied to Table: %v", align)
800+
target.logger.Debugf("Option: WithHeaderAlignment applied to Table: %v", align)
801801
}
802802
}
803803
}
@@ -833,7 +833,7 @@ func WithRenderer(f tw.Renderer) Option {
833833
return func(target *Table) {
834834
target.renderer = f
835835
if target.logger != nil {
836-
target.logger.Debug("Option: WithRenderer applied to Table: %T", f)
836+
target.logger.Debugf("Option: WithRenderer applied to Table: %T", f)
837837
f.Logger(target.logger)
838838
}
839839
}
@@ -847,7 +847,7 @@ func WithRendererSettings(settings tw.Settings) Option {
847847
cfg := target.renderer.Config()
848848
cfg.Settings = settings
849849
if target.logger != nil {
850-
target.logger.Debug("Option: WithRendererSettings applied to Table: %+v", settings)
850+
target.logger.Debugf("Option: WithRendererSettings applied to Table: %+v", settings)
851851
}
852852
}
853853
}
@@ -873,7 +873,7 @@ func WithRowMaxWidth(maxWidth int) Option {
873873
}
874874
target.config.Row.ColMaxWidths.Global = maxWidth
875875
if target.logger != nil {
876-
target.logger.Debug("Option: WithRowMaxWidth applied to Table: %v", maxWidth)
876+
target.logger.Debugf("Option: WithRowMaxWidth applied to Table: %v", maxWidth)
877877
}
878878
}
879879
}
@@ -928,7 +928,7 @@ func WithTrimSpace(state tw.State) Option {
928928
return func(target *Table) {
929929
target.config.Behavior.TrimSpace = state
930930
if target.logger != nil {
931-
target.logger.Debug("Option: WithAutoHide applied to Table: %v", state)
931+
target.logger.Debugf("Option: WithAutoHide applied to Table: %v", state)
932932
}
933933
}
934934
}
@@ -954,9 +954,9 @@ func WithRendition(rendition tw.Rendition) Option {
954954

955955
if ru, ok := target.renderer.(tw.Renditioning); ok {
956956
ru.Rendition(rendition)
957-
target.logger.Debug("Option: WithRendition: Applied to renderer via Renditioning.SetRendition(): %+v", rendition)
957+
target.logger.Debugf("Option: WithRendition: Applied to renderer via Renditioning.SetRendition(): %+v", rendition)
958958
} else {
959-
target.logger.Warn("Option: WithRendition: Current renderer type %T does not implement tw.Renditioning. Rendition may not be applied as expected.", target.renderer)
959+
target.logger.Warnf("Option: WithRendition: Current renderer type %T does not implement tw.Renditioning. Rendition may not be applied as expected.", target.renderer)
960960
}
961961
}
962962
}

csv.go

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ func NewCSVReader(writer io.Writer, csvReader *csv.Reader, hasHeader bool, opts
4444
return t, nil
4545
}
4646
// Log other read errors
47-
t.logger.Error("NewCSVReader: Error reading CSV header: %v", err)
47+
t.logger.Errorf("NewCSVReader: Error reading CSV header: %v", err)
4848
return nil, err // Return nil *Table on critical read error
4949
}
5050

@@ -59,7 +59,7 @@ func NewCSVReader(writer io.Writer, csvReader *csv.Reader, hasHeader bool, opts
5959

6060
if !isEmptyHeader {
6161
t.Header(headers) // Use the Table method to set the header data
62-
t.logger.Debug("NewCSVReader: Header set from CSV: %v", headers)
62+
t.logger.Debugf("NewCSVReader: Header set from CSV: %v", headers)
6363
} else {
6464
t.logger.Debug("NewCSVReader: Read an empty header line, skipping setting table header.")
6565
}
@@ -74,20 +74,20 @@ func NewCSVReader(writer io.Writer, csvReader *csv.Reader, hasHeader bool, opts
7474
}
7575
if err != nil {
7676
// Log other read errors during data processing
77-
t.logger.Error("NewCSVReader: Error reading CSV record: %v", err)
77+
t.logger.Errorf("NewCSVReader: Error reading CSV record: %v", err)
7878
return nil, err // Return nil *Table on critical read error
7979
}
8080

8181
// Append the record to the table's internal buffer (for batch rendering).
8282
// The Table.Append method handles conversion and storage.
8383
if appendErr := t.Append(record); appendErr != nil {
84-
t.logger.Error("NewCSVReader: Error appending record #%d: %v", rowCount+1, appendErr)
84+
t.logger.Errorf("NewCSVReader: Error appending record #%d: %v", rowCount+1, appendErr)
8585
// Decide if append error is fatal. For now, let's treat it as fatal.
8686
return nil, appendErr
8787
}
8888
rowCount++
8989
}
90-
t.logger.Debug("NewCSVReader: Finished reading CSV. Appended %d data rows.", rowCount)
90+
t.logger.Debugf("NewCSVReader: Finished reading CSV. Appended %d data rows.", rowCount)
9191

9292
// Return the configured and populated table instance, ready for Render() call.
9393
return t, nil

go.mod

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ require (
1111
require (
1212
github.com/mattn/go-colorable v0.1.13 // indirect
1313
github.com/mattn/go-isatty v0.0.19 // indirect
14-
github.com/olekukonko/ll v0.0.6-0.20250513034024-62c5c2714b38 // indirect
14+
github.com/olekukonko/ll v0.0.7 // indirect
1515
github.com/olekukonko/ts v0.0.0-20171002115256-78ecb04241c0 // indirect
1616
github.com/rivo/uniseg v0.2.0 // indirect
1717
golang.org/x/sys v0.12.0 // indirect

go.sum

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,8 @@ github.com/olekukonko/ll v0.0.6-0.20250513001635-5dbed4661872 h1:44lc4ASGSoHddTt
3333
github.com/olekukonko/ll v0.0.6-0.20250513001635-5dbed4661872/go.mod h1:En+sEW0JNETl26+K8eZ6/W4UQ7CYSrrgg/EdIYT2H8g=
3434
github.com/olekukonko/ll v0.0.6-0.20250513034024-62c5c2714b38 h1:Lnuzuijce7bnRJnlns11a2mUTW9lMF5kUW+ZriZh/hI=
3535
github.com/olekukonko/ll v0.0.6-0.20250513034024-62c5c2714b38/go.mod h1:En+sEW0JNETl26+K8eZ6/W4UQ7CYSrrgg/EdIYT2H8g=
36+
github.com/olekukonko/ll v0.0.7 h1:K66xcUlG2qWRhPoLw/cidmbv4pDDJtZuvJGsR5QTzXo=
37+
github.com/olekukonko/ll v0.0.7/go.mod h1:En+sEW0JNETl26+K8eZ6/W4UQ7CYSrrgg/EdIYT2H8g=
3638
github.com/olekukonko/ts v0.0.0-20171002115256-78ecb04241c0 h1:LiZB1h0GIcudcDci2bxbqI6DXV8bF8POAnArqvRrIyw=
3739
github.com/olekukonko/ts v0.0.0-20171002115256-78ecb04241c0/go.mod h1:F/7q8/HZz+TXjlsoZQQKVYvXTZaFH4QRa3y+j1p7MS0=
3840
github.com/rivo/uniseg v0.2.0 h1:S1pD9weZBuJdFmowNwbpi7BJ8TNftyUImj/0WQi72jY=

0 commit comments

Comments
 (0)