log

package
v0.0.0-...-b595bbb Latest Latest
Warning

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

Go to latest
Published: Jun 10, 2024 License: AGPL-3.0 Imports: 7 Imported by: 0

Documentation

Index

Constants

View Source
const (
	FieldAction                = "action"                  // name of the action field
	FieldAuthClient            = "auth_client"             // name of the auth client field
	FieldAuthClientID          = "auth_client_id"          // name of the auth client id field
	FieldAuthCode              = "auth_code"               // name of the code field
	FieldBindVars              = "bind_vars"               // name of the query bind vars field
	FieldCollection            = "collection"              // name of the collection field
	FieldCollectionOptions     = "collection_options"      // name of the collection field
	FieldDatabase              = "database"                // name of the database field
	Field                      = "details"                 // name of the details field
	FieldDocument              = "document"                // name of the document field
	FieldDocumentCount         = "document_count"          // name of the document count field
	FieldDuration              = "duration"                // name of the duration field
	FieldEmail                 = "email"                   // name of the email field
	FieldEndpoints             = "endpoints"               // name of the endpoints field
	FieldFilter                = "filter"                  // name of the filter field
	FieldIdleConnectionTimeout = "idle_connection_timeout" // name of the idle connection timeout field
	FieldIndexFields           = "fields"                  // name of the index fields
	FieldIndexOptions          = "index_options"           // name of the index options field
	FieldInput                 = "input"                   // name of the input field
	FieldKey                   = "key"                     // name of the key field
	FieldKind                  = "kind"                    // name of the kind field
	FieldLimit                 = "limit"                   // name of the limit field
	FieldMaxIdleConnections    = "max_idle_connections"    // name of the max idle connections field
	FieldMaxOpenConnections    = "max_open_connections"    // name of the max open connections field
	FieldMethod                = "method"                  // name of the method field
	FieldOffset                = "offset"                  // name of the offset field
	FieldOperationID           = "operation_id"            // name of the operation id field
	FieldPath                  = "path"                    // name of the path field
	FieldProtocol              = "protocol"                // name of the protocol field
	FieldQuery                 = "query"                   // name of the query field
	FieldRemoteAddr            = "remote_addr"             // name of the remote address field
	FieldRequestID             = "request_id"              // name of the request id field
	FieldRoles                 = "roles"                   // name of the roles field
	FieldScopes                = "scopes"                  // name of the scopes field
	FieldSession               = "session"                 // name of the session field
	FieldSize                  = "size"                    // name of the size field
	FieldStatus                = "status"                  // name of the user status field
	FieldTTL                   = "ttl"                     // name of the ttl field
	FieldToken                 = "token"                   // name of the token field
	FieldURL                   = "url"                     // name of the url field
	FieldUser                  = "user"                    // name of the user field
	FieldUserAgent             = "user_agent"              // name of the user agent field
	FieldUserID                = "user_id"                 // name of the user id field
	FieldUsername              = "username"                // name of the username field
	FieldValue                 = "value"                   // name of the value field
)

Variables

View Source
var (
	ErrNoLogger            = errors.New("no logger")             // the logger is missing
	ErrInvalidLogLevel     = errors.New("invalid log level")     // invalid log level
	ErrInvalidLoggerConfig = errors.New("invalid logger config") // invalid logger config

)

Functions

func Debug

func Debug(ctx context.Context, message string, fields ...zap.Field)

Debug logs the message with the debug level.

func Error

func Error(ctx context.Context, err error, fields ...zap.Field)

Error logs the message with the error level.

func Fatal

func Fatal(ctx context.Context, message string, fields ...zap.Field)

Fatal logs the message with the fatal level.

func Info

func Info(ctx context.Context, message string, fields ...zap.Field)

Info logs the message with the info level.

func Log

func Log(ctx context.Context, level zapcore.Level, message string, fields ...zap.Field)

Log logs the message with the given level. NOTE: This may log sensitive information. TODO: Implement a log filter to filter out sensitive information.

func Panic

func Panic(ctx context.Context, message string, fields ...zap.Field)

Panic logs the message with the panic level.

func Warn

func Warn(ctx context.Context, message string, fields ...zap.Field)

Warn logs the message with the warn level.

func WithAction

func WithAction(action Action) zap.Field

WithAction sets the action field.

func WithAuthClient

func WithAuthClient(client any) zap.Field

WithAuthClient sets the auth client field.

func WithAuthClientID

func WithAuthClientID(clientID string) zap.Field

WithAuthClientID sets the auth client id field.

func WithAuthCode

func WithAuthCode(code string) zap.Field

WithAuthCode sets the authorization code field.

func WithBindVars

func WithBindVars(bindVars map[string]any) zap.Field

WithBindVars sets the query bind vars field.

func WithCollectionOptions

func WithCollectionOptions(collectionOpts any) zap.Field

WithCollectionOptions sets the index options field.

func WithContext

func WithContext(ctx context.Context, logger Logger) context.Context

WithContext returns a new context with the logger. If the logger is not provided, it returns the context with the global logger assigned.

func WithDatabase

func WithDatabase(database string) zap.Field

WithDatabase sets the database field.

func WithDetails

func WithDetails(details string) zap.Field

WithDetails sets the details field.

func WithDocument

func WithDocument(document any) zap.Field

WithDocument sets the document field.

func WithDocumentCount

func WithDocumentCount(count int64) zap.Field

WithDocumentCount sets the document count field.

func WithDuration

func WithDuration[D time.Duration | float64 | int64](duration D) zap.Field

WithDuration sets the duration field.

func WithEmail

func WithEmail(email string) zap.Field

WithEmail sets the email field.

func WithEndpoints

func WithEndpoints(endpoints []string) zap.Field

WithEndpoints sets the endpoints field.

func WithError

func WithError(err error) zap.Field

WithError sets the error field.

func WithFilter

func WithFilter(filter any) zap.Field

WithFilter sets the filter field.

func WithIdleConnectionTimeout

func WithIdleConnectionTimeout(idleTimeout time.Duration) zap.Field

WithIdleConnectionTimeout sets the idle connection timeout field.

func WithIndexFields

func WithIndexFields(fields []string) zap.Field

WithIndexFields sets the index fields.

func WithIndexOptions

func WithIndexOptions(indexOptions any) zap.Field

WithIndexOptions sets the index options field.

func WithInput

func WithInput(input any) zap.Field

WithInput sets the input field.

func WithKey

func WithKey(key string) zap.Field

WithKey sets the key field.

func WithKind

func WithKind(kind string) zap.Field

WithKind sets the kind field.

func WithLimit

func WithLimit(limit int) zap.Field

WithLimit sets the limit field.

func WithMaxIdleConnections

func WithMaxIdleConnections(maxIdleConnections int) zap.Field

WithMaxIdleConnections sets the max idle connections field.

func WithMaxOpenConnections

func WithMaxOpenConnections(maxOpenConnections int) zap.Field

WithMaxOpenConnections sets the max open connections field.

func WithMethod

func WithMethod(method string) zap.Field

WithMethod sets the method field.

func WithOffset

func WithOffset(offset int) zap.Field

WithOffset sets the offset field.

func WithOperationID

func WithOperationID(operationID string) zap.Field

WithOperationID sets the operation id field.

func WithPath

func WithPath(path string) zap.Field

WithPath sets the path field.

func WithProtocol

func WithProtocol(protocol string) zap.Field

WithProtocol sets the protocol field.

func WithQuery

func WithQuery(query string) zap.Field

WithQuery sets the query field.

func WithRemoteAddr

func WithRemoteAddr(remoteAddr string) zap.Field

WithRemoteAddr sets the remote address field.

func WithRequestID

func WithRequestID(requestID string) zap.Field

WithRequestID sets the request id field.

func WithScopes

func WithScopes(scopes []string) zap.Field

WithScopes sets the scopes field.

func WithSession

func WithSession(session any) zap.Field

WithSession sets the session field.

func WithSize

func WithSize(size int64) zap.Field

WithSize sets the size field.

func WithStatus

func WithStatus[S string | int](status S) zap.Field

WithStatus sets the status code field.

func WithTTL

func WithTTL(ttl time.Duration) zap.Field

WithTTL sets the ttl field.

func WithToken

func WithToken(token string) zap.Field

WithToken sets the ttl field.

func WithURL

func WithURL(url string) zap.Field

WithURL sets the url field.

func WithUserAgent

func WithUserAgent(userAgent string) zap.Field

WithUserAgent sets the user agent field.

func WithUserID

func WithUserID(userID string) zap.Field

WithUserID sets the user id field.

func WithUsername

func WithUsername(username string) zap.Field

WithUsername sets the username field.

func WithValue

func WithValue(value any) zap.Field

WithValue sets the value field.

Types

type Action

type Action int

Action represents the action that is being performed upon logging.

const (
	ActionHTTPRequestHandle Action = iota // handle an HTTP request

	ActionDBCollectionCreate // create a database collection
	ActionDBDocumentCreate   // create a document in a collection
	ActionDBDocumentDelete   // delete a document from a collection
	ActionDBDocumentRead     // read a document from a collection
	ActionDBDocumentUpdate   // update a document in a collection
	ActionDBIndexCreate      // create an index in the collection
	ActionDBInitialize       // initialize a database
	ActionDBQueryExecute     // execute a database query

	ActionAuthRequestAuthorize // authorize a request
	ActionAuthSessionCreate    // create a session
	ActionAuthStoreCreate      // create auth store
	ActionAuthTokenCreate      // create a token
	ActionAuthTokenIntrospect  // introspect a token
	ActionAuthTokenRevoke      // revoke a token
	ActionAuthUserAuthenticate // authenticate a user
	ActionRequestDeserialize   // deserialize a request
	ActionRequestTransform     // transform a request
	ActionRequesterValidate    // validate a requester

	ActionCertificateLoad // load a certificate
	ActionConfigLoad      // load a configuration
	ActionPrivateKeyLoad  // load a private key

	ActionHealthCheck // check the health of a component
)

func (Action) String

func (a Action) String() string

String returns the string representation of the action.

type Logger

type Logger interface {
	Sugar() *zap.SugaredLogger
	Named(s string) *zap.Logger
	WithOptions(opts ...zap.Option) *zap.Logger
	With(fields ...zap.Field) *zap.Logger
	Check(lvl zapcore.Level, msg string) *zapcore.CheckedEntry
	Log(lvl zapcore.Level, msg string, fields ...zap.Field)
	Debug(msg string, fields ...zap.Field)
	Info(msg string, fields ...zap.Field)
	Warn(msg string, fields ...zap.Field)
	Error(msg string, fields ...zap.Field)
	DPanic(msg string, fields ...zap.Field)
	Panic(msg string, fields ...zap.Field)
	Fatal(msg string, fields ...zap.Field)
	Sync() error
	Core() zapcore.Core
}

Logger defines the interface for the application logger.

func ConfigureLogger

func ConfigureLogger(level string) (Logger, error)

ConfigureLogger configures the logger then returns it.

func DefaultLogger

func DefaultLogger() Logger

DefaultLogger returns the global logger.

func FromContext

func FromContext(ctx context.Context) Logger

FromContext returns the logger from the context. If the logger is not found in the context, it returns the global logger.

type SimpleLogger

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

SimpleLogger is used to log the message where only arguments are available.

func NewSimpleLogger

func NewSimpleLogger(logger Logger) *SimpleLogger

NewSimpleLogger returns a new SimpleLogger.

func (*SimpleLogger) Debug

func (l *SimpleLogger) Debug(args ...interface{})

func (*SimpleLogger) Error

func (l *SimpleLogger) Error(args ...interface{})

func (*SimpleLogger) Fatal

func (l *SimpleLogger) Fatal(args ...interface{})

func (*SimpleLogger) Info

func (l *SimpleLogger) Info(args ...interface{})

func (*SimpleLogger) Warn

func (l *SimpleLogger) Warn(args ...interface{})

type ZapLogger

type ZapLogger = zap.Logger

ZapLogger is a type alias for zap.Logger.

Jump to

Keyboard shortcuts

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