annotations

package
v1.168.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jul 24, 2026 License: Apache-2.0 Imports: 8 Imported by: 0

Documentation

Overview

Package annotations provides loggers for emitting structured build and CI annotations such as errors, warnings, and notices.

Unlike ordinary log lines, annotations are intended for systems that can highlight issues in a richer way, for example by attaching messages to files and line numbers or surfacing build problems prominently in the UI.

The package provides a generic annotation model plus platform-specific formatters for common CI systems. Annotation loggers are built on top of the repository's [logs.Loggers] abstraction so they can reuse existing logging sinks.

References:

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func SeverityStrings

func SeverityStrings() []string

SeverityStrings returns a slice of all String values of the enum

Types

type Annotation

type Annotation struct {
	// Severity identifies whether the annotation is an error, warning, or notice.
	Severity Severity
	// Message is the human-readable annotation text.
	Message string
	// File is the file path associated with the annotation, if any.
	File string
	// Line is the 1-based line number associated with the annotation, if any.
	Line *int
	// Column is the 1-based column number associated with the annotation, if any.
	Column *int
}

Annotation describes a structured annotation message.

type AnnotationLogger

type AnnotationLogger struct {
	baselogs.Loggers
	// contains filtered or unexported fields
}

AnnotationLogger formats annotations and emits them through an underlying logger.

The logger delegates final emission to an existing [logs.Loggers] implementation and is therefore suitable for any sink already supported by the logs package.

func NewAzureDevOpsLogger

func NewAzureDevOpsLogger(baseLogger baselogs.Loggers) (*AnnotationLogger, error)

NewAzureDevOpsLogger creates an Azure DevOps-formatted annotation logger backed by baseLogger.

func NewGitHubLogger

func NewGitHubLogger(baseLogger baselogs.Loggers) (*AnnotationLogger, error)

NewGitHubLogger creates a GitHub-formatted annotation logger backed by baseLogger.

func NewLogger

func NewLogger(baseLogger baselogs.Loggers, formatter IFormatter) (*AnnotationLogger, error)

NewLogger creates an annotation logger backed by baseLogger.

func NewTeamCityLogger

func NewTeamCityLogger(baseLogger baselogs.Loggers) (*AnnotationLogger, error)

NewTeamCityLogger creates a TeamCity-formatted annotation logger backed by baseLogger.

func (*AnnotationLogger) Check

func (l *AnnotationLogger) Check() error

func (*AnnotationLogger) WriteAnnotation

func (l *AnnotationLogger) WriteAnnotation(annotation *Annotation) error

WriteAnnotation writes annotation using the configured formatter.

func (*AnnotationLogger) WriteError

func (l *AnnotationLogger) WriteError(message string, options ...AnnotationOption) error

WriteError writes an error-level annotation.

func (*AnnotationLogger) WriteNotice

func (l *AnnotationLogger) WriteNotice(message string, options ...AnnotationOption) error

WriteNotice writes a notice-level annotation.

func (*AnnotationLogger) WriteWarning

func (l *AnnotationLogger) WriteWarning(message string, options ...AnnotationOption) error

WriteWarning writes a warning-level annotation.

type AnnotationOption

type AnnotationOption func(*Annotation) *Annotation

AnnotationOption configures an annotation.

func WithColumn

func WithColumn(column int) AnnotationOption

WithColumn sets the column associated with an annotation.

func WithFile

func WithFile(path string) AnnotationOption

WithFile sets the file path associated with an annotation.

func WithLine

func WithLine(line int) AnnotationOption

WithLine sets the line associated with an annotation.

type AzureDevOpsFormatter

type AzureDevOpsFormatter struct{}

AzureDevOpsFormatter formats annotations as Azure DevOps logging commands.

Reference:

func (AzureDevOpsFormatter) Format

func (AzureDevOpsFormatter) Format(annotation *Annotation) string

type GitHubFormatter

type GitHubFormatter struct{}

GitHubFormatter formats annotations as GitHub Actions annotation commands.

Reference:

func (GitHubFormatter) Format

func (GitHubFormatter) Format(annotation *Annotation) string

type IAnnotationLogger

type IAnnotationLogger interface {
	baselogs.Loggers
	// WriteAnnotation writes annotation using the configured formatter.
	WriteAnnotation(annotation *Annotation) error
	// WriteError writes an error-level annotation.
	WriteError(message string, options ...AnnotationOption) error
	// WriteWarning writes a warning-level annotation.
	WriteWarning(message string, options ...AnnotationOption) error
	// WriteNotice writes a notice-level annotation.
	WriteNotice(message string, options ...AnnotationOption) error
}

IAnnotationLogger extends [logs.Loggers] with methods for writing structured annotations.

An annotation logger emits issue records in a format that CI systems can interpret specially, for example by surfacing them as file-linked errors or warnings in the build UI.

type IFormatter

type IFormatter interface {
	Format(annotation *Annotation) string
}

IFormatter converts an annotation into the platform-specific line to emit.

References:

type Severity

type Severity int

Severity identifies the severity of an annotation.

const (
	SeverityError Severity = iota
	SeverityWarning
	SeverityNotice
)

func SeverityString

func SeverityString(s string) (Severity, error)

SeverityString retrieves an enum value from the enum constants string name. Throws an error if the param is not part of the enum.

func SeverityValues

func SeverityValues() []Severity

SeverityValues returns all values of the enum

func (Severity) IsASeverity

func (i Severity) IsASeverity() bool

IsASeverity returns "true" if the value is listed in the enum definition. "false" otherwise

func (Severity) MarshalJSON

func (i Severity) MarshalJSON() ([]byte, error)

MarshalJSON implements the json.Marshaler interface for Severity

func (Severity) MarshalText

func (i Severity) MarshalText() ([]byte, error)

MarshalText implements the encoding.TextMarshaler interface for Severity

func (Severity) MarshalYAML

func (i Severity) MarshalYAML() (interface{}, error)

MarshalYAML implements a YAML Marshaler for Severity

func (Severity) String

func (i Severity) String() string

func (*Severity) UnmarshalJSON

func (i *Severity) UnmarshalJSON(data []byte) error

UnmarshalJSON implements the json.Unmarshaler interface for Severity

func (*Severity) UnmarshalText

func (i *Severity) UnmarshalText(text []byte) error

UnmarshalText implements the encoding.TextUnmarshaler interface for Severity

func (*Severity) UnmarshalYAML

func (i *Severity) UnmarshalYAML(unmarshal func(interface{}) error) error

UnmarshalYAML implements a YAML Unmarshaler for Severity

type TeamCityFormatter

type TeamCityFormatter struct{}

TeamCityFormatter formats annotations as TeamCity service messages.

Reference:

func (TeamCityFormatter) Format

func (TeamCityFormatter) Format(annotation *Annotation) string

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL