From 5db4dea248074f51bcd7c10c2e6504aff8ee7b6c Mon Sep 17 00:00:00 2001 From: sayan Date: Thu, 2 Oct 2025 10:53:44 +0530 Subject: [PATCH 1/5] added include-timestamp functionality --- internal/app/app.go | 4 ++++ main.go | 37 ++++++++++++++++++++----------------- parse/process.go | 7 ++++++- parse/process_options.go | 6 ++++++ 4 files changed, 36 insertions(+), 18 deletions(-) diff --git a/internal/app/app.go b/internal/app/app.go index 93f7f82..f9f9ecc 100644 --- a/internal/app/app.go +++ b/internal/app/app.go @@ -48,6 +48,9 @@ type Options struct { // Compare includes a diff of a previous test output file in the summary table. Compare string + + //used with FollowOutput, when enabled it would include timestamp with log lines + IncludeTimestamp bool } func Run(option Options) (int, error) { @@ -75,6 +78,7 @@ func Run(option Options) (int, error) { parse.WithWriter(option.FollowOutputWriter), parse.WithProgress(option.Progress), parse.WithProgressOutput(option.ProgressOutput), + parse.WithIncludeTimestamp(option.IncludeTimestamp), ) if err != nil { return 1, err diff --git a/main.go b/main.go index d9fe66a..5579e6a 100644 --- a/main.go +++ b/main.go @@ -37,6 +37,7 @@ var ( trimPathPtr = flag.String("trimpath", "", "") // Undocumented flags followVerbosePtr = flag.Bool("follow-verbose", false, "") + includeTimestamp = flag.Bool("include-timestamp", false, "include timestamps in follow output") // Legacy flags noBordersPtr = flag.Bool("noborders", false, "") @@ -48,23 +49,24 @@ var usage = `Usage: go test [packages...] -json > pkgs.out ; tparse [options...] -file pkgs.out Options: - -h Show help. - -v Show version. - -all Display table event for pass and skip. (Failed items always displayed) - -pass Display table for passed tests. - -skip Display table for skipped tests. - -notests Display packages containing no test files or empty test files. - -smallscreen Split subtest names vertically to fit on smaller screens. - -slow Number of slowest tests to display. Default is 0, display all. - -sort Sort table output by attribute [name, elapsed, cover]. Default is name. - -nocolor Disable all colors. (NO_COLOR also supported) - -format The output format for tables [basic, plain, markdown]. Default is basic. - -file Read test output from a file. - -follow Follow raw output from go test to stdout. - -follow-output Write raw output from go test to a file (takes precedence over -follow). - -progress Print a single summary line for each package. Useful for long running test suites. - -compare Compare against a previous test output file. (experimental) - -trimpath Remove path prefix from package names in output, simplifying their display. + -h Show help. + -v Show version. + -all Display table event for pass and skip. (Failed items always displayed) + -pass Display table for passed tests. + -skip Display table for skipped tests. + -notests Display packages containing no test files or empty test files. + -smallscreen Split subtest names vertically to fit on smaller screens. + -slow Number of slowest tests to display. Default is 0, display all. + -sort Sort table output by attribute [name, elapsed, cover]. Default is name. + -nocolor Disable all colors. (NO_COLOR also supported) + -format The output format for tables [basic, plain, markdown]. Default is basic. + -file Read test output from a file. + -follow Follow raw output from go test to stdout. + -follow-output Write raw output from go test to a file (takes precedence over -follow). + -include-timestamp Include timestamps in follow output. + -progress Print a single summary line for each package. Useful for long running test suites. + -compare Compare against a previous test output file. (experimental) + -trimpath Remove path prefix from package names in output, simplifying their display. ` var version string @@ -169,6 +171,7 @@ func main() { Progress: *progressPtr, ProgressOutput: os.Stdout, Compare: *comparePtr, + IncludeTimestamp: *includeTimestamp, // Do not expose publicly. DisableTableOutput: false, diff --git a/parse/process.go b/parse/process.go index 8c28e99..556565b 100644 --- a/parse/process.go +++ b/parse/process.go @@ -104,7 +104,12 @@ func Process(r io.Reader, optionsFunc ...OptionsFunc) (*GoTestSummary, error) { if !option.followVerbose && isNoisy(e) { continue } - fmt.Fprint(option.w, e.Output) + if e.Output!="" && option.includeTimestamp { + fmt.Fprint(option.w,e.Time.Format("2006-01-02T15:04:05.000000-07:00")+" "+e.Output) + }else{ + fmt.Fprint(option.w,e.Output) + } + } // Progress is a special case of follow, where we only print the // progress of the test suite, but not the output. diff --git a/parse/process_options.go b/parse/process_options.go index 8a63b5c..3a224df 100644 --- a/parse/process_options.go +++ b/parse/process_options.go @@ -12,6 +12,8 @@ type options struct { progress bool progressOutput io.Writer + + includeTimestamp bool } type OptionsFunc func(o *options) @@ -39,3 +41,7 @@ func WithProgress(b bool) OptionsFunc { func WithProgressOutput(w io.Writer) OptionsFunc { return func(o *options) { o.progressOutput = w } } + +func WithIncludeTimestamp(b bool)OptionsFunc{ + return func(o *options){ o.includeTimestamp=b} +} \ No newline at end of file From 04032d461201f8f1f0cc64506e163fd19d2c4708 Mon Sep 17 00:00:00 2001 From: sayan Date: Thu, 2 Oct 2025 10:56:13 +0530 Subject: [PATCH 2/5] fixed formatting of WithIncludeTimestamp function --- parse/process_options.go | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/parse/process_options.go b/parse/process_options.go index 3a224df..5c1efab 100644 --- a/parse/process_options.go +++ b/parse/process_options.go @@ -42,6 +42,6 @@ func WithProgressOutput(w io.Writer) OptionsFunc { return func(o *options) { o.progressOutput = w } } -func WithIncludeTimestamp(b bool)OptionsFunc{ - return func(o *options){ o.includeTimestamp=b} -} \ No newline at end of file +func WithIncludeTimestamp(b bool) OptionsFunc { + return func(o *options) { o.includeTimestamp = b } +} From 134271f8b983e37de0b8fce18eeea09fd7d62cf1 Mon Sep 17 00:00:00 2001 From: sayan Date: Thu, 2 Oct 2025 17:55:29 +0530 Subject: [PATCH 3/5] fixed code formatting issue --- internal/app/app.go | 4 ++-- main.go | 12 ++++++------ parse/process.go | 10 +++++----- 3 files changed, 13 insertions(+), 13 deletions(-) diff --git a/internal/app/app.go b/internal/app/app.go index f9f9ecc..9b41135 100644 --- a/internal/app/app.go +++ b/internal/app/app.go @@ -49,8 +49,8 @@ type Options struct { // Compare includes a diff of a previous test output file in the summary table. Compare string - //used with FollowOutput, when enabled it would include timestamp with log lines - IncludeTimestamp bool + // Used with FollowOutput, when enabled it would include timestamp with log lines + IncludeTimestamp bool } func Run(option Options) (int, error) { diff --git a/main.go b/main.go index 5579e6a..fc3aad4 100644 --- a/main.go +++ b/main.go @@ -165,12 +165,12 @@ func main() { Trim: *smallScreenPtr, TrimPath: *trimPathPtr, }, - Format: format, - Sorter: sorter, - ShowNoTests: *showNoTestsPtr, - Progress: *progressPtr, - ProgressOutput: os.Stdout, - Compare: *comparePtr, + Format: format, + Sorter: sorter, + ShowNoTests: *showNoTestsPtr, + Progress: *progressPtr, + ProgressOutput: os.Stdout, + Compare: *comparePtr, IncludeTimestamp: *includeTimestamp, // Do not expose publicly. diff --git a/parse/process.go b/parse/process.go index 556565b..12195f0 100644 --- a/parse/process.go +++ b/parse/process.go @@ -104,12 +104,12 @@ func Process(r io.Reader, optionsFunc ...OptionsFunc) (*GoTestSummary, error) { if !option.followVerbose && isNoisy(e) { continue } - if e.Output!="" && option.includeTimestamp { - fmt.Fprint(option.w,e.Time.Format("2006-01-02T15:04:05.000000-07:00")+" "+e.Output) - }else{ - fmt.Fprint(option.w,e.Output) + if e.Output != "" && option.includeTimestamp { + fmt.Fprint(option.w, e.Time.Format("2006-01-02T15:04:05.000000-07:00")+" "+e.Output) + } else { + fmt.Fprint(option.w, e.Output) } - + } // Progress is a special case of follow, where we only print the // progress of the test suite, but not the output. From 38a0c15d2c9ec3efaa503bc92c950bf5ce611164 Mon Sep 17 00:00:00 2001 From: sayan Date: Sat, 15 Nov 2025 21:45:42 +0530 Subject: [PATCH 4/5] changed custom time format to a time package format --- parse/process.go | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/parse/process.go b/parse/process.go index 12195f0..13ad11c 100644 --- a/parse/process.go +++ b/parse/process.go @@ -10,6 +10,7 @@ import ( "sort" "strconv" "strings" + "time" ) // ErrNotParsable indicates the event line was not parsable. @@ -105,7 +106,7 @@ func Process(r io.Reader, optionsFunc ...OptionsFunc) (*GoTestSummary, error) { continue } if e.Output != "" && option.includeTimestamp { - fmt.Fprint(option.w, e.Time.Format("2006-01-02T15:04:05.000000-07:00")+" "+e.Output) + fmt.Fprint(option.w, e.Time.Format(time.RFC3339Nano)+" "+e.Output) } else { fmt.Fprint(option.w, e.Output) } From 6fec3508b9e91df84069a3763cef9a96f752458a Mon Sep 17 00:00:00 2001 From: Sayan-995 <145650382+Sayan-995@users.noreply.github.com> Date: Sun, 16 Nov 2025 02:41:28 +0530 Subject: [PATCH 5/5] Change timestamp format to RFC3339 --- parse/process.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/parse/process.go b/parse/process.go index 5915f06..baeaabb 100644 --- a/parse/process.go +++ b/parse/process.go @@ -106,7 +106,7 @@ func Process(r io.Reader, optionsFunc ...OptionsFunc) (*GoTestSummary, error) { continue } if e.Output != "" && option.includeTimestamp { - fmt.Fprint(option.w, e.Time.Format(time.RFC3339Nano)+" "+e.Output) + fmt.Fprint(option.w, e.Time.Format(time.RFC3339)+" "+e.Output) } else { fmt.Fprint(option.w, e.Output) }