|
| 1 | +package diag |
| 2 | + |
| 3 | +// Builder provides a log entry building api. This should not be used directly, |
| 4 | +// but should be used by calling the component based method on the supplied |
| 5 | +// Diagnostics. |
| 6 | +type Builder struct { |
| 7 | + d *Diagnostics |
| 8 | + e *Diagnostic |
| 9 | +} |
| 10 | + |
| 11 | +func (b *Builder) Fatal(detail, summary string) *Diagnostics { |
| 12 | + return b.build(SeverityFatal, detail, summary) |
| 13 | +} |
| 14 | + |
| 15 | +func (b *Builder) Error(detail, summary string) *Diagnostics { |
| 16 | + return b.build(SeverityError, detail, summary) |
| 17 | +} |
| 18 | + |
| 19 | +func (b *Builder) Warn(detail, summary string) *Diagnostics { |
| 20 | + return b.build(SeverityWarn, detail, summary) |
| 21 | +} |
| 22 | + |
| 23 | +func (b *Builder) Info(detail, summary string) *Diagnostics { |
| 24 | + return b.build(SeverityInfo, detail, summary) |
| 25 | +} |
| 26 | + |
| 27 | +func (b *Builder) Debug(detail, summary string) *Diagnostics { |
| 28 | + return b.build(SeverityDebug, detail, summary) |
| 29 | +} |
| 30 | + |
| 31 | +func (b *Builder) Trace(detail, summary string) *Diagnostics { |
| 32 | + return b.build(SeverityTrace, detail, summary) |
| 33 | +} |
| 34 | + |
| 35 | +func (b *Builder) build(sev Severity, detail, summary string) *Diagnostics { |
| 36 | + diags, diag := b.d, b.e |
| 37 | + |
| 38 | + diag.Severity = sev |
| 39 | + diag.Detail = detail |
| 40 | + diag.Summary = summary |
| 41 | + |
| 42 | + diags.Append(*diag) |
| 43 | + |
| 44 | + return diags |
| 45 | +} |
0 commit comments