log

package module
v0.9.11 Latest Latest
Warning

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

Go to latest
Published: Feb 25, 2021 License: MIT Imports: 11 Imported by: 32

README

ContainerSSH - Launch Containers on Demand

ContainerSSH Logging Library

Go Report Card LGTM Alerts

This library provides internal logging for ContainerSSH. Its functionality is very similar to how syslog is structured.

⚠⚠⚠ Warning: This is a developer documentation. ⚠⚠⚠
The user documentation for ContainerSSH is located at containerssh.io.

Basic concept

This is not the logger you would expect from the go-log library. This library combines the Go errors and the log messages into one. In other words, the Message object can be used both as an error and a log message.

The main Message structure has several properties: a unique error code, a user-safe error message and a detailed error message for the system administrator. Additionally, it also may contain several key-value pairs called labels to convey additional information.

Creating a message

If you want to create a message you can use the following methods:

log.UserMessage()

The log.UserMessage method creates a new Message with a user-facing message structure as follows:

msg := log.UserMessage(
    "E_SOME_ERROR_CODE",
    "Dear user, an internal error happened.",
    "Details about the error (%s)",
    "Some string that will end up instead of %s."
)
  • The first parameter is an error code that is unique so people can identify the error. This error code should be documented so users can find it easily.
  • The second parameter is a string printed to the user. It does not support formatting characters.
  • The third parameter is a string that can be logged for the system administrator. It can contain fmt.Sprintf-style formatting characters.
  • All subsequent parameters are used to replace the formatting characters.

log.NewMessage()

The log.NewMessage() method is a simplified version of log.UserMessage() without the user-facing message. The user-facing message will always be Internal Error.. The method signature is the following:

msg := log.NewMessage(
    "E_SOME_ERROR_CODE",
    "Details about the error (%s)",
    "Some string that will end up instead of %s."
)

log.WrapUser()

The log.WrapUser() method can be used to create a wrapped error with a user-facing message. It automatically appends the original error message to the administrator-facing message. The function signature is the following:

msg := log.WrapUser(
    originalErr,
    "E_SOME_CODE",
    "Dear user, some error happened."
    "Dear admin, an error happened. %s" + 
        "The error message will be appended to this message."
    "This string will appear instead of %s in the admin-message."
)

log.Wrap()

Like the log.WrapUser() method the log.Wrap() will skip the user-visible error message and otherwise be identical to log.Wrap().

msg := log.Wrap(
    originalErr,
    "E_SOME_CODE",
    "Dear admin, an error happened. %s" + 
        "The error message will be appended to this message."
    "This string will appear instead of %s in the admin-message."
)

Adding labels to messages

Labels are useful for recording extra information with messages that can be indexed by the logging system. These labels may or may not be recorded by the logging backend. For example, the syslog output doesn't support recording labels due to size constraints. In other words, the message itself should contain enough information for an administrator to interpret the error.

You can add labels to messages like this:

msg.Label("labelName", "labelValue")

Hint: Label() calls can be chained.

Using messages

As mentioned before, the Message interface implements the error interface, so these messages can simply be returned like a normal error would.

Logging

This library also provides a Logger interface that can log all kinds of messages and errors, including the Message interface. It provides the following methods for logging:

  • logger.Debug(message ...interface{})
  • logger.Info(message ...interface{})
  • logger.Notice(message ...interface{})
  • logger.Warning(message ...interface{})
  • logger.Error(message ...interface{})
  • logger.Critical(message ...interface{})
  • logger.Alert(message ...interface{})
  • logger.Emergency(message ...interface{})

You are encouraged to pass a Message implementation to it.

We also provide the following compatibility methods which log at the info level.

  • logger.Log(v ...interface{})
  • logger.Logf(format string, v ...interface{})

We provide a method to create a child logger that has a different minimum log level. Messages below this level will be discarded:

newLogger := logger.WithLevel(log.LevelInfo)

We can also create a new logger copy with default labels added:

newLogger := logger.WithLabel("label name", "label value")

Finally, the logger also supports calling the Rotate() and Close() methods. Rotate() instructs the output to close all handles and reopen them to facilitate rotating logs. Close() permanently closes the writer.

Creating a logger

The Logger interface is intended for generic implementations. The default implementation can be created as follows:

logger, err := log.NewLogger(config)

Alternatively, you can also use the log.MustNewLogger method to skip having to deal with the error. (It will panic if an error happens.)

If you need a factory you can use the log.LoggerFactory interface and the log.NewLoggerFactory to create a factory you can pass around. The Make(config) method will make a new logger when needed.

Configuration

The configuration structure for the default logger implementation is contained in the log.Config structure.

Configuring the output format

The most important configuration is where your logs will end up:

log.Config{
    Output: log.OutputStdout,
}

The following options are possible:

  • log.OutputStdout logs to the standard output or any other io.Writer
  • log.OutputFile logs to a file on the local filesystem.
  • log.OutputSyslog logs to a syslog server using a UNIX or UDP socket.

Logging to stdout

If you set the Output option to log.OutputStdout the output will be written to the standard output in the format specified below (see "Changing the log format"). The destination can be overridden:

log.Config {
    Output: log.OutputStdout,
    Stdout: someOtherWriter,
}

Logging to a file

The file logger is configured as follows:

log.Config {
    Output: log.OutputFile,
    File: "/var/log/containerssh.log",
}

You can call the Rotate() method on the logger to close and reopen the file. This allows for log rotation.

Logging to syslog

The syslog logger writes to a syslog daemon. Typically, this is located on the /dev/log UNIX socket, but sending logs over UDP is also supported. TCP, encryption, and other advanced Syslog features are not supported, so adding a Syslog daemon on the local node is strongly recommended.

The configuration is the following:

log.Config{
    Output: log.OutputSyslog,
    Facility: log.FacilityStringAuth, // See facilities list below
    Tag: "ProgramName", // Add program name here
    Pid: false, // Change to true to add the PID to the Tag
    Hostname: "" // Change to override host name 
}

The following facilities are supported:

  • log.FacilityStringKern
  • log.FacilityStringUser
  • log.FacilityStringMail
  • log.FacilityStringDaemon
  • log.FacilityStringAuth
  • log.FacilityStringSyslog
  • log.FacilityStringLPR
  • log.FacilityStringNews
  • log.FacilityStringUUCP
  • log.FacilityStringCron
  • log.FacilityStringAuthPriv
  • log.FacilityStringFTP
  • log.FacilityStringNTP
  • log.FacilityStringLogAudit
  • log.FacilityStringLogAlert
  • log.FacilityStringClock
  • log.FacilityStringLocal0
  • log.FacilityStringLocal1
  • log.FacilityStringLocal2
  • log.FacilityStringLocal3
  • log.FacilityStringLocal4
  • log.FacilityStringLocal5
  • log.FacilityStringLocal6
  • log.FacilityStringLocal7

Changing the log format

We currently support two log formats: text and ljson. The format is applied for the stdout and file outputs and can be configured as follows:

log.Config {
    Format: log.FormatText|log.FormatLJSON,
}
The text format

The text format is structured as follows:

TIMESTAMP[TAB]LEVEL[TAB]MODULE[TAB]MESSAGE[NEWLINE]
  • TIMESTAMP is the timestamp of the message in RFC3339 format.
  • LEVEL is the level of the message (debug, info, notice, warning, error, critical, alert, emergency)
  • MODULE is the name of the module logged. May be empty.
  • MESSAGE is the text message or structured data logged.

This format is recommended for human consumption only.

The ljson format

This format logs in a newline-delimited JSON format. Each message has the following format:

{"timestamp": "TIMESTAMP", "level": "LEVEL", "module": "MODULE", "message": "MESSAGE", "details": "DETAILS"}
  • TIMESTAMP is the timestamp of the message in RFC3339 format.
  • LEVEL is the level of the message (debug, info, notice, warning, error, critical, alert, emergency)
  • MODULE is the name of the module logged. May be absent if not sent.
  • MESSAGE is the text message. May be absent if not set.
  • DETAILS is a structured log message. May be absent if not set.

Creating a logger for testing

You can create a logger for testing purposes that logs using the t *testing.T log facility:

logger := log.NewTestLogger(t)

Documentation

Index

Constants

View Source
const ELogFileOpenFailed = "E_LOG_FILE_OPEN_FAILED"

ELogFileOpenFailed indicates that the log file could not be opened.

View Source
const ELogRotateFailed = "E_LOG_ROTATE_FAILED"

ELogRotateFailed is an error that happens when a log rotation is desired but failed for some reason.

View Source
const ELogWriteFailed = "E_LOG_WRITE_FAILED"

ELogWriteFailed is an error that occurs when writing the log destination failed. (e.g. the disk is full)

View Source
const EUnknownError = "E_UNKNOWN_ERROR"

EUnknownError is a non-conformant error.

Variables

This section is empty.

Functions

func NewGoLogWriter added in v0.9.1

func NewGoLogWriter(backendLogger Logger) io.Writer

NewGoLogWriter creates an adapter for the go logger that writes using the Log method of the logger.

Types

type Config added in v0.9.3

type Config struct {
	// Level describes the minimum level to log at
	Level Level `json:"level" yaml:"level" default:"5"`

	// Format describes the log message format
	Format Format `json:"format" yaml:"format" default:"ljson"`

	// Destination is the target to write the log messages to.
	Destination Destination `json:"destination" yaml:"destination" default:"stdout"`

	// File is the log file to write to if Destination is set to "file".
	File string `json:"file" yaml:"file" default:"/var/log/containerssh/containerssh.log"`

	// Syslog configures the syslog destination.
	Syslog SyslogConfig `json:"syslog" yaml:"syslog"`

	// T is the Go test for logging purposes.
	T *testing.T

	// Stdout is the standard output used by the DestinationStdout destination.
	Stdout io.Writer
}

Config describes the logging settings.

func (*Config) Validate added in v0.9.8

func (c *Config) Validate() error

Validate validates the log configuration.

type Destination added in v0.9.11

type Destination string

Destination is the output to write to.

const (
	// DestinationStdout is writing log messages to the standard output.
	DestinationStdout Destination = "stdout"
	// DestinationFile is writing the log messages to a file.
	DestinationFile Destination = "file"
	// DestinationSyslog is writing log messages to syslog.
	DestinationSyslog Destination = "syslog"
	// DestinationTest writes the logs to the *testing.T facility.
	DestinationTest Destination = "test"
)

func (Destination) Validate added in v0.9.11

func (o Destination) Validate() error

Validate validates the output target.

type Facility added in v0.9.10

type Facility int

Priority

const (
	// FacilityKern are kernel messages.
	FacilityKern Facility = 0
	// FacilityUser are user level messages.
	FacilityUser Facility = 1
	// FacilityMail are user mail log messages.
	FacilityMail Facility = 2
	// FacilityDaemon are daemon messages.
	FacilityDaemon Facility = 3
	// FacilityAuth are authentication messages.
	FacilityAuth Facility = 4
	// FacilitySyslog are syslog-specific messages.
	FacilitySyslog Facility = 5
	// FacilityLPR are printer messages.
	FacilityLPR Facility = 6
	// FacilityNews are news messages.
	FacilityNews Facility = 7
	// FacilityUUCP are UUCP subsystem messages.
	FacilityUUCP Facility = 8
	// FacilityCron are clock daemon messages.
	FacilityCron Facility = 9
	// FacilityAuthPriv are security/authorization messages.
	FacilityAuthPriv Facility = 10
	// FacilityFTP are FTP daemon messages.
	FacilityFTP Facility = 11
	// FacilityNTP are network time daemon messages.
	FacilityNTP Facility = 12
	// FacilityLogAudit are log audit messages.
	FacilityLogAudit Facility = 13
	// FacilityLogAlert are log alert messages.
	FacilityLogAlert Facility = 14
	// FacilityClock are clock daemon messages.
	FacilityClock Facility = 15

	// FacilityLocal0 are locally administered messages.
	FacilityLocal0 Facility = 16
	// FacilityLocal1 are locally administered messages.
	FacilityLocal1 Facility = 17
	// FacilityLocal2 are locally administered messages.
	FacilityLocal2 Facility = 18
	// FacilityLocal3 are locally administered messages.
	FacilityLocal3 Facility = 19
	// FacilityLocal4 are locally administered messages.
	FacilityLocal4 Facility = 20
	// FacilityLocal5 are locally administered messages.
	FacilityLocal5 Facility = 21
	// FacilityLocal6 are locally administered messages.
	FacilityLocal6 Facility = 22
	// FacilityLocal7 are locally administered messages.
	FacilityLocal7 Facility = 23
)

func (Facility) MustName added in v0.9.10

func (f Facility) MustName() FacilityString

MustName is identical to Name but panics if the facility is invalid.

func (Facility) Name added in v0.9.10

func (f Facility) Name() (FacilityString, error)

Name returns the facility name.

func (Facility) Validate added in v0.9.10

func (f Facility) Validate() error

Validate checks if the facility is valid.

type FacilityString added in v0.9.10

type FacilityString string

FacilityString are facility names.

const (
	// FacilityStringKern are kernel messages.
	FacilityStringKern FacilityString = "kern"
	// FacilityStringUser are user level messages.
	FacilityStringUser FacilityString = "user"
	// FacilityStringMail are user mail log messages.
	FacilityStringMail FacilityString = "mail"
	// FacilityStringDaemon are daemon messages.
	FacilityStringDaemon FacilityString = "daemon"
	// FacilityStringAuth are authentication messages.
	FacilityStringAuth FacilityString = "auth"
	// FacilityStringSyslog are syslog-specific messages.
	FacilityStringSyslog FacilityString = "syslog"
	// FacilityStringLPR are printer messages.
	FacilityStringLPR FacilityString = "lpr"
	// FacilityStringNews are news messages.
	FacilityStringNews FacilityString = "news"
	// FacilityStringUUCP are UUCP subsystem messages.
	FacilityStringUUCP FacilityString = "uucp"
	// FacilityStringCron are clock daemon messages.
	FacilityStringCron FacilityString = "cron"
	// FacilityStringAuthPriv are security/authorization messages.
	FacilityStringAuthPriv FacilityString = "authpriv"
	// FacilityStringFTP are FTP daemon messages.
	FacilityStringFTP FacilityString = "ftp"
	// FacilityStringNTP are network time daemon messages.
	FacilityStringNTP FacilityString = "ntp"
	// FacilityStringLogAudit are log audit messages.
	FacilityStringLogAudit FacilityString = "logaudit"
	// FacilityStringLogAlert are log alert messages.
	FacilityStringLogAlert FacilityString = "logalert"
	// FacilityStringClock are clock daemon messages.
	FacilityStringClock FacilityString = "clock"

	// FacilityStringLocal0 are locally administered messages.
	FacilityStringLocal0 FacilityString = "local0"
	// FacilityStringLocal1 are locally administered messages.
	FacilityStringLocal1 FacilityString = "local1"
	// FacilityStringLocal2 are locally administered messages.
	FacilityStringLocal2 FacilityString = "local2"
	// FacilityStringLocal3 are locally administered messages.
	FacilityStringLocal3 FacilityString = "local3"
	// FacilityStringLocal4 are locally administered messages.
	FacilityStringLocal4 FacilityString = "local4"
	// FacilityStringLocal5 are locally administered messages.
	FacilityStringLocal5 FacilityString = "local5"
	// FacilityStringLocal6 are locally administered messages.
	FacilityStringLocal6 FacilityString = "local6"
	// FacilityStringLocal7 are locally administered messages.
	FacilityStringLocal7 FacilityString = "local7"
)

func (FacilityString) MustNumber added in v0.9.10

func (s FacilityString) MustNumber() Facility

MustNumber is identical to Number but panics instead of returning errors

func (FacilityString) Number added in v0.9.10

func (s FacilityString) Number() (Facility, error)

Number returns the facility number.

func (FacilityString) Validate added in v0.9.10

func (s FacilityString) Validate() error

Validate validates the facility string.

type Format added in v0.9.3

type Format string

Format is the logging format to use.

const (
	// FormatLJSON is a newline-delimited JSON log format.
	FormatLJSON Format = "ljson"
	// FormatText prints the logs as plain text.
	FormatText Format = "text"
)

func (Format) Validate added in v0.9.3

func (format Format) Validate() error

Validate returns an error if the format is invalid.

type LabelName added in v0.9.10

type LabelName string

LabelName is a name for a Message label. Can only contain A-Z, a-z, 0-9, -, _.

type LabelValue added in v0.9.10

type LabelValue interface{}

LabelValue is a string, int, bool, or float.

type Labels added in v0.9.10

type Labels map[LabelName]LabelValue

Labels is a map linking

type Level

type Level int8

Level syslog-style log level identifiers

const (
	LevelDebug     Level = 7
	LevelInfo      Level = 6
	LevelNotice    Level = 5
	LevelWarning   Level = 4
	LevelError     Level = 3
	LevelCritical  Level = 2
	LevelAlert     Level = 1
	LevelEmergency Level = 0
)

Supported values for Level

func (Level) MarshalJSON added in v0.9.6

func (level Level) MarshalJSON() ([]byte, error)

MarshalJSON marshals a level number to a JSON string

func (Level) MarshalYAML added in v0.9.6

func (level Level) MarshalYAML() (interface{}, error)

MarshalYAML creates a YAML text representation from a numeric level

func (Level) MustName added in v0.9.10

func (level Level) MustName() LevelString

MustName Convert the int level to the string representation and panics if the name is not valid.

func (*Level) Name added in v0.9.10

func (level *Level) Name() (LevelString, error)

Name Convert the int level to the string representation

func (Level) String

func (level Level) String() string

String Convert the int level to the string representation. Panics if the level is not valid.

func (*Level) UnmarshalJSON added in v0.9.5

func (level *Level) UnmarshalJSON(data []byte) error

UnmarshalJSON decodes a JSON level string to a level type.

func (*Level) UnmarshalYAML added in v0.9.5

func (level *Level) UnmarshalYAML(unmarshal func(interface{}) error) error

UnmarshalYAML decodes a YAML level string to a level type.

func (Level) Validate

func (level Level) Validate() error

Validate if the log level has a valid value

type LevelString

type LevelString string

LevelString is a type for supported log level strings

const (
	LevelDebugString     LevelString = "debug"
	LevelInfoString      LevelString = "info"
	LevelNoticeString    LevelString = "notice"
	LevelWarningString   LevelString = "warning"
	LevelErrorString     LevelString = "error"
	LevelCriticalString  LevelString = "crit"
	LevelAlertString     LevelString = "alert"
	LevelEmergencyString LevelString = "emerg"
)

List of valid string values for log levels

func (LevelString) ToLevel

func (level LevelString) ToLevel() (Level, error)

ToLevel convert the string level to the int representation

type Logger

type Logger interface {
	// WithLevel returns a copy of the logger for a specified log level. Panics if the log level provided is invalid.
	WithLevel(level Level) Logger
	// WithLabel returns a logger with an added label (e.g. username, IP, etc.) Panics if the label name is empty.
	WithLabel(labelName LabelName, labelValue LabelValue) Logger

	// Debug logs a message at the debug level.
	Debug(message ...interface{})
	// Debugf logs a message at the debug level with a formatting string.
	// Deprecated: use Debug with a Message instead.
	Debugf(format string, args ...interface{})

	// Info logs a message at the info level.
	Info(message ...interface{})
	// Infof logs a message at the info level with a formatting string.
	// Deprecated: use Info with a Message instead.
	Infof(format string, args ...interface{})

	// Notice logs a message at the notice level.
	Notice(message ...interface{})
	// Noticef logs a message at the notice level with a formatting string.
	// Deprecated: use Notice with a Message instead.
	Noticef(format string, args ...interface{})

	// Warning logs a message at the warning level.
	Warning(message ...interface{})
	// Warningf logs a message at the warning level with a formatting string.
	// Deprecated: use Warning with a Message instead.
	Warningf(format string, args ...interface{})

	// Error logs a message at the error level.
	Error(message ...interface{})
	// Errorf logs a message at the error level with a formatting string.
	// Deprecated: use Error with a Message instead.
	Errorf(format string, args ...interface{})

	// Critical logs a message at the critical level.
	Critical(message ...interface{})
	// Criticalf logs a message at the critical level with a formatting string.
	// Deprecated: use Critical with a Message instead.
	Criticalf(format string, args ...interface{})

	// Alert logs a message at the alert level.
	Alert(message ...interface{})
	// Alertf logs a message at the alert level with a formatting string
	// Deprecated: use Alert with a Message instead.
	Alertf(format string, args ...interface{})

	// Emergency logs a message at the emergency level.
	Emergency(message ...interface{})
	// Emergencyf logs a message at the emergency level with a formatting string.
	// Deprecated: use Emergency with a Message instead.
	Emergencyf(format string, message ...interface{})

	// Log logs a number of objects or strings to the log.
	Log(v ...interface{})
	// Logf formats a message and logs it.
	Logf(format string, v ...interface{})

	// Rotate triggers the logging backend to close all connections and reopen them to allow for rotating log files.
	Rotate() error
	// Close closes the logging backend.
	Close() error
}

Logger The logger interface provides logging facilities on various levels.

func MustNewLogger added in v0.9.10

func MustNewLogger(
	config Config,
) Logger

MustNewLogger is identical to NewLogger, except that it panics instead of returning an error

func NewLogger added in v0.9.10

func NewLogger(config Config) (Logger, error)

NewLogger creates a standard logger pipeline.

- config is the configuration structure for the logger

goland:noinspection GoUnusedExportedFunction

func NewTestLogger added in v0.9.10

func NewTestLogger(t *testing.T) Logger

NewTestLogger creates a logger for testing purposes.

type LoggerFactory

type LoggerFactory interface {
	// Make creates a new logger with the specified configuration and module.
	//
	// - config is the configuration structure.
	//
	// Return:
	//
	// - Logger is the logger created.
	// - error is returned if the configuration was invalid.
	Make(config Config) (Logger, error)

	// MustMake is identical to Make but panics if an error happens
	MustMake(config Config) Logger
}

LoggerFactory is a factory to create a logger on demand

func NewLoggerFactory added in v0.9.10

func NewLoggerFactory() LoggerFactory

NewLoggerFactory create a pipeline logger factory

type Message added in v0.9.10

type Message interface {
	// NewMessage is the Go-compatible error message.
	Error() string
	// String returns the string representation of this message.
	String() string

	// Code is a unique code identifying log messages.
	Code() string
	// UserMessage is a message that is safe to print/send to the end user.
	UserMessage() string
	// Explanation is the text explanation for the system administrator.
	Explanation() string
	// Labels are a set of extra labels for the message containing information.
	Labels() Labels
	// Label adds a label to the message.
	Label(name LabelName, value LabelValue) Message
}

Message is a message structure for error reporting in ContainerSSH. The actual implementations may differ, but we provide the UserMessage method to construct a message that conforms to this interface.

func NewMessage added in v0.9.10

func NewMessage(Code string, Explanation string, Args ...interface{}) Message

NewMessage creates an internal error with only the explanation for the administrator inserted.

  • Code is an error code allowing an administrator to identify the error that happened.
  • Explanation is the explanation string to the system administrator. This is an fmt.Sprintf-compatible string
  • Args are the arguments to Explanation to create a formatted message. It is recommended that these arguments also be added as labels to allow system administrators to index the error properly.

func UserMessage added in v0.9.10

func UserMessage(Code string, UserMessage string, Explanation string, Args ...interface{}) Message

UserMessage constructs a Message.

  • Code is an error code allowing an administrator to identify the error that happened.
  • UserMessage is the message that can be printed to the user if needed.
  • Explanation is the explanation string to the system administrator. This is an fmt.Sprintf-compatible string
  • Args are the arguments to Explanation to create a formatted message. It is recommended that these arguments also be added as labels to allow system administrators to index the error properly.

type SyslogConfig added in v0.9.10

type SyslogConfig struct {
	// Destination is the socket to send logs to. Can be a local path to unix sockets as well as UDP destinations.
	Destination string `json:"destination" yaml:"destination" default:"/dev/log"`
	// Facility logs to the specified syslog facility.
	Facility FacilityString `json:"facility" yaml:"facility" default:"auth"`
	// Tag is the syslog tag to log with.
	Tag string `json:"tag" yaml:"tag" default:"ContainerSSH"`
	// Pid is a setting to append the current process ID to the tag.
	Pid bool `json:"pid" yaml:"pid" default:"false"`
	// contains filtered or unexported fields
}

SyslogConfig is the configuration for syslog logging.

func (*SyslogConfig) Validate added in v0.9.10

func (c *SyslogConfig) Validate() error

Validate validates the syslog configuration

type WrappingMessage added in v0.9.10

type WrappingMessage interface {
	Message
	// Unwrap returns the original error wrapped in this message.
	Unwrap() error
}

WrappingMessage is a message that wraps a different error.

func Wrap added in v0.9.10

func Wrap(Cause error, Code string, Explanation string, Args ...interface{}) WrappingMessage

Wrap creates a wrapped error with a specific Code and Explanation string. The wrapping method will automatically

append the error message in brackets.
  • Cause is the original error that can be accessed with the Unwrap method.
  • Code is an error code allowing an administrator to identify the error that happened.
  • Explanation is the explanation string to the system administrator. This is an fmt.Sprintf-compatible string
  • Args are the arguments to Explanation to create a formatted message. It is recommended that these arguments also be added as labels to allow system administrators to index the error properly.

func WrapUser added in v0.9.10

func WrapUser(Cause error, Code string, User string, Explanation string, Args ...interface{}) WrappingMessage

WrapUser creates a Message wrapping an error with a user-facing message.

  • Cause is the original error that can be accessed with the Unwrap method.
  • Code is an error code allowing an administrator to identify the error that happened.
  • UserMessage is the message that can be printed to the user if needed.
  • Explanation is the explanation string to the system administrator. This is an fmt.Sprintf-compatible string
  • Args are the arguments to Explanation to create a formatted message. It is recommended that these arguments also be added as labels to allow system administrators to index the error properly.

type Writer added in v0.9.10

type Writer interface {
	// Write writes a log message to the output.
	Write(level Level, message Message) error
	// Rotate attempts to rotate the logs. Has no effect on non-file based loggers.
	Rotate() error

	io.Closer
}

Writer is a specialized writer to write a line of log messages.

Jump to

Keyboard shortcuts

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