logging

package
v0.0.0-...-c1b1270 Latest Latest
Warning

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

Go to latest
Published: Dec 13, 2024 License: Apache-2.0 Imports: 15 Imported by: 0

Documentation

Overview

Copyright 2018 the Velero contributors.

Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.

Copyright 2018 the Velero contributors.

Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.

Index

Constants

View Source
const (
	ListeningLevel   = logrus.ErrorLevel
	ListeningMessage = "merge-log-57847fd0-0c7c-48e3-b5f7-984b293d8376"
	LogSourceKey     = "log-source"
)

Variables

This section is empty.

Functions

func DefaultHooks

func DefaultHooks(merge bool) []logrus.Hook

DefaultHooks returns a slice of the default logrus hooks to be used by a logger.

func DefaultLogger

func DefaultLogger(level logrus.Level, format Format) *logrus.Logger

DefaultLogger returns a Logger with the default properties and hooks. The desired output format is passed as a LogFormat Enum.

func DefaultMergeLogger

func DefaultMergeLogger(level logrus.Level, format Format) *logrus.Logger

DefaultLogger returns a Logger with the default properties and hooks, and also a hook to support log merge. The desired output format is passed as a LogFormat Enum.

Types

type DualModeLogger

type DualModeLogger interface {
	logrus.FieldLogger
	// DoneForPersist stops outputting logs to the persist file
	DoneForPersist(log logrus.FieldLogger)
	// GetPersistFile moves the persist file pointer to beginning and returns it
	GetPersistFile() (*os.File, error)
	// Dispose closes the temp file pointer and removes the file
	Dispose(log logrus.FieldLogger)
}

DualModeLogger is a thread safe logger interface to write logs to dual targets, one of which is a persist file, so that the log could be further transferred.

func NewTempFileLogger

func NewTempFileLogger(logLevel logrus.Level, logFormat Format, hook *LogHook, fields logrus.Fields) (DualModeLogger, error)

NewTempFileLogger creates a DualModeLogger instance that writes logs to both Stdout and a file in the temp folder.

type ErrorLocationHook

type ErrorLocationHook struct{}

ErrorLocationHook is a logrus hook that attaches error location information to log entries if an error is being logged and it has stack-trace information (i.e. if it originates from or is wrapped by github.com/pkg/errors, or if it implements the errorLocationer interface, like errors returned from plugins typically do).

func (*ErrorLocationHook) Fire

func (h *ErrorLocationHook) Fire(entry *logrus.Entry) error

func (*ErrorLocationHook) Levels

func (h *ErrorLocationHook) Levels() []logrus.Level

type Format

type Format string

Format is a string representation of the desired output format for logs

const (
	FormatText Format = "text"
	FormatJSON Format = "json"
)

type FormatFlag

type FormatFlag struct {
	*flag.Enum
	// contains filtered or unexported fields
}

FormatFlag is a command-line flag for setting the logrus log format.

func NewFormatFlag

func NewFormatFlag() *FormatFlag

NewFormatFlag constructs a new log level flag.

func (*FormatFlag) Parse

func (f *FormatFlag) Parse() Format

Parse returns the flag's value as a Format.

type HcLogLevelHook

type HcLogLevelHook struct{}

HcLogLevelHook adds an hclog-compatible field ("@level") containing the log level. Note that if you use this, you SHOULD NOT use logrus.JSONFormatter's FieldMap to set the level key to "@level" because that will result in the hclog-compatible info written here being overwritten.

func (*HcLogLevelHook) Fire

func (h *HcLogLevelHook) Fire(entry *logrus.Entry) error

func (*HcLogLevelHook) Levels

func (h *HcLogLevelHook) Levels() []logrus.Level

type LevelFlag

type LevelFlag struct {
	*flag.Enum
	// contains filtered or unexported fields
}

LevelFlag is a command-line flag for setting the logrus log level.

func LogLevelFlag

func LogLevelFlag(defaultValue logrus.Level) *LevelFlag

LogLevelFlag constructs a new log level flag.

func (*LevelFlag) Parse

func (f *LevelFlag) Parse() logrus.Level

Parse returns the flag's value as a logrus.Level.

type LocationInfo

type LocationInfo struct {
	File     string
	Function string
	Line     int
}

LocationInfo specifies the location of a line of code.

func GetFrameLocationInfo

func GetFrameLocationInfo(frame errors.Frame) LocationInfo

GetFrameLocationInfo returns the location of a frame.

type LogHook

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

LogHook is a logrus hook that counts the number of log statements that have been written at each logrus level. It also maintains log entries at each logrus level in result structure.

func NewLogHook

func NewLogHook() *LogHook

NewLogHook returns a pointer to an initialized LogHook.

func (*LogHook) Fire

func (h *LogHook) Fire(entry *logrus.Entry) error

Fire executes the hook's logic.

func (*LogHook) GetCount

func (h *LogHook) GetCount(level logrus.Level) int

GetCount returns the number of log statements that have been written at the specific level provided.

func (*LogHook) GetEntries

func (h *LogHook) GetEntries(level logrus.Level) results.Result

GetEntries returns the log statements that have been written at the specific level provided.

func (*LogHook) Levels

func (h *LogHook) Levels() []logrus.Level

Levels returns the logrus levels that the hook should be fired for.

type LogLocationHook

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

LogLocationHook is a logrus hook that attaches location information to log entries, i.e. the file and line number of the logrus log call. This hook is designed for use in both the Velero server and Velero plugin implementations. When triggered within a plugin, a marker field will be set on the log entry indicating that the location came from a plugin. The Velero server instance will not overwrite location information if it sees this marker.

func (*LogLocationHook) Fire

func (h *LogLocationHook) Fire(entry *logrus.Entry) error

func (*LogLocationHook) Levels

func (h *LogLocationHook) Levels() []logrus.Level

func (*LogLocationHook) WithLoggerName

func (h *LogLocationHook) WithLoggerName(name string) *LogLocationHook

WithLoggerName gives the hook a name to use when setting the marker field on a log entry indicating the location has been recorded by a plugin. This should only be used when setting up a hook for a logger used in a plugin.

type MergeHook

type MergeHook struct {
}

MergeHook is used to redirect a batch of logs to another logger atomically. It hooks a log with ListeningMessage message, once the message is hit it replaces the logger's output to HookWriter so that HookWriter retrieves the logs from a file indicated by LogSourceKey field.

func (*MergeHook) Fire

func (h *MergeHook) Fire(entry *logrus.Entry) error

func (*MergeHook) Levels

func (h *MergeHook) Levels() []logrus.Level

Jump to

Keyboard shortcuts

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