logger

package
v3.0.0+incompatible Latest Latest
Warning

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

Go to latest
Published: Nov 17, 2023 License: Apache-2.0 Imports: 22 Imported by: ? modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Index

Constants

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

TimeFormat - logging time format.

Variables

View Source
var (
	ColorBold = func() func(a ...interface{}) string {
		if isTerminal() {
			return color.New(color.Bold).SprintFunc()
		}
		return fmt.Sprint
	}()
	ColorFgRed = func() func(a ...interface{}) string {
		if isTerminal() {
			return color.New(color.FgRed).SprintFunc()
		}
		return fmt.Sprint
	}()
	ColorBgRed = func() func(format string, a ...interface{}) string {
		if isTerminal() {
			return color.New(color.BgRed).SprintfFunc()
		}
		return fmt.Sprintf
	}()
	ColorFgWhite = func() func(format string, a ...interface{}) string {
		if isTerminal() {
			return color.New(color.FgWhite).SprintfFunc()
		}
		return fmt.Sprintf
	}()
)

Global colors.

View Source
var AuditTargets = []Target{}

AuditTargets is the list of enabled audit loggers

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 Targets = []Target{}

Targets is the set of enabled loggers

Functions

func AddAuditTarget

func AddAuditTarget(t Target)

AddAuditTarget adds a new audit logger target to the list of enabled loggers

func AddTarget

func AddTarget(t Target)

AddTarget adds a new logger target to the list of enabled loggers

func AuditLog

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

AuditLog - logs audit logs to all audit targets.

func CriticalIf

func CriticalIf(ctx context.Context, err error)

CriticalIf logs the provided error 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 Fatal

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

Fatal prints only fatal error 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 error

func Info

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

Info :

func Init

func Init(goPath string, 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 error happens.

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)

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

func LogIf

func LogIf(ctx context.Context, err error)

LogIf prints a detailed error message during the execution of the server, if it is not an ignored error.

func LogOnceIf

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

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

func RegisterUIError

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

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

func SetReqInfo

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

SetReqInfo sets ReqInfo in the context.

func StartupMessage

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

StartupMessage :

Types

type Console

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

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

type KeyVal

type KeyVal struct {
	Key string
	Val string
}

KeyVal - appended to ReqInfo.Tags

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 ReqInfo

type ReqInfo struct {
	RemoteHost   string // Client Host/IP
	UserAgent    string // User Agent
	DeploymentID string // x-minio-deployment-id
	RequestID    string // x-amz-request-id
	API          string // API name - GetObject PutObject NewMultipartUpload etc.
	BucketName   string // Bucket name
	ObjectName   string // Object name

	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 NewReqInfo

func NewReqInfo(remoteHost, userAgent, deploymentID, requestID, api, bucket, object string) *ReqInfo

NewReqInfo :

func (*ReqInfo) AppendTags

func (r *ReqInfo) AppendTags(key string, val string) *ReqInfo

AppendTags - appends key/val to ReqInfo.tags

func (*ReqInfo) GetTags

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

GetTags - returns the user defined tags

func (*ReqInfo) SetTags

func (r *ReqInfo) SetTags(key string, val string) *ReqInfo

SetTags - sets key/val to ReqInfo.tags

type ResponseWriter

type ResponseWriter struct {
	http.ResponseWriter
	// 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 auditiing purposes.

func (*ResponseWriter) Flush

func (lrw *ResponseWriter) Flush()

Flush - Calls the underlying Flush.

func (*ResponseWriter) WriteHeader

func (lrw *ResponseWriter) WriteHeader(code int)

WriteHeader - writes http status code

type Target

type Target interface {
	Send(entry interface{}) error
}

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

Directories

Path Synopsis
message
log
target

Jump to

Keyboard shortcuts

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