-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcolorizers_human_readable.go
123 lines (112 loc) · 4.58 KB
/
colorizers_human_readable.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
package glog
func wrapHumanReadable(v float64, separator, s string, e int) string {
if e < 0 {
e = -e
}
e *= 2
return Float(v, LoggerConfig.AutoFloatPrecision) + separator + Wrap(s, LoggerConfig.ColorUnitHumanReadable+e)
}
// HumanReadableShort colors the same way as Float() does but will make `n` human-readable using short scale suffixes (base1000).
//
// Related config setting(s):
//
// - `LoggerConfig.AutoFloatPrecision`
// - `LoggerConfig.ColorUnitHumanReadable` + exponent of the matching scale step
func HumanReadableShort[N Number](value N) string {
v, e, u := humanReadableShort(value)
return wrapHumanReadable(v, "", u, e)
}
// HumanReadableLong colors the same way as Float() does but will make `n` human-readable using long scale suffixes (base1000).
//
// Related config setting(s):
//
// - `LoggerConfig.AutoFloatPrecision`
// - `LoggerConfig.ColorUnitHumanReadable` + exponent of the matching scale step
func HumanReadableLong[N Number](value N) string {
v, e, u := humanReadableLong(value)
return wrapHumanReadable(v, "", u, e)
}
// HumanReadableIEC colors the same way as Float() does but will make `n` human-readable using IEC-prefixes (base1024).
//
// Related config setting(s):
//
// - `LoggerConfig.AutoFloatPrecision`
// - `LoggerConfig.ColorUnitHumanReadable` + exponent of the matching scale step
func HumanReadableIEC[N Number](value N, unit string) string {
v, e, u := humanReadableIEC(value, unit)
return wrapHumanReadable(v, " ", u, e)
}
// HumanReadableSI colors the same way as Float() does but will make `n` human-readable using SI-prefixes (base1000).
//
// Related config setting(s):
//
// - `LoggerConfig.AutoFloatPrecision`
// - `LoggerConfig.ColorUnitHumanReadable` + exponent of the matching scale step
func HumanReadableSI[N Number](value N, unit string) string {
v, e, u := humanReadableSI(value, unit)
return wrapHumanReadable(v, " ", u, e)
}
// HumanReadableBytesIEC colors the same way as Float() does but will make `bytes` human-readable using IEC-prefixes (base1024).
//
// Related config setting(s):
//
// - `LoggerConfig.AutoFloatPrecision`
// - `LoggerConfig.ColorUnitHumanReadable` + exponent of the matching scale step
func HumanReadableBytesIEC[N Number](bytes N) string {
return HumanReadableIEC(bytes, "B")
}
// HumanReadableBytesSI colors the same way as Float() does but will make `bytes` human-readable using SI-prefixes (base1000).
//
// Related config setting(s):
//
// - `LoggerConfig.AutoFloatPrecision`
// - `LoggerConfig.ColorUnitHumanReadable` + exponent of the matching scale step
func HumanReadableBytesSI[N Number](bytes N) string {
return HumanReadableSI(bytes, "B")
}
// HumanReadableRateIEC colors the same way as Float() does but will make `n` human-readable using IEC-prefixes (base1024).
//
// `interval` defines the duration during which `n` accumulated.
//
// Related config setting(s):
//
// - `LoggerConfig.AutoFloatPrecision`
// - `LoggerConfig.ColorUnitHumanReadable` + exponent of the matching scale step
func HumanReadableRateIEC[N Number](n N, unit, interval string) string {
v, e, u := humanReadableIEC(n, unit)
return wrapHumanReadable(v, " ", u+"/"+interval, e)
}
// HumanReadableRateIEC colors the same way as Float() does but will make `n` human-readable using IEC-prefixes (base1024).
//
// `interval` defines the duration during which `n` accumulated.
//
// Related config setting(s):
//
// - `LoggerConfig.AutoFloatPrecision`
// - `LoggerConfig.ColorUnitHumanReadable` + exponent of the matching scale step
func HumanReadableRateSI[N Number](n N, unit, interval string) string {
v, e, u := humanReadableSI(n, unit)
return wrapHumanReadable(v, " ", u+"/"+interval, e)
}
// HumanReadableRateBytesIEC colors the same way as Float() does but will make `bytes` human-readable using IEC-prefixes (base1024).
//
// `interval` defines the duration during which `bytes` accumulated.
//
// Related config setting(s):
//
// - `LoggerConfig.AutoFloatPrecision`
// - `LoggerConfig.ColorUnitHumanReadable` + exponent of the matching scale step
func HumanReadableRateBytesIEC[N Number](bytes N, interval string) string {
return HumanReadableRateIEC(bytes, "B", interval)
}
// HumanReadableRateBytesSI colors the same way as Float() does but will make `bytes` human-readable using SI-prefixes (base1000).
//
// `interval` defines the duration during which `bytes` accumulated.
//
// Related config setting(s):
//
// - `LoggerConfig.AutoFloatPrecision`
// - `LoggerConfig.ColorUnitHumanReadable` + exponent of the matching scale step
func HumanReadableRateBytesSI[N Number](bytes N, interval string) string {
return HumanReadableRateSI(bytes, "B", interval)
}