Documentation ¶
Index ¶
- Constants
- func AddRequestFields(ctx context.Context, rsFields RequestScopedFields) context.Contextdeprecated
- func DefaultOptions(options ...LoggerOption)
- func NewLogger(config *Config, options ...LoggerOption) *standardLogger
- type AuthPayload
- type Config
- type EventCtxKeydeprecated
- type Field
- func (lf *Field) Bool(key string, b bool) *Field
- func (lf *Field) Bytes(key string, val []byte) *Field
- func (lf *Field) Duration(key string, d time.Duration) *Field
- func (lf *Field) Float32(key string, val float32) *Field
- func (lf *Field) Float64(key string, val float64) *Field
- func (lf *Field) Func(f func(e *zerolog.Event)) *Field
- func (lf *Field) IPAddr(key string, ip net.IP) *Field
- func (lf *Field) Int(key string, val int) *Field
- func (lf *Field) Int64(key string, val int64) *Field
- func (lf *Field) Str(key string, val string) *Field
- func (lf *Field) Time(key string, t time.Time) *Field
- func (lf *Field) UInt(key string, val uint) *Field
- func (lf *Field) UInt64(key string, val uint64) *Field
- func (lf *Field) UUID(key string, uuid uuid.UUID) *Field
- type Logger
- type LoggerOption
- func WithAuthenticatedUserTracing(auth *AuthPayload) LoggerOption
- func WithAuthorizationTracing(req *http.Request) LoggerOption
- func WithDatadogTracing(ctx context.Context) LoggerOption
- func WithProperties(fields *Field) LoggerOption
- func WithRequestDiagnostics(req *http.Request) LoggerOption
- func WithRequestTracing(req *http.Request) LoggerOption
- func WithSystemTracing() LoggerOption
- type Property
- func (lf *Property) Details(details string)
- func (lf *Property) Detailsf(format string, v ...interface{})
- func (lf *Property) Properties(fields *Field) *Property
- func (lf *Property) Send()
- func (lf *Property) WithAuthenticatedUserTracing(auth *AuthPayload) *Property
- func (lf *Property) WithAuthorizationTracing(req *http.Request) *Property
- func (lf *Property) WithDatadogTracing(ctx context.Context) *Property
- func (lf *Property) WithGlamplifyRequestFieldsFromCtx(ctx context.Context) *Propertydeprecated
- func (lf *Property) WithRequestDiagnostics(req *http.Request) *Property
- func (lf *Property) WithRequestTracing(req *http.Request) *Property
- func (lf *Property) WithSystemTracing() *Property
- type RequestScopedFieldsdeprecated
Constants ¶
const ( AppVerDefault = "1.0.0" AwsAccountIDDefault = "development" AppFarmDefault = "local" LogLevelDefault = "INFO" MissingDefault = "<missing>" )
const ( // *** Global Environment Variables ***. AppNameEnv = "APP" AppNameLeagcyEnv = "APP_NAME" AppVerEnv = "APP_VERSION" AppFarmEnv = "FARM" AppFarmLegacyEnv = "APP_ENV" ProductEnv = "PRODUCT" // *** AWS Environment Variables ***. AwsProfileEnv = "AWS_PROFILE" AwsRegionEnv = "AWS_REGION" AwsAccountIDEnv = "AWS_ACCOUNT_ID" // *** Log Environment Variables ***. LogLevelEnv = "LOG_LEVEL" LogQuietModeEnv = "QUIET_MODE" LogConsoleWriterEnv = "CONSOLE_WRITER" LogConsoleColourEnv = "CONSOLE_COLOUR" )
const ( TraceIDHeader = "X-amzn-Trace-ID" RequestIDHeader = "X-Request-ID" CorrelationIDHeader = "X-Correlation-ID" ErrorUUID = "00000000-0000-0000-0000-000000000000" AuthorizationHeader = "Authorization" XCAServiceGatewayAuthorizationHeader = "X-CA-SGW-Authorization" UserAgentHeader = "User-Agent" XForwardedForHeader = "X-Forwarded-For" )
Variables ¶
This section is empty.
Functions ¶
func AddRequestFields
deprecated
added in
v0.0.34
func AddRequestFields(ctx context.Context, rsFields RequestScopedFields) context.Context
Deprecated: AddRequestFields adds a RequestScopedFields to the context. Please migrate to use the WithRequestTracing() and WithAuthenticatedUserTracing() extension methods.
func DefaultOptions ¶ added in v1.0.24
func DefaultOptions(options ...LoggerOption)
DefaultOptions adds global properties to the DefaultLogger. Note: This creates a new DefaultLogger.
func NewLogger ¶ added in v0.0.13
func NewLogger(config *Config, options ...LoggerOption) *standardLogger
NewLogger creates a new standardLogger using the supplied config.
Types ¶
type AuthPayload ¶
type AuthPayload struct { // CustomerAccountID is the ID of the currently logged in user's parent // account/organization, sometimes known as the "account_aggregate_id". CustomerAccountID string // UserID is the ID of the currently authenticated user, and will // generally be a "user_aggregate_id". UserID string // RealUserID, when supplied, is the ID of the user who is currently // impersonating the current "UserID". This value is optional. RealUserID string }
AuthPayload contains the customer account_id, user_id and realuser_id uuids.
type Config ¶ added in v0.0.13
type Config struct { // Mandatory fields listed in https://cultureamp.atlassian.net/wiki/spaces/TV/pages/3114598406/Logging+Standard AppName string `env:"APP" envDefault:"<unknown>"` // The name of the application the log was generated from AppVersion string `env:"APP_VERSION" envDefault:"1.0.0"` // The version of the application AwsRegion string `env:"AWS_REGION" envDefault:"dev"` // the AWS region this code is running in AwsAccountID string `env:"AWS_ACCOUNT_ID" envDefault:"development"` // the AWS account ID this code is running in Product string `env:"PRODUCT" envDefault:"<unknown>"` // performance, engagmentment, etc. Farm string `env:"FARM" envDefault:"local"` // The name of the farm or where the code is running LogLevel string `env:"LOG_LEVEL" envDefault:"INFO"` // The logging level Quiet bool `env:"QUIET_MODE" envDefault:"false"` // Are we running inside tests and we should be quiet? ConsoleWriter bool `env:"CONSOLE_WRITER" envDefault:"false"` // If ConsoleWriter=true then key-value pair output ConsoleColour bool `env:"CONSOLE_COLOUR" envDefault:"false"` // If ConsoleWriter=true then enable/disable colour TimeNow timeNowFunc // Defaults to "time.Now" but useful to set in tests }
Config contains logging configuration values.
func NewLoggerConfig ¶ added in v0.0.13
NewLoggerConfig creates a new configuration based on environment variables which can easily be reset before passing to NewLogger().
type EventCtxKey
deprecated
added in
v0.0.34
type EventCtxKey int
Deprecated: EventCtxKey type.
const ( // Deprecated: RequestFieldsCtx EventCtxKey = iota. RequestFieldsCtx EventCtxKey = iota )
type Field ¶ added in v0.0.37
type Field struct {
// contains filtered or unexported fields
}
Field contains an element of the log, usually a key-value pair.
func (*Field) Bytes ¶ added in v1.0.12
Bytes adds the property key with val as an []byte to the log.
func (*Field) Duration ¶ added in v0.0.37
Duration adds the property key with val as an time.Duration to the log.
func (*Field) Float32 ¶ added in v1.0.12
Float32 adds the property key with val as an float32 to the log.
func (*Field) Float64 ¶ added in v1.0.12
Float64 adds the property key with val as an float64 to the log.
func (*Field) Func ¶ added in v1.0.7
Func allows an anonymous func to run for the accumulated event.
func (*Field) IPAddr ¶ added in v0.0.37
IPAddr adds the property key with val as an net.IP to the log.
func (*Field) Str ¶ added in v0.0.37
Str adds the property key with val as a string to the log. Note: Empty string values will not be logged.
func (*Field) Time ¶ added in v0.0.37
Time adds the property key with val as an uuid.UUID to the log.
type Logger ¶
type Logger interface { Debug(event string) *Property Info(event string) *Property Warn(event string) *Property Error(event string, err error) *Property Fatal(event string, err error) *Property Panic(event string, err error) *Property Child(options ...LoggerOption) Logger WithContext(ctx context.Context) context.Context }
Logger interface used for mock testing.
DefaultLogger is the package level default implementation used by all package level methods. Package level methods are provided for ease of use. For testing you can replace the DefaultLogger with your own mock:
DefaultLogger = newmockLogger().
type LoggerOption ¶ added in v1.0.24
func WithAuthenticatedUserTracing ¶ added in v1.0.24
func WithAuthenticatedUserTracing(auth *AuthPayload) LoggerOption
WithAuthenticatedUserTracing adds an "authentication" subdocument to the log that includes important account, user and realuser fields.
func WithAuthorizationTracing ¶ added in v1.0.24
func WithAuthorizationTracing(req *http.Request) LoggerOption
WithAuthorizationTracing adds an "authorization" subdocument to the log that includes important authorization headers that are automatically redacted.
func WithDatadogTracing ¶ added in v1.0.24
func WithDatadogTracing(ctx context.Context) LoggerOption
WithDatadogTracing adds a "datadog" subdocument to the log that includes the fields dd.trace_id and dd.span_id. If Xray is configured it also adds xray.trace_id and xray.seg_id fields.
func WithProperties ¶ added in v1.0.24
func WithProperties(fields *Field) LoggerOption
func WithRequestDiagnostics ¶ added in v1.0.24
func WithRequestDiagnostics(req *http.Request) LoggerOption
WithRequestDiagnostics adds a "request" subdocument to the log that includes important request fields.
func WithRequestTracing ¶ added in v1.0.24
func WithRequestTracing(req *http.Request) LoggerOption
WithRequestTracing adds a "tracing" subdocument to the log that includes important trace, request and correlation fields.
func WithSystemTracing ¶ added in v1.0.24
func WithSystemTracing() LoggerOption
WithSystemTracing adds a "system" subdocument to the log that includes important host, runtime, cpu and loc fields.
type Property ¶ added in v0.0.13
type Property struct {
// contains filtered or unexported fields
}
Property contains an element of the log, usually a key-value pair.
func Debug ¶
Debug starts a new message with debug level.
You must call Details, Detailsf or Send on the returned event in order to send the event to the output.
func Error ¶
Error starts a new message with error level.
You must call Details, Detailsf or Send on the returned event in order to send the event to the output.
func Fatal ¶
Fatal starts a new message with fatal level. The os.Exit(1) function is called by the Msg method, which terminates the program immediately.
You must call Details, Detailsf or Send on the returned event in order to send the event to the output.
func Info ¶
Info starts a new message with info level.
You must call Details, Detailsf or Send on the returned event in order to send the event to the output.
func Panic ¶
Panic starts a new message with panic level. The panic() function is called by the Msg method, which stops the ordinary flow of a goroutine.
You must call Details, Detailsf or Send on the returned event in order to send the event to the output.
func Warn ¶
Warn starts a new message with warn level.
You must call Details, Detailsf or Send on the returned event in order to send the event to the output.
func (*Property) Details ¶ added in v0.0.13
Details adds the property 'details' with the val as a string to the log. This is a terminating Property that signals that the log statement is complete and can now be sent to the output.
NOTICE: once this method is called, the *Property should be disposed. Calling Details twice can have unexpected results.
func (*Property) Detailsf ¶ added in v0.0.13
Detailsf adds the property 'details' with the format and args to the log. This is a terminating Property that signals that the log statement is complete and can now be sent to the output.
NOTICE: once this method is called, the *Property should be disposed. Calling Detailsf twice can have unexpected results.
func (*Property) Properties ¶ added in v0.0.13
Properties adds an entire sub-document of type Property to the log.
func (*Property) Send ¶ added in v0.0.13
func (lf *Property) Send()
Send terminates the log and signals that it is now complete and can be sent to the output.
NOTICE: once this method is called, the *Property should be disposed. Calling Send twice can have unexpected results.
func (*Property) WithAuthenticatedUserTracing ¶ added in v0.0.13
func (lf *Property) WithAuthenticatedUserTracing(auth *AuthPayload) *Property
WithAuthenticatedUserTracing adds an "authentication" subdocument to the log that includes important account, user and realuser fields.
func (*Property) WithAuthorizationTracing ¶ added in v0.0.29
WithAuthorizationTracing adds an "authorization" subdocument to the log that includes important authorization headers that are automatically redacted.
func (*Property) WithDatadogTracing ¶ added in v1.0.7
WithDatadogTracing adds a "datadog" subdocument to the log that includes the fields dd.trace_id and dd.span_id. If Xray is configured it also adds xray.trace_id and xray.seg_id fields.
func (*Property) WithGlamplifyRequestFieldsFromCtx
deprecated
added in
v0.0.34
func (*Property) WithRequestDiagnostics ¶ added in v0.0.40
WithRequestDiagnostics adds a "request" subdocument to the log that includes important request fields.
func (*Property) WithRequestTracing ¶ added in v0.0.13
WithRequestTracing adds a "tracing" subdocument to the log that includes important trace, request and correlation fields.
func (*Property) WithSystemTracing ¶ added in v0.0.13
WithSystemTracing adds a "system" subdocument to the log that includes important host, runtime, cpu and loc fields.
type RequestScopedFields
deprecated
added in
v0.0.34
type RequestScopedFields struct { TraceID string `json:"trace_id"` // AWS XRAY trace id. Format of this is controlled by AWS. Do not rely on it, some services may not use XRAY. RequestID string `json:"request_id"` // Client generated RANDOM string. Most of the time this will be empty. Clients can set this to help us diagnose issues. CorrelationID string `json:"correlation_id"` // Set ALWAYS by the web-gateway as a UUID v4. UserAggregateID string `json:"user"` // If JWT and correct key present, then this will be set to the Effective User UUID CustomerAggregateID string `json:"customer"` // If JWT and correct key present, then this will be set to the Customer UUID (aka Account) }
Deprecated: RequestScopedFields instead use the WithRequestTracing() and WithAuthenticatedUserTracing() extension methods.
func GetRequestScopedFields
deprecated
added in
v0.0.34
func GetRequestScopedFields(ctx context.Context) (RequestScopedFields, bool)
Deprecated: GetRequestScopedFields gets the RequestScopedFields from the context. Please migrate to use the WithRequestTracing() and WithAuthenticatedUserTracing() extension methods.