Documentation
¶
Index ¶
- Constants
- func GenerateMessageCodesFile(filename string) (string, error)
- func GetMessageCodes(filename string) (map[string]string, error)
- func MustWriteMessageCodesFile(sourceFile string, destinationFile string)
- func NewGoLogWriter(backendLogger Logger) io.Writer
- func WriteMessageCodesFile(sourceFile string, destinationFile string) error
- type Config
- type Destination
- type Facility
- type FacilityString
- type Format
- type LabelName
- type LabelValue
- type Labels
- type Level
- func (level Level) MarshalJSON() ([]byte, error)
- func (level Level) MarshalYAML() (interface{}, error)
- func (level Level) MustName() LevelString
- func (level *Level) Name() (LevelString, error)
- func (level Level) String() string
- func (level *Level) UnmarshalJSON(data []byte) error
- func (level *Level) UnmarshalYAML(unmarshal func(interface{}) error) error
- func (level Level) Validate() error
- type LevelString
- type Logger
- type LoggerFactory
- type Message
- type SyslogConfig
- type WrappingMessage
- type Writer
Constants ¶
const ELogFileOpenFailed = "LOG_FILE_OPEN_FAILED"
ContainerSSH failed to open the specified log file.
const ELogRotateFailed = "LOG_ROTATE_FAILED"
ContainerSSH cannot rotate the logs as requested because of an underlying error.
const ELogWriteFailed = "LOG_WRITE_FAILED"
ContainerSSH cannot write to the specified log file. This usually happens because the underlying filesystem is full or the log is located on a non-local storage (e.g. NFS), which is not supported.
const EUnknownError = "UNKNOWN_ERROR"
This is an untyped error. If you see this in a log that is a bug and should be reported.
const MTest = "TEST"
This is message that should only be seen in unit and component tests, never in production.
Variables ¶
This section is empty.
Functions ¶
func GenerateMessageCodesFile ¶ added in v0.9.12
func GetMessageCodes ¶ added in v0.9.12
GetMessageCodes parses the specified go source file and returns a key-value mapping of message codes and their associated description or an error.
func MustWriteMessageCodesFile ¶ added in v0.9.12
func NewGoLogWriter ¶ added in v0.9.1
NewGoLogWriter creates an adapter for the go logger that writes using the Log method of the logger.
func WriteMessageCodesFile ¶ added in v0.9.12
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.
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.
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 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 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
MarshalJSON marshals a level number to a JSON string
func (Level) MarshalYAML ¶ added in v0.9.6
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 ¶
String Convert the int level to the string representation. Panics if the level is not valid.
func (*Level) UnmarshalJSON ¶ added in v0.9.5
UnmarshalJSON decodes a JSON level string to a level type.
func (*Level) UnmarshalYAML ¶ added in v0.9.5
UnmarshalYAML decodes a YAML level string to a level type.
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
MustNewLogger is identical to NewLogger, except that it panics instead of returning an error
func NewLogger ¶ added in v0.9.10
NewLogger creates a standard logger pipeline.
- config is the configuration structure for the logger
goland:noinspection GoUnusedExportedFunction
func NewTestLogger ¶ added in v0.9.10
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
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
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.