Documentation
¶
Overview ¶
Package logger provides a general logging tools
Index ¶
Constants ¶
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 ¶
func Interceptor(cfg config.LoggingConfig) grpc.UnaryServerInterceptor
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 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 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.