88 "sync"
99 "time"
1010
11+ "github.com/githubnext/gh-aw/pkg/timeutil"
1112 "github.com/mattn/go-isatty"
1213)
1314
@@ -106,9 +107,9 @@ func (l *Logger) Printf(format string, args ...interface{}) {
106107
107108 message := fmt .Sprintf (format , args ... )
108109 if l .color != "" {
109- fmt .Fprintf (os .Stderr , "%s%s%s %s +%s\n " , l .color , l .namespace , colorReset , message , formatDuration (diff ))
110+ fmt .Fprintf (os .Stderr , "%s%s%s %s +%s\n " , l .color , l .namespace , colorReset , message , timeutil . FormatDuration (diff ))
110111 } else {
111- fmt .Fprintf (os .Stderr , "%s %s +%s\n " , l .namespace , message , formatDuration (diff ))
112+ fmt .Fprintf (os .Stderr , "%s %s +%s\n " , l .namespace , message , timeutil . FormatDuration (diff ))
112113 }
113114}
114115
@@ -127,32 +128,12 @@ func (l *Logger) Print(args ...interface{}) {
127128
128129 message := fmt .Sprint (args ... )
129130 if l .color != "" {
130- fmt .Fprintf (os .Stderr , "%s%s%s %s +%s\n " , l .color , l .namespace , colorReset , message , formatDuration (diff ))
131+ fmt .Fprintf (os .Stderr , "%s%s%s %s +%s\n " , l .color , l .namespace , colorReset , message , timeutil . FormatDuration (diff ))
131132 } else {
132- fmt .Fprintf (os .Stderr , "%s %s +%s\n " , l .namespace , message , formatDuration (diff ))
133+ fmt .Fprintf (os .Stderr , "%s %s +%s\n " , l .namespace , message , timeutil . FormatDuration (diff ))
133134 }
134135}
135136
136- // formatDuration formats a duration for display like the debug npm package
137- func formatDuration (d time.Duration ) string {
138- if d < time .Microsecond {
139- return fmt .Sprintf ("%dns" , d .Nanoseconds ())
140- }
141- if d < time .Millisecond {
142- return fmt .Sprintf ("%dµs" , d .Microseconds ())
143- }
144- if d < time .Second {
145- return fmt .Sprintf ("%dms" , d .Milliseconds ())
146- }
147- if d < time .Minute {
148- return fmt .Sprintf ("%.1fs" , d .Seconds ())
149- }
150- if d < time .Hour {
151- return fmt .Sprintf ("%.1fm" , d .Minutes ())
152- }
153- return fmt .Sprintf ("%.1fh" , d .Hours ())
154- }
155-
156137// computeEnabled computes whether a namespace matches the DEBUG patterns
157138func computeEnabled (namespace string ) bool {
158139 patterns := strings .Split (debugEnv , "," )
0 commit comments