LogMetrics logs performance metrics
(component string, metrics map[string]interface{})
| 132 | |
| 133 | // LogMetrics logs performance metrics |
| 134 | func LogMetrics(component string, metrics map[string]interface{}) { |
| 135 | attrs := []slog.Attr{ |
| 136 | slog.String("component", component), |
| 137 | slog.Time("timestamp", time.Now()), |
| 138 | } |
| 139 | |
| 140 | for key, value := range metrics { |
| 141 | switch v := value.(type) { |
| 142 | case string: |
| 143 | attrs = append(attrs, slog.String(key, v)) |
| 144 | case int: |
| 145 | attrs = append(attrs, slog.Int(key, v)) |
| 146 | case int64: |
| 147 | attrs = append(attrs, slog.Int64(key, v)) |
| 148 | case float64: |
| 149 | attrs = append(attrs, slog.Float64(key, v)) |
| 150 | case bool: |
| 151 | attrs = append(attrs, slog.Bool(key, v)) |
| 152 | case time.Duration: |
| 153 | attrs = append(attrs, slog.Duration(key, v)) |
| 154 | default: |
| 155 | attrs = append(attrs, slog.Any(key, v)) |
| 156 | } |
| 157 | } |
| 158 | |
| 159 | StructuredInfo("Performance metrics", attrs...) |
| 160 | } |
| 161 | |
| 162 | // SetLogLevel dynamically sets the log level |
| 163 | func SetLogLevel(level slog.Level) { |
nothing calls this directly
no test coverage detected