Documentation ¶
Index ¶
- Constants
- Variables
- func ContextWithRequestID(ctx context.Context) context.Context
- func DBG(ctx context.Context, metadata interface{}, message string)
- func ERR(ctx context.Context, err error, message string)
- func ErrMetadata(err error) map[string]interface{}
- func FTL(ctx context.Context, err error, message string)
- func GenRequestID() string
- func GetRequestID(ctx context.Context) string
- func INF(ctx context.Context, metadata interface{}, message string)
- func Metadata(detail interface{}) map[string]interface{}
- func New(configs ...Config) error
- func NewContext(in ...context.Context) context.Context
- func SetRequestID(ctx context.Context, id string) context.Context
- func SetRequestIDFromMetadata(ctx context.Context) context.Context
- func TRC(ctx context.Context, metadata interface{}, message string)
- func WRN(ctx context.Context, err error, message string)
- type Config
- type KV
- type Logger
- type PGX
- type ZeroLogger
- func (z *ZeroLogger) Debug(requestID string, fields map[string]interface{}, message string)
- func (z *ZeroLogger) Error(requestID string, err error, fields map[string]interface{}, message string)
- func (z *ZeroLogger) Fatal(requestID string, err error, fields map[string]interface{}, message string)
- func (z *ZeroLogger) Info(requestID string, fields map[string]interface{}, message string)
- func (z *ZeroLogger) Trace(requestID string, fields map[string]interface{}, message string)
- func (z *ZeroLogger) Warn(requestID string, err error, fields map[string]interface{}, message string)
Constants ¶
const (
CtxKeyRequestID = contextKey(RequestID)
)
const ( // RequestID is a random generated string to identify each request. // Example: qwerty1234. RequestID = tags.RequestID )
Key for standardized context value.
Variables ¶
var ( // DefaultConfig is a configuration to create: // - Non JSON structured. // - No app name. // - Output to os.Stderr. DefaultConfig = Config{ Debug: true, AppName: "", Filename: "", } )
Functions ¶
func ContextWithRequestID ¶
ContextWithRequestID checks if current context has request id already and assign one if none found. Use for middleware and intercept all incoming requests to assign request id to the context if it doesn't exist.
func ErrMetadata ¶
ErrMetadata returns a metadata constructed from error. If you are printing a log, this metadata should always be set. Useful if you want to trace log with certain information.
func GetRequestID ¶
GetContextID returns a request id assigned inside a context.
func Metadata ¶
func Metadata(detail interface{}) map[string]interface{}
Metadata returns a basic metadata added a more detail metadata.
func NewContext ¶
NewContext returns a context with built-in request id.
func SetRequestID ¶
SetRequestID returns a context with assigned request id.
func SetRequestIDFromMetadata ¶
SetRequestIDFromMetadata returns a context with request id and context id value if they exists in metadata.
Types ¶
type Logger ¶
type Logger interface { Trace( requestID string, fields map[string]interface{}, message string, ) Debug( requestID string, fields map[string]interface{}, message string, ) Info( requestID string, fields map[string]interface{}, message string, ) Warn( requestID string, err error, fields map[string]interface{}, message string, ) Error( requestID string, err error, fields map[string]interface{}, message string, ) Fatal( requestID string, err error, fields map[string]interface{}, message string, ) }
type ZeroLogger ¶
type ZeroLogger struct {
// contains filtered or unexported fields
}
func NewZerolog ¶
func NewZerolog(config Config) (*ZeroLogger, error)
func (*ZeroLogger) Debug ¶
func (z *ZeroLogger) Debug( requestID string, fields map[string]interface{}, message string, )
func (*ZeroLogger) Error ¶
func (z *ZeroLogger) Error( requestID string, err error, fields map[string]interface{}, message string, )
func (*ZeroLogger) Fatal ¶
func (z *ZeroLogger) Fatal( requestID string, err error, fields map[string]interface{}, message string, )
func (*ZeroLogger) Info ¶
func (z *ZeroLogger) Info( requestID string, fields map[string]interface{}, message string, )