Skip to content

Commit 9c57685

Browse files
committed
Shorthand for using map with metrics inside on main context
1 parent de1727a commit 9c57685

File tree

1 file changed

+26
-0
lines changed

1 file changed

+26
-0
lines changed

emf/logger.go

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -107,24 +107,50 @@ func (l *Logger) Metric(name string, value int) *Logger {
107107
return l
108108
}
109109

110+
// Metrics puts all of the int metrics on default context.
111+
func (l *Logger) Metrics(m map[string]int) *Logger {
112+
return l.MetricsAs(m, None)
113+
}
114+
110115
// MetricFloat puts float metric on default context.
111116
func (l *Logger) MetricFloat(name string, value float64) *Logger {
112117
l.defaultContext.put(name, value, None)
113118
return l
114119
}
115120

121+
// MetricsFloat puts all of the float metrics on default context.
122+
func (l *Logger) MetricsFloat(m map[string]float64) *Logger {
123+
return l.MetricsFloatAs(m, None)
124+
}
125+
116126
// MetricAs puts int metric with MetricUnit on default context.
117127
func (l *Logger) MetricAs(name string, value int, unit MetricUnit) *Logger {
118128
l.defaultContext.put(name, value, unit)
119129
return l
120130
}
121131

132+
// Metrics puts all of the int metrics with MetricUnit on default context.
133+
func (l *Logger) MetricsAs(m map[string]int, unit MetricUnit) *Logger {
134+
for name, value := range m {
135+
l.defaultContext.put(name, value, unit)
136+
}
137+
return l
138+
}
139+
122140
// MetricFloatAs puts float metric with MetricUnit on default context.
123141
func (l *Logger) MetricFloatAs(name string, value float64, unit MetricUnit) *Logger {
124142
l.defaultContext.put(name, value, unit)
125143
return l
126144
}
127145

146+
// MetricsFloatAs puts all of the float metrics with MetricUnit on default context.
147+
func (l *Logger) MetricsFloatAs(m map[string]float64, unit MetricUnit) *Logger {
148+
for name, value := range m {
149+
l.defaultContext.put(name, value, unit)
150+
}
151+
return l
152+
}
153+
128154
// Log prints all Contexts and metric values to chosen output in Embedded Metric Format.
129155
func (l *Logger) Log() {
130156
var metrics []MetricDirective

0 commit comments

Comments
 (0)