-
-
Notifications
You must be signed in to change notification settings - Fork 249
/
formatters.go
690 lines (586 loc) · 20.6 KB
/
formatters.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
package processor
import (
"bytes"
"encoding/csv"
"encoding/json"
"fmt"
glang "golang.org/x/text/language"
gmessage "golang.org/x/text/message"
"gopkg.in/yaml.v2"
"os"
"sort"
"strings"
"time"
)
var tabularShortBreak = "───────────────────────────────────────────────────────────────────────────────\n"
var tabularShortBreakCi = "-------------------------------------------------------------------------------\n"
var tabularShortFormatHead = "%-20s %9s %9s %8s %9s %8s %10s\n"
var tabularShortFormatBody = "%-20s %9d %9d %8d %9d %8d %10d\n"
var tabularShortFormatFile = "%-30s %9d %8d %9d %8d %10d\n"
var shortFormatFileTrucate = 29
var shortNameTruncate = 20
var tabularShortFormatHeadNoComplexity = "%-22s %11s %11s %9s %11s %10s\n"
var tabularShortFormatBodyNoComplexity = "%-22s %11d %11d %9d %11d %10d\n"
var tabularShortFormatFileNoComplexity = "%-34s %11d %9d %11d %10d\n"
var shortFormatFileTrucateNoComplexity = 33
var longNameTruncate = 22
var tabularWideBreak = "─────────────────────────────────────────────────────────────────────────────────────────────────────────────\n"
var tabularWideBreakCi = "-------------------------------------------------------------------------------------------------------------\n"
var tabularWideFormatHead = "%-33s %9s %9s %8s %9s %8s %10s %16s\n"
var tabularWideFormatBody = "%-33s %9d %9d %8d %9d %8d %10d %16.2f\n"
var tabularWideFormatFile = "%-43s %9d %8d %9d %8d %10d %16.2f\n"
var wideFormatFileTrucate = 42
func sortSummaryFiles(summary *LanguageSummary) {
switch {
case SortBy == "name" || SortBy == "names" || SortBy == "language" || SortBy == "languages":
sort.Slice(summary.Files, func(i, j int) bool {
return summary.Files[i].Lines > summary.Files[j].Lines
})
case SortBy == "line" || SortBy == "lines":
sort.Slice(summary.Files, func(i, j int) bool {
return summary.Files[i].Lines > summary.Files[j].Lines
})
case SortBy == "blank" || SortBy == "blanks":
sort.Slice(summary.Files, func(i, j int) bool {
return summary.Files[i].Blank > summary.Files[j].Blank
})
case SortBy == "code" || SortBy == "codes":
sort.Slice(summary.Files, func(i, j int) bool {
return summary.Files[i].Code > summary.Files[j].Code
})
case SortBy == "comment" || SortBy == "comments":
sort.Slice(summary.Files, func(i, j int) bool {
return summary.Files[i].Comment > summary.Files[j].Comment
})
case SortBy == "complexity" || SortBy == "complexitys":
sort.Slice(summary.Files, func(i, j int) bool {
return summary.Files[i].Complexity > summary.Files[j].Complexity
})
default:
sort.Slice(summary.Files, func(i, j int) bool {
return summary.Files[i].Lines > summary.Files[j].Lines
})
}
}
// LanguageSummary to generate output like cloc
type languageSummaryCloc struct {
Name string `yaml:"name"`
Code int64 `yaml:"code"`
Comment int64 `yaml:"comment"`
Blank int64 `yaml:"blank"`
Count int64 `yaml:"nFiles"`
}
type summaryStruct struct {
Code int64 `yaml:"code"`
Comment int64 `yaml:"comment"`
Blank int64 `yaml:"blank"`
Count int64 `yaml:"nFiles"`
}
type headerStruct struct {
Url string `yaml:"url"`
Version string `yaml:"version"`
Elapsed_seconds float64 `yaml:"elapsed_seconds"`
N_files int64 `yaml:"n_files"`
N_lines int64 `yaml:"n_lines"`
Files_per_second float64 `yaml:"files_per_second"`
Lines_per_second float64 `yaml:"lines_per_second"`
}
type LanguageReportStart struct {
Header headerStruct
}
type LanguageReportEnd struct {
Sum summaryStruct `yaml:"SUM"`
}
func getTabularShortBreak() string {
if Ci {
return tabularShortBreakCi
}
return tabularShortBreak
}
func getTabularWideBreak() string {
if Ci {
return tabularWideBreakCi
}
return tabularWideBreak
}
func toClocYAML(input chan *FileJob) string {
startTime := makeTimestampMilli()
languages := map[string]languageSummaryCloc{}
var sumFiles, sumLines, sumCode, sumComment, sumBlank, sumComplexity int64 = 0, 0, 0, 0, 0, 0
for res := range input {
sumFiles++
sumLines += res.Lines
sumCode += res.Code
sumComment += res.Comment
sumBlank += res.Blank
sumComplexity += res.Complexity
_, ok := languages[res.Language]
if !ok {
languages[res.Language] = languageSummaryCloc{
Name: res.Language,
Code: res.Code,
Comment: res.Comment,
Blank: res.Blank,
Count: 1,
}
} else {
tmp := languages[res.Language]
languages[res.Language] = languageSummaryCloc{
Name: res.Language,
Code: tmp.Code + res.Code,
Comment: tmp.Comment + res.Comment,
Blank: tmp.Blank + res.Blank,
Count: tmp.Count + 1,
}
}
}
es := float64(makeTimestampMilli()-startTimeMilli) * float64(0.001)
header := headerStruct{
Url: "https://github.com/boyter/scc/",
Version: Version,
N_files: sumFiles,
N_lines: sumLines,
Elapsed_seconds: es,
Files_per_second: float64(float64(sumFiles) / es),
Lines_per_second: float64(float64(sumLines) / es),
}
summary := summaryStruct{
Blank: sumBlank,
Comment: sumComment,
Code: sumCode,
Count: sumFiles,
}
reportStart := LanguageReportStart{
Header: header,
}
reportEnd := LanguageReportEnd{
Sum: summary,
}
report_yaml, _ := yaml.Marshal(reportStart)
sum_yaml, _ := yaml.Marshal(reportEnd)
language_yaml, _ := yaml.Marshal(languages)
yamlString := "# https://github.com/boyter/scc/\n" + string(report_yaml) + string(language_yaml) + string(sum_yaml)
if Debug {
printDebug(fmt.Sprintf("milliseconds to build formatted string: %d", makeTimestampMilli()-startTime))
}
return yamlString
}
func toJSON(input chan *FileJob) string {
startTime := makeTimestampMilli()
languages := map[string]LanguageSummary{}
var sumFiles, sumLines, sumCode, sumComment, sumBlank, sumComplexity int64 = 0, 0, 0, 0, 0, 0
for res := range input {
sumFiles++
sumLines += res.Lines
sumCode += res.Code
sumComment += res.Comment
sumBlank += res.Blank
sumComplexity += res.Complexity
_, ok := languages[res.Language]
if !ok {
files := []*FileJob{}
files = append(files, res)
languages[res.Language] = LanguageSummary{
Name: res.Language,
Lines: res.Lines,
Code: res.Code,
Comment: res.Comment,
Blank: res.Blank,
Complexity: res.Complexity,
Count: 1,
Files: files,
}
} else {
tmp := languages[res.Language]
files := append(tmp.Files, res)
languages[res.Language] = LanguageSummary{
Name: res.Language,
Lines: tmp.Lines + res.Lines,
Code: tmp.Code + res.Code,
Comment: tmp.Comment + res.Comment,
Blank: tmp.Blank + res.Blank,
Complexity: tmp.Complexity + res.Complexity,
Count: tmp.Count + 1,
Files: files,
}
}
}
language := []LanguageSummary{}
for _, summary := range languages {
language = append(language, summary)
}
jsonString, _ := json.Marshal(language)
if Debug {
printDebug(fmt.Sprintf("milliseconds to build formatted string: %d", makeTimestampMilli()-startTime))
}
return string(jsonString)
}
func toCSV(input chan *FileJob) string {
records := [][]string{{
"Language",
"Location",
"Filename",
"Lines",
"Code",
"Comments",
"Blanks",
"Complexity"},
}
for result := range input {
records = append(records, []string{
result.Language,
result.Location,
result.Filename,
fmt.Sprint(result.Lines),
fmt.Sprint(result.Code),
fmt.Sprint(result.Comment),
fmt.Sprint(result.Blank),
fmt.Sprint(result.Complexity)})
}
b := &bytes.Buffer{}
w := csv.NewWriter(b)
w.WriteAll(records)
w.Flush()
return b.String()
}
func fileSummarize(input chan *FileJob) string {
switch {
case More || strings.ToLower(Format) == "wide":
return fileSummarizeLong(input)
case strings.ToLower(Format) == "json":
return toJSON(input)
case strings.ToLower(Format) == "cloc-yaml" || strings.ToLower(Format) == "cloc-yml":
return toClocYAML(input)
case strings.ToLower(Format) == "csv":
return toCSV(input)
}
return fileSummarizeShort(input)
}
func fileSummarizeLong(input chan *FileJob) string {
var str strings.Builder
str.WriteString(getTabularWideBreak())
str.WriteString(fmt.Sprintf(tabularWideFormatHead, "Language", "Files", "Lines", "Code", "Comments", "Blanks", "Complexity", "Complexity/Lines"))
if !Files {
str.WriteString(getTabularWideBreak())
}
languages := map[string]LanguageSummary{}
var sumFiles, sumLines, sumCode, sumComment, sumBlank, sumComplexity int64 = 0, 0, 0, 0, 0, 0
var sumWeightedComplexity float64
for res := range input {
sumFiles++
sumLines += res.Lines
sumCode += res.Code
sumComment += res.Comment
sumBlank += res.Blank
sumComplexity += res.Complexity
var weightedComplexity float64
if res.Code != 0 {
weightedComplexity = (float64(res.Complexity) / float64(res.Code)) * 100
}
res.WeightedComplexity = weightedComplexity
sumWeightedComplexity += weightedComplexity
_, ok := languages[res.Language]
if !ok {
files := []*FileJob{}
files = append(files, res)
languages[res.Language] = LanguageSummary{
Name: res.Language,
Lines: res.Lines,
Code: res.Code,
Comment: res.Comment,
Blank: res.Blank,
Complexity: res.Complexity,
Count: 1,
WeightedComplexity: weightedComplexity,
Files: files,
}
} else {
tmp := languages[res.Language]
files := append(tmp.Files, res)
languages[res.Language] = LanguageSummary{
Name: res.Language,
Lines: tmp.Lines + res.Lines,
Code: tmp.Code + res.Code,
Comment: tmp.Comment + res.Comment,
Blank: tmp.Blank + res.Blank,
Complexity: tmp.Complexity + res.Complexity,
Count: tmp.Count + 1,
WeightedComplexity: tmp.WeightedComplexity + weightedComplexity,
Files: files,
}
}
}
language := []LanguageSummary{}
for _, summary := range languages {
language = append(language, summary)
}
// Cater for the common case of adding plural even for those options that don't make sense
// as its quite common for those who English is not a first language to make a simple mistake
switch {
case SortBy == "name" || SortBy == "names" || SortBy == "language" || SortBy == "languages":
sort.Slice(language, func(i, j int) bool {
return strings.Compare(language[i].Name, language[j].Name) < 0
})
case SortBy == "line" || SortBy == "lines":
sort.Slice(language, func(i, j int) bool {
return language[i].Lines > language[j].Lines
})
case SortBy == "blank" || SortBy == "blanks":
sort.Slice(language, func(i, j int) bool {
return language[i].Blank > language[j].Blank
})
case SortBy == "code" || SortBy == "codes":
sort.Slice(language, func(i, j int) bool {
return language[i].Code > language[j].Code
})
case SortBy == "comment" || SortBy == "comments":
sort.Slice(language, func(i, j int) bool {
return language[i].Comment > language[j].Comment
})
case SortBy == "complexity" || SortBy == "complexitys":
sort.Slice(language, func(i, j int) bool {
return language[i].Complexity > language[j].Complexity
})
default:
sort.Slice(language, func(i, j int) bool {
return language[i].Count > language[j].Count
})
}
startTime := makeTimestampMilli()
for _, summary := range language {
if Files {
str.WriteString(getTabularWideBreak())
}
trimmedName := summary.Name
if len(summary.Name) > longNameTruncate {
trimmedName = summary.Name[:longNameTruncate-1] + "…"
}
str.WriteString(fmt.Sprintf(tabularWideFormatBody, trimmedName, summary.Count, summary.Lines, summary.Code, summary.Comment, summary.Blank, summary.Complexity, summary.WeightedComplexity))
if Files {
sortSummaryFiles(&summary)
str.WriteString(getTabularWideBreak())
for _, res := range summary.Files {
tmp := res.Location
if len(tmp) >= wideFormatFileTrucate {
totrim := len(tmp) - wideFormatFileTrucate
tmp = "~" + tmp[totrim:]
}
str.WriteString(fmt.Sprintf(tabularWideFormatFile, tmp, res.Lines, res.Code, res.Comment, res.Blank, res.Complexity, res.WeightedComplexity))
}
}
}
if Debug {
printDebug(fmt.Sprintf("milliseconds to build formatted string: %d", makeTimestampMilli()-startTime))
}
str.WriteString(getTabularWideBreak())
str.WriteString(fmt.Sprintf(tabularWideFormatBody, "Total", sumFiles, sumLines, sumCode, sumComment, sumBlank, sumComplexity, sumWeightedComplexity))
str.WriteString(getTabularWideBreak())
if !Cocomo {
estimatedEffort := EstimateEffort(int64(sumCode))
estimatedCost := EstimateCost(estimatedEffort, AverageWage)
estimatedScheduleMonths := EstimateScheduleMonths(estimatedEffort)
estimatedPeopleRequired := estimatedEffort / estimatedScheduleMonths
p := gmessage.NewPrinter(glang.English)
str.WriteString(p.Sprintf("Estimated Cost to Develop $%d\n", int64(estimatedCost)))
str.WriteString(fmt.Sprintf("Estimated Schedule Effort %f months\n", estimatedScheduleMonths))
str.WriteString(fmt.Sprintf("Estimated People Required %f\n", estimatedPeopleRequired))
str.WriteString(getTabularWideBreak())
}
return str.String()
}
func fileSummarizeShort(input chan *FileJob) string {
var str strings.Builder
str.WriteString(getTabularShortBreak())
if !Complexity {
str.WriteString(fmt.Sprintf(tabularShortFormatHead, "Language", "Files", "Lines", "Code", "Comments", "Blanks", "Complexity"))
} else {
str.WriteString(fmt.Sprintf(tabularShortFormatHeadNoComplexity, "Language", "Files", "Lines", "Code", "Comments", "Blanks"))
}
if !Files {
str.WriteString(getTabularShortBreak())
}
languages := map[string]LanguageSummary{}
var sumFiles, sumLines, sumCode, sumComment, sumBlank, sumComplexity int64 = 0, 0, 0, 0, 0, 0
for res := range input {
sumFiles++
sumLines += res.Lines
sumCode += res.Code
sumComment += res.Comment
sumBlank += res.Blank
sumComplexity += res.Complexity
_, ok := languages[res.Language]
if !ok {
files := []*FileJob{}
files = append(files, res)
languages[res.Language] = LanguageSummary{
Name: res.Language,
Lines: res.Lines,
Code: res.Code,
Comment: res.Comment,
Blank: res.Blank,
Complexity: res.Complexity,
Count: 1,
Files: files,
}
} else {
tmp := languages[res.Language]
files := append(tmp.Files, res)
languages[res.Language] = LanguageSummary{
Name: res.Language,
Lines: tmp.Lines + res.Lines,
Code: tmp.Code + res.Code,
Comment: tmp.Comment + res.Comment,
Blank: tmp.Blank + res.Blank,
Complexity: tmp.Complexity + res.Complexity,
Count: tmp.Count + 1,
Files: files,
}
}
}
language := []LanguageSummary{}
for _, summary := range languages {
language = append(language, summary)
}
language = sortLanguageSummary(language)
startTime := makeTimestampMilli()
for _, summary := range language {
if Files {
str.WriteString(getTabularShortBreak())
}
trimmedName := summary.Name
trimmedName = trimNameShort(summary, trimmedName)
if !Complexity {
str.WriteString(fmt.Sprintf(tabularShortFormatBody, trimmedName, summary.Count, summary.Lines, summary.Code, summary.Comment, summary.Blank, summary.Complexity))
} else {
str.WriteString(fmt.Sprintf(tabularShortFormatBodyNoComplexity, trimmedName, summary.Count, summary.Lines, summary.Code, summary.Comment, summary.Blank))
}
if Files {
sortSummaryFiles(&summary)
str.WriteString(getTabularShortBreak())
for _, res := range summary.Files {
tmp := res.Location
if len(tmp) >= shortFormatFileTrucate {
totrim := len(tmp) - shortFormatFileTrucate
tmp = "~" + tmp[totrim:]
}
if !Complexity {
str.WriteString(fmt.Sprintf(tabularShortFormatFile, tmp, res.Lines, res.Code, res.Comment, res.Blank, res.Complexity))
} else {
str.WriteString(fmt.Sprintf(tabularShortFormatFileNoComplexity, tmp, res.Lines, res.Code, res.Comment, res.Blank))
}
}
}
}
if Debug {
printDebug(fmt.Sprintf("milliseconds to build formatted string: %d", makeTimestampMilli()-startTime))
}
str.WriteString(getTabularShortBreak())
if !Complexity {
str.WriteString(fmt.Sprintf(tabularShortFormatBody, "Total", sumFiles, sumLines, sumCode, sumComment, sumBlank, sumComplexity))
} else {
str.WriteString(fmt.Sprintf(tabularShortFormatBodyNoComplexity, "Total", sumFiles, sumLines, sumCode, sumComment, sumBlank))
}
str.WriteString(getTabularShortBreak())
calculateCocomo(sumCode, &str)
return str.String()
}
func trimNameShort(summary LanguageSummary, trimmedName string) string {
if len(summary.Name) > shortNameTruncate {
trimmedName = summary.Name[:shortNameTruncate-1] + "…"
}
return trimmedName
}
func calculateCocomo(sumCode int64, str *strings.Builder) {
if !Cocomo {
estimatedEffort := EstimateEffort(int64(sumCode))
estimatedCost := EstimateCost(estimatedEffort, AverageWage)
estimatedScheduleMonths := EstimateScheduleMonths(estimatedEffort)
estimatedPeopleRequired := estimatedEffort / estimatedScheduleMonths
p := gmessage.NewPrinter(glang.English)
str.WriteString(p.Sprintf("Estimated Cost to Develop $%d\n", int64(estimatedCost)))
str.WriteString(fmt.Sprintf("Estimated Schedule Effort %f months\n", estimatedScheduleMonths))
str.WriteString(fmt.Sprintf("Estimated People Required %f\n", estimatedPeopleRequired))
str.WriteString(getTabularShortBreak())
}
}
func sortLanguageSummary(language []LanguageSummary) []LanguageSummary {
// Cater for the common case of adding plural even for those options that don't make sense
// as its quite common for those who English is not a first language to make a simple mistake
// NB in any non name cases if the values are the same we sort by name to ensure
// deterministic output
switch {
case SortBy == "name" || SortBy == "names" || SortBy == "language" || SortBy == "languages":
sort.Slice(language, func(i, j int) bool {
return strings.Compare(language[i].Name, language[j].Name) < 0
})
case SortBy == "line" || SortBy == "lines":
sort.Slice(language, func(i, j int) bool {
if language[i].Lines == language[j].Lines {
return strings.Compare(language[i].Name, language[j].Name) < 0
}
return language[i].Lines > language[j].Lines
})
case SortBy == "blank" || SortBy == "blanks":
sort.Slice(language, func(i, j int) bool {
if language[i].Blank == language[j].Blank {
return strings.Compare(language[i].Name, language[j].Name) < 0
}
return language[i].Blank > language[j].Blank
})
case SortBy == "code" || SortBy == "codes":
sort.Slice(language, func(i, j int) bool {
if language[i].Code == language[j].Code {
return strings.Compare(language[i].Name, language[j].Name) < 0
}
return language[i].Code > language[j].Code
})
case SortBy == "comment" || SortBy == "comments":
sort.Slice(language, func(i, j int) bool {
if language[i].Comment == language[j].Comment {
return strings.Compare(language[i].Name, language[j].Name) < 0
}
return language[i].Comment > language[j].Comment
})
case SortBy == "complexity" || SortBy == "complexitys":
sort.Slice(language, func(i, j int) bool {
if language[i].Complexity == language[j].Complexity {
return strings.Compare(language[i].Name, language[j].Name) < 0
}
return language[i].Complexity > language[j].Complexity
})
default: // Files IE default falls into this category
sort.Slice(language, func(i, j int) bool {
if language[i].Count == language[j].Count {
return strings.Compare(language[i].Name, language[j].Name) < 0
}
return language[i].Count > language[j].Count
})
}
return language
}
// Get the time as standard UTC/Zulu format
func getFormattedTime() string {
return time.Now().UTC().Format(time.RFC3339)
}
// Prints a message to stdout if flag to enable warning output is set
func printWarn(msg string) {
if Verbose {
fmt.Println(fmt.Sprintf(" WARN %s: %s", getFormattedTime(), msg))
}
}
// Prints a message to stdout if flag to enable debug output is set
func printDebug(msg string) {
if Debug {
fmt.Println(fmt.Sprintf("DEBUG %s: %s", getFormattedTime(), msg))
}
}
// Prints a message to stdout if flag to enable trace output is set
func printTrace(msg string) {
if Trace {
fmt.Println(fmt.Sprintf("TRACE %s: %s", getFormattedTime(), msg))
}
}
// Used when explicitly for os.exit output when crashing out
func printError(msg string) {
_, _ = fmt.Fprintf(os.Stderr, "ERROR %s: %s\n", getFormattedTime(), msg)
}