log

package
v1.0.0-rc4 Latest Latest
Warning

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

Go to latest
Published: Oct 28, 2022 License: Apache-2.0 Imports: 8 Imported by: 0

Documentation

Index

Constants

View Source
const (
	FieldURI                       = "uri"
	FieldServiceName               = "service"
	FieldData                      = "data"
	FieldRequestBody               = "requestBody"
	FieldResponse                  = "response"
	FieldSize                      = "size"
	FieldMaxSize                   = "maxSize"
	FieldHTTPStatus                = "httpStatus"
	FieldParameter                 = "parameter"
	FieldTotal                     = "total"
	FieldSuffix                    = "suffix"
	FieldSuffixes                  = "suffixes"
	FieldOperationType             = "operationType"
	FieldOperation                 = "operation"
	FieldOperations                = "operations"
	FieldOperationID               = "operationID"
	FieldGenesisTime               = "genesisTime"
	FieldOperationGenesisTime      = "opGenesisTime"
	FieldSidetreeTxn               = "sidetreeTxn"
	FieldID                        = "id"
	FieldResolutionModel           = "resolutionModel"
	FieldVersion                   = "version"
	FieldNamespace                 = "namespace"
	FieldAnchorString              = "anchorString"
	FieldSource                    = "source"
	FieldTotalPending              = "totalPending"
	FieldTransactionTime           = "transactionTime"
	FieldTransactionNumber         = "transactionNumber"
	FieldCommitment                = "commitment"
	FieldRecoveryCommitment        = "recoveryCommitment"
	FieldUpdateCommitment          = "updateCommitment"
	FieldTotalCommitments          = "totalCommitments"
	FieldTotalOperations           = "totalOperations"
	FieldTotalCreateOperations     = "totalCreateOperations"
	FieldTotalUpdateOperations     = "totalUpdateOperations"
	FieldTotalRecoverOperations    = "totalRecoverOperations"
	FieldTotalDeactivateOperations = "totalDeactivateOperations"
	FieldDocument                  = "document"
	FieldDeactivated               = "deactivated"
	FieldVersionTime               = "versionTime"
	FieldPatch                     = "patch"
	FieldIsBatch                   = "isBatch"
	FieldContent                   = "content"
	FieldSources                   = "sources"
	FieldAlias                     = "alias"
)

Log Fields.

Log levels.

Variables

View Source
var DefaultEncoding = Console

DefaultEncoding sets the default logger encoding. It may be overridden at build time using the -ldflags option.

Functions

func CloseIteratorError

func CloseIteratorError(log *Log, err error)

CloseIteratorError outputs a 'close iterator' error log to the given logger.

func CloseResponseBodyError

func CloseResponseBodyError(log *Log, err error)

CloseResponseBodyError outputs a 'close response body' error log to the given logger.

func GetSpec

func GetSpec() string

GetSpec returns the log spec which specifies the log level of each individual module. The spec is in the following format:

module1=level1:module2=level2:module3=level3:defaultLevel

Example: module1=error:module2=debug:module3=warning:info

func InvalidParameterValue

func InvalidParameterValue(log *Log, param string, err error)

InvalidParameterValue outputs an 'invalid parameter' log to the given logger.

func ReadRequestBodyError

func ReadRequestBodyError(log *Log, err error)

ReadRequestBodyError outputs a 'read response body' error log to the given logger.

func SetDefaultLevel

func SetDefaultLevel(level Level)

SetDefaultLevel sets the default log level.

func SetLevel

func SetLevel(module string, level Level)

SetLevel sets the log level for given module and level.

func SetSpec

func SetSpec(spec string) error

SetSpec sets the log levels for individual modules as well as the default log level. The format of the spec is as follows:

module1=level1:module2=level2:module3=level3:defaultLevel

Valid log levels are: critical, error, warning, info, debug

Example:

module1=error:module2=debug:module3=warning:info

func WithAlias

func WithAlias(value string) zap.Field

WithAlias sets the alias field.

func WithAnchorString

func WithAnchorString(value string) zap.Field

WithAnchorString sets the anchor-string field.

func WithCommitment

func WithCommitment(value string) zap.Field

WithCommitment sets the commitment field.

func WithContent

func WithContent(value []byte) zap.Field

WithContent sets the content field.

func WithData

func WithData(value []byte) zap.Field

WithData sets the data field.

func WithDeactivated

func WithDeactivated(value bool) zap.Field

WithDeactivated sets the deactivated field.

func WithDocument

func WithDocument(value map[string]interface{}) zap.Field

WithDocument sets the document field.

func WithError

func WithError(err error) zap.Field

WithError sets the error field.

func WithGenesisTime

func WithGenesisTime(value uint64) zap.Field

WithGenesisTime sets the genesis-time field.

func WithHTTPStatus

func WithHTTPStatus(value int) zap.Field

WithHTTPStatus sets the http-status field.

func WithID

func WithID(value string) zap.Field

WithID sets the id field.

func WithIsBatch

func WithIsBatch(value bool) zap.Field

WithIsBatch sets the is-batch field.

func WithMaxSize

func WithMaxSize(value int) zap.Field

WithMaxSize sets the max-size field.

func WithNamespace

func WithNamespace(value string) zap.Field

WithNamespace sets the namespace field.

func WithOperation

func WithOperation(value interface{}) zap.Field

WithOperation sets the operation field.

func WithOperationGenesisTime

func WithOperationGenesisTime(value uint64) zap.Field

WithOperationGenesisTime sets the op-genesis-time field.

func WithOperationID

func WithOperationID(value string) zap.Field

WithOperationID sets the operation-id field.

func WithOperationType

func WithOperationType(value string) zap.Field

WithOperationType sets the operation-type field.

func WithOperations

func WithOperations(value interface{}) zap.Field

WithOperations sets the operation field.

func WithParameter

func WithParameter(value string) zap.Field

WithParameter sets the parameter field.

func WithPatch

func WithPatch(value interface{}) zap.Field

WithPatch sets the patch field.

func WithRecoveryCommitment

func WithRecoveryCommitment(value string) zap.Field

WithRecoveryCommitment sets the recovery-commitment field.

func WithRequestBody

func WithRequestBody(value []byte) zap.Field

WithRequestBody sets the request-body field.

func WithResolutionModel

func WithResolutionModel(value interface{}) zap.Field

WithResolutionModel sets the resolution-model field.

func WithResponse

func WithResponse(value []byte) zap.Field

WithResponse sets the response field.

func WithServiceName

func WithServiceName(value string) zap.Field

WithServiceName sets the service field.

func WithSidetreeTxn

func WithSidetreeTxn(value interface{}) zap.Field

WithSidetreeTxn sets the sidetree-txn field.

func WithSize

func WithSize(value int) zap.Field

WithSize sets the size field.

func WithSource

func WithSource(value string) zap.Field

WithSource sets the source field.

func WithSources

func WithSources(value ...string) zap.Field

WithSources sets the sources field.

func WithSuffix

func WithSuffix(value string) zap.Field

WithSuffix sets the suffix field.

func WithSuffixes

func WithSuffixes(value ...string) zap.Field

WithSuffixes sets the suffixes field.

func WithTotal

func WithTotal(value int) zap.Field

WithTotal sets the total field.

func WithTotalCommitments

func WithTotalCommitments(value int) zap.Field

WithTotalCommitments sets the total-commitments field.

func WithTotalCreateOperations

func WithTotalCreateOperations(value int) zap.Field

WithTotalCreateOperations sets the total-create-operations field.

func WithTotalDeactivateOperations

func WithTotalDeactivateOperations(value int) zap.Field

WithTotalDeactivateOperations sets the total-deactivate-operations field.

func WithTotalOperations

func WithTotalOperations(value int) zap.Field

WithTotalOperations sets the total-operations field.

func WithTotalPending

func WithTotalPending(value uint) zap.Field

WithTotalPending sets the total-pending field.

func WithTotalRecoverOperations

func WithTotalRecoverOperations(value int) zap.Field

WithTotalRecoverOperations sets the total-recover-operations field.

func WithTotalUpdateOperations

func WithTotalUpdateOperations(value int) zap.Field

WithTotalUpdateOperations sets the total-update-operations field.

func WithTransactionNumber

func WithTransactionNumber(value uint64) zap.Field

WithTransactionNumber sets the transaction-number field.

func WithTransactionTime

func WithTransactionTime(value uint64) zap.Field

WithTransactionTime sets the transaction-time field.

func WithURIString

func WithURIString(value string) zap.Field

WithURIString sets the uri field.

func WithUpdateCommitment

func WithUpdateCommitment(value string) zap.Field

WithUpdateCommitment sets the update-commitment field.

func WithVersion

func WithVersion(value string) zap.Field

WithVersion sets the version field.

func WithVersionTime

func WithVersionTime(value string) zap.Field

WithVersionTime sets the version-time field.

func WriteResponseBodyError

func WriteResponseBodyError(log *Log, err error)

WriteResponseBodyError outputs a 'write response body' error log to the given logger.

func WroteResponse

func WroteResponse(log *Log, data []byte)

WroteResponse outputs a 'wrote response' log to the given logger.

Types

type Encoding

type Encoding = string

Encoding defines the log encoding.

const (
	Console Encoding = "console"
	JSON    Encoding = "json"
)

Log encodings.

type Level

type Level int

Level defines a log level for logging messages.

func GetLevel

func GetLevel(module string) Level

GetLevel returns the log level for the given module.

func ParseLevel

func ParseLevel(level string) (Level, error)

ParseLevel returns the level from the given string.

func (Level) String

func (l Level) String() string

String returns string representation of given log level.

type Log

type Log struct {
	*zap.Logger
	// contains filtered or unexported fields
}

Log uses the Zap Logger to log messages in a structured way.

func New

func New(module string, opts ...Option) *Log

New creates a structured Logger implementation based on given module name.

func (*Log) IsEnabled

func (l *Log) IsEnabled(level Level) bool

IsEnabled returns true if given log level is enabled.

type ObjectMarshaller

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

ObjectMarshaller uses reflection to marshal an object's fields.

func NewObjectMarshaller

func NewObjectMarshaller(key string, obj interface{}) *ObjectMarshaller

NewObjectMarshaller returns a new ObjectMarshaller.

func (*ObjectMarshaller) MarshalLogObject

func (m *ObjectMarshaller) MarshalLogObject(e zapcore.ObjectEncoder) error

MarshalLogObject marshals the object's fields.

type Option

type Option func(o *options)

Option is a logger option.

func WithEncoding

func WithEncoding(encoding Encoding) Option

WithEncoding sets the output encoding (console or json).

func WithFields

func WithFields(fields ...zap.Field) Option

WithFields sets the fields that will be output with every log.

func WithStdErr

func WithStdErr(stdErr zapcore.WriteSyncer) Option

WithStdErr sets the output for logs of type ERROR, PANIC, and FATAL.

func WithStdOut

func WithStdOut(stdOut zapcore.WriteSyncer) Option

WithStdOut sets the output for logs of type DEBUG, INFO, and WARN.

type StringArrayMarshaller

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

StringArrayMarshaller marshals an array of strings into a log field.

func NewStringArrayMarshaller

func NewStringArrayMarshaller(values []string) *StringArrayMarshaller

NewStringArrayMarshaller returns a new StringArrayMarshaller.

func (*StringArrayMarshaller) MarshalLogArray

func (m *StringArrayMarshaller) MarshalLogArray(e zapcore.ArrayEncoder) error

MarshalLogArray marshals the array.

Jump to

Keyboard shortcuts

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