logger

package
v0.17.2 Latest Latest
Warning

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

Go to latest
Published: May 23, 2022 License: AGPL-3.0 Imports: 35 Imported by: 5

Documentation

Index

Constants

View Source
const (
	EnvLoggerJSONEnable      = "CONSOLE_LOGGER_JSON_ENABLE"
	EnvLoggerAnonymousEnable = "CONSOLE_LOGGER_ANONYMOUS_ENABLE"
	EnvLoggerQuietEnable     = "CONSOLE_LOGGER_QUIET_ENABLE"

	EnvGlobalDeploymentID      = "CONSOLE_GLOBAL_DEPLOYMENT_ID"
	EnvLoggerWebhookEnable     = "CONSOLE_LOGGER_WEBHOOK_ENABLE"
	EnvLoggerWebhookEndpoint   = "CONSOLE_LOGGER_WEBHOOK_ENDPOINT"
	EnvLoggerWebhookAuthToken  = "CONSOLE_LOGGER_WEBHOOK_AUTH_TOKEN"
	EnvLoggerWebhookClientCert = "CONSOLE_LOGGER_WEBHOOK_CLIENT_CERT"
	EnvLoggerWebhookClientKey  = "CONSOLE_LOGGER_WEBHOOK_CLIENT_KEY"
	EnvLoggerWebhookQueueSize  = "CONSOLE_LOGGER_WEBHOOK_QUEUE_SIZE"

	EnvAuditWebhookEnable     = "CONSOLE_AUDIT_WEBHOOK_ENABLE"
	EnvAuditWebhookEndpoint   = "CONSOLE_AUDIT_WEBHOOK_ENDPOINT"
	EnvAuditWebhookAuthToken  = "CONSOLE_AUDIT_WEBHOOK_AUTH_TOKEN"
	EnvAuditWebhookClientCert = "CONSOLE_AUDIT_WEBHOOK_CLIENT_CERT"
	EnvAuditWebhookClientKey  = "CONSOLE_AUDIT_WEBHOOK_CLIENT_KEY"
	EnvAuditWebhookQueueSize  = "CONSOLE_AUDIT_WEBHOOK_QUEUE_SIZE"
)

Audit/Logger constants

View Source
const ConsoleLoggerTgt = "console+http"

ConsoleLoggerTgt is a stringified value to represent console logging

View Source
const TimeFormat string = "15:04:05 MST 01/02/2006"

TimeFormat - logging time format.

Variables

View Source
var BodyPlaceHolder = []byte("<BODY>")

BodyPlaceHolder returns a dummy body placeholder

View Source
var Disable = false

Disable disables all logging, false by default. (used for "go test")

View Source
var ErrCritical struct{}

ErrCritical is the value panic'd whenever CriticalIf is called.

View Source
var (
	GlobalContext context.Context
)

Functions

func AuditLog

func AuditLog(ctx context.Context, w *ResponseWriter, r *http.Request, reqClaims map[string]interface{}, filterKeys ...string)

AuditLog - logs audit logs to all audit targets.

func CriticalIf

func CriticalIf(ctx context.Context, err error, errKind ...interface{})

CriticalIf logs the provided errors on the console. It fails the current go-routine by causing a `panic(ErrCritical)`.

func EnableAnonymous

func EnableAnonymous()

EnableAnonymous - turns anonymous flag to avoid printing sensitive information.

func EnableJSON

func EnableJSON()

EnableJSON - outputs logs in json format.

func EnableQuiet

func EnableQuiet()

EnableQuiet - turns quiet option on.

func Error

func Error(msg string, data ...interface{})

Error :

func Fatal

func Fatal(err error, msg string, data ...interface{})

Fatal prints only fatal errors message with no stack trace it will be called for input validation failures

func FatalIf

func FatalIf(err error, msg string, data ...interface{})

FatalIf is similar to Fatal() but it ignores passed nil errors

func GetAuditEntry

func GetAuditEntry(ctx context.Context) *audit.Entry

GetAuditEntry returns Audit entry if set.

func GetGlobalDeploymentID

func GetGlobalDeploymentID() string

GetGlobalDeploymentID :

func Info

func Info(msg string, data ...interface{})

Info :

func Init

func Init(goPath, goRoot string)

Init sets the trimStrings to possible GOPATHs and GOROOT directories. Also append github.com/minio/minio This is done to clean up the filename, when stack trace is displayed when an errors happens.

func InitializeLogger

func InitializeLogger(ctx context.Context, transport *http.Transport) error

InitializeLogger :

func IsAnonymous

func IsAnonymous() bool

IsAnonymous - returns true if anonFlag is true

func IsJSON

func IsJSON() bool

IsJSON - returns true if jsonFlag is true

func IsQuiet

func IsQuiet() bool

IsQuiet - returns true if quietFlag is true

func LogAlwaysIf

func LogAlwaysIf(ctx context.Context, err error, errKind ...interface{})

LogAlwaysIf prints a detailed errors message during the execution of the server.

func LogIf

func LogIf(ctx context.Context, err error, errKind ...interface{})

LogIf prints a detailed errors message during the execution of the server

func LogOnceIf

func LogOnceIf(ctx context.Context, err error, id interface{}, errKind ...interface{})

LogOnceIf - Logs notification errors - once per errors. id is a unique identifier for related log messages, refer to cmd/notification.go on how it is used.

func NewHTTPTransportWithClientCerts

func NewHTTPTransportWithClientCerts(parentTransport *http.Transport, clientCert, clientKey string) *http.Transport

NewHTTPTransportWithClientCerts returns a new http configuration used while communicating with the cloud backends.

func RegisterError

func RegisterError(f func(string, error, bool) string)

RegisterError registers the specified rendering function. This latter will be called for a pretty rendering of fatal errors.

func SetAuditEntry

func SetAuditEntry(ctx context.Context, audit *audit.Entry) context.Context

SetAuditEntry sets Audit info in the context.

func SetReqInfo

func SetReqInfo(ctx context.Context, req *ReqInfo) context.Context

SetReqInfo sets ReqInfo in the context.

func UpdateAuditWebhookTargets

func UpdateAuditWebhookTargets(cfg Config) error

UpdateAuditWebhookTargets swaps audit webhook targets with newly loaded ones from the cfg

func UpdateSystemTargets

func UpdateSystemTargets(cfg Config) error

UpdateSystemTargets swaps targets with newly loaded ones from the cfg

Types

type Config

type Config struct {
	HTTP         map[string]http.Config `json:"http"`
	AuditWebhook map[string]http.Config `json:"audit"`
}

Config console and http logger targets

func LookupConfigForSubSys

func LookupConfigForSubSys(subSys string) (cfg Config, err error)

LookupConfigForSubSys - lookup logger config, override with ENVs if set, for the given sub-system

func NewConfig

func NewConfig() Config

NewConfig - initialize new logger config.

type KeyVal

type KeyVal struct {
	Key string
	Val interface{}
}

KeyVal - appended to ReqInfo.Tags

type Kind

type Kind string

Kind specifies the kind of errors log

const (
	// Minio errors
	Minio Kind = "CONSOLE"
	// Application errors
	Application Kind = "APPLICATION"
	// All errors
	All Kind = "ALL"
)

type Level

type Level int8

Level type

const (
	InformationLvl Level = iota + 1
	ErrorLvl
	FatalLvl
)

Enumerated level types

func (Level) String

func (level Level) String() string

type Logger

type Logger interface {
	// contains filtered or unexported methods
}

Logger interface describes the methods that need to be implemented to satisfy the interface requirements.

type ObjectVersion

type ObjectVersion struct {
	ObjectName string
	VersionID  string `json:"VersionId,omitempty"`
}

ObjectVersion object version key/versionId

type ReqInfo

type ReqInfo struct {
	RemoteHost   string          // Client Host/IP
	Host         string          // Node Host/IP
	UserAgent    string          // User Agent
	DeploymentID string          // x-minio-deployment-id
	RequestID    string          // x-amz-request-id
	SessionID    string          // custom session id
	API          string          // API name - GetObject PutObject NewMultipartUpload etc.
	BucketName   string          `json:",omitempty"` // Bucket name
	ObjectName   string          `json:",omitempty"` // Object name
	VersionID    string          `json:",omitempty"` // corresponding versionID for the object
	Objects      []ObjectVersion `json:",omitempty"` // Only set during MultiObject delete handler.
	AccessKey    string          // Access Key

	sync.RWMutex
	// contains filtered or unexported fields
}

ReqInfo stores the request info.

func GetReqInfo

func GetReqInfo(ctx context.Context) *ReqInfo

GetReqInfo returns ReqInfo if set.

func (*ReqInfo) GetTags

func (r *ReqInfo) GetTags() []KeyVal

GetTags - returns the user defined tags

func (*ReqInfo) GetTagsMap

func (r *ReqInfo) GetTagsMap() map[string]interface{}

GetTagsMap - returns the user defined tags in a map structure

type ResponseWriter

type ResponseWriter struct {
	http.ResponseWriter
	StatusCode int
	// Log body of 4xx or 5xx responses
	LogErrBody bool
	// Log body of all responses
	LogAllBody bool

	TimeToFirstByte time.Duration
	StartTime       time.Time
	// contains filtered or unexported fields
}

ResponseWriter - is a wrapper to trap the http response status code.

func NewResponseWriter

func NewResponseWriter(w http.ResponseWriter) *ResponseWriter

NewResponseWriter - returns a wrapped response writer to trap http status codes for auditing purposes.

func (*ResponseWriter) Body

func (lrw *ResponseWriter) Body() []byte

Body - Return response body.

func (*ResponseWriter) Flush

func (lrw *ResponseWriter) Flush()

Flush - Calls the underlying Flush.

func (*ResponseWriter) Size

func (lrw *ResponseWriter) Size() int

Size - reutrns the number of bytes written

func (*ResponseWriter) Write

func (lrw *ResponseWriter) Write(p []byte) (int, error)

func (*ResponseWriter) WriteHeader

func (lrw *ResponseWriter) WriteHeader(code int)

WriteHeader - writes http status code

type Target

type Target interface {
	String() string
	Endpoint() string
	Init() error
	Cancel()
	Send(entry interface{}, errKind string) error
	Type() types.TargetType
}

Target is the entity that we will receive a single log entry and Send it to the log target

e.g. Send the log to a http server

func AuditTargets

func AuditTargets() []Target

AuditTargets returns active audit targets. Returned slice may not be modified in any way.

func SystemTargets

func SystemTargets() []Target

SystemTargets returns active targets. Returned slice may not be modified in any way.

Directories

Path Synopsis
message
log
target

Jump to

Keyboard shortcuts

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