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 RuleEvalData ¶ added in v0.0.24
type RuleEvalData struct {
RuleName string `json:"name"`
// Action is an ActionOpt string
Action interfaces.ActionOpt `json:"action"`
}
RuleEvalData reports
type TelemetryStore ¶ added in v0.0.24
type TelemetryStore struct {
// Project records the project that the request was associated with.
Project string `json:"project"`
// The resource processed by the request, for example, a repository or a profile.
Resource string `json:"resource"`
// 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(ruleName string, action interfaces.ActionOpt)
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.