logger

package
v0.0.35 Latest Latest
Warning

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

Go to latest
Published: Mar 13, 2024 License: Apache-2.0 Imports: 23 Imported by: 0

Documentation

Overview

Package logger provides a general logging tools

Index

Constants

View Source
const Text = "text"

Text is the constant for the text format

Variables

This section is empty.

Functions

func FromFlags

func FromFlags(cfg config.LoggingConfig) zerolog.Logger

FromFlags configures logging and returns a logger with settings matching the supplied cfg. It also performs some global initialization, because that's how zerolog works.

func Interceptor

Interceptor creates a gRPC unary server interceptor that logs incoming requests and their responses using the Zerolog logger attached to the context.Context. Successful requests are logged at the info level and error requests are logged at the error level.

Returns:

  • grpc.UnaryServerInterceptor: The gRPC unary server interceptor function.

Example usage:

server := grpc.NewServer(
  ...
  grpc.UnaryServerInterceptor(logger.Interceptor(loggingConfig)),
  ...
)

Types

type ActionEvalData added in v0.0.25

type ActionEvalData struct {
	// how was the action configured - on, off, ...
	State string `json:"state"`
	// what was the result of the action - success, failure, ...
	Result string `json:"result"`
}

ActionEvalData reports

type Profile added in v0.0.27

type Profile struct {
	Name string    `json:"name"`
	ID   uuid.UUID `json:"id"`
}

Profile is a struct describing a Profile for telemetry purposes

type RuleEvalData added in v0.0.24

type RuleEvalData struct {
	RuleType RuleType `json:"ruletype"`
	Profile  Profile  `json:"profile"`

	EvalResult string                                   `json:"eval_result"`
	Actions    map[interfaces.ActionType]ActionEvalData `json:"actions"`
}

RuleEvalData reports

type RuleType added in v0.0.27

type RuleType struct {
	Name string    `json:"name"`
	ID   uuid.UUID `json:"id"`
}

RuleType is a struct describing a rule type for telemetry purposes

type TelemetryStore added in v0.0.24

type TelemetryStore struct {
	// Project records the project ID that the request was associated with.
	Project uuid.UUID `json:"project"`

	// Provider records the provider name that the request was associated with.
	Provider string `json:"provider"`

	// Repository is the repository ID that the request was associated with.
	Repository uuid.UUID `json:"repository"`

	// Artifact is the artifact ID that the request was associated with.
	Artifact uuid.UUID `json:"artifact"`

	// PullRequest is the pull request ID that the request was associated with.
	PullRequest uuid.UUID `json:"pr"`

	// Profile is the profile that the request was associated with.
	Profile Profile `json:"profile"`

	// RuleType is the rule type that the request was associated with.
	RuleType RuleType `json:"ruletype"`

	// Hashed (SHA256) `sub` from the JWT.  This should be hard to reverse (pseudonymized),
	// but allows correlation between requests.
	LoginHash string `json:"login_sha"`

	// Rules evaluated during processing
	Evals []RuleEvalData `json:"rules"`
}

TelemetryStore is a struct that can be used to store telemetry data in the context.

func BusinessRecord added in v0.0.24

func BusinessRecord(ctx context.Context) *TelemetryStore

BusinessRecord provides the ability to store an observation about the current flow of business logic in the context of the current request. When called in in the context of a logged action, it will record and send the marshalled data to the logging system.

When called outside a logged context, it will collect and discard the data.

func (*TelemetryStore) AddRuleEval added in v0.0.24

func (ts *TelemetryStore) AddRuleEval(
	evalInfo interfaces.ActionsParams,
)

AddRuleEval is a convenience method to add a rule evaluation result to the telemetry store.

func (*TelemetryStore) Record added in v0.0.24

func (ts *TelemetryStore) Record(e *zerolog.Event) *zerolog.Event

Record adds the collected data to the supplied event record.

func (*TelemetryStore) WithTelemetry added in v0.0.24

func (ts *TelemetryStore) WithTelemetry(ctx context.Context) context.Context

WithTelemetry enriches the current context with a TelemetryStore which will collect observations about the current flow of business logic.

type TelemetryStoreWMMiddleware added in v0.0.25

type TelemetryStoreWMMiddleware struct {
	// contains filtered or unexported fields
}

TelemetryStoreWMMiddleware is a Watermill middleware that logs the relevant telemetry data.

func NewTelemetryStoreWMMiddleware added in v0.0.25

func NewTelemetryStoreWMMiddleware(l *zerolog.Logger) *TelemetryStoreWMMiddleware

NewTelemetryStoreWMMiddleware returns a new TelemetryStoreWMMiddleware.

func (*TelemetryStoreWMMiddleware) TelemetryStoreMiddleware added in v0.0.25

func (m *TelemetryStoreWMMiddleware) TelemetryStoreMiddleware(h message.HandlerFunc) message.HandlerFunc

TelemetryStoreMiddleware is a Watermill middleware that logs the relevant telemetry data.

Jump to

Keyboard shortcuts

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