logging

package
v0.9.2 Latest Latest
Warning

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

Go to latest
Published: Apr 17, 2020 License: Apache-2.0 Imports: 13 Imported by: 72

Documentation

Overview

(C) Copyright 2019 Intel Corporation.

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.

GOVERNMENT LICENSE RIGHTS-OPEN SOURCE SOFTWARE The Government's rights to use, modify, reproduce, release, perform, display, or disclose this software are subject to the terms of the Apache License as provided in Contract No. 8F-30005. Any reproduction of computer software, computer software documentation, or portions thereof marked with this legend must also reproduce the markings.

(C) Copyright 2019 Intel Corporation.

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.

GOVERNMENT LICENSE RIGHTS-OPEN SOURCE SOFTWARE The Government's rights to use, modify, reproduce, release, perform, display, or disclose this software are subject to the terms of the Apache License as provided in Contract No. 8F-30005. Any reproduction of computer software, computer software documentation, or portions thereof marked with this legend must also reproduce the markings.

(C) Copyright 2019 Intel Corporation.

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.

GOVERNMENT LICENSE RIGHTS-OPEN SOURCE SOFTWARE The Government's rights to use, modify, reproduce, release, perform, display, or disclose this software are subject to the terms of the Apache License as provided in Contract No. 8F-30005. Any reproduction of computer software, computer software documentation, or portions thereof marked with this legend must also reproduce the markings.

(C) Copyright 2019 Intel Corporation.

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.

GOVERNMENT LICENSE RIGHTS-OPEN SOURCE SOFTWARE The Government's rights to use, modify, reproduce, release, perform, display, or disclose this software are subject to the terms of the Apache License as provided in Contract No. 8F-30005. Any reproduction of computer software, computer software documentation, or portions thereof marked with this legend must also reproduce the markings.

(C) Copyright 2019 Intel Corporation.

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.

GOVERNMENT LICENSE RIGHTS-OPEN SOURCE SOFTWARE The Government's rights to use, modify, reproduce, release, perform, display, or disclose this software are subject to the terms of the Apache License as provided in Contract No. 8F-30005. Any reproduction of computer software, computer software documentation, or portions thereof marked with this legend must also reproduce the markings.

(C) Copyright 2019 Intel Corporation.

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.

GOVERNMENT LICENSE RIGHTS-OPEN SOURCE SOFTWARE The Government's rights to use, modify, reproduce, release, perform, display, or disclose this software are subject to the terms of the Apache License as provided in Contract No. 8F-30005. Any reproduction of computer software, computer software documentation, or portions thereof marked with this legend must also reproduce the markings.

(C) Copyright 2019 Intel Corporation.

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.

GOVERNMENT LICENSE RIGHTS-OPEN SOURCE SOFTWARE The Government's rights to use, modify, reproduce, release, perform, display, or disclose this software are subject to the terms of the Apache License as provided in Contract No. 8F-30005. Any reproduction of computer software, computer software documentation, or portions thereof marked with this legend must also reproduce the markings.

(C) Copyright 2019 Intel Corporation.

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.

GOVERNMENT LICENSE RIGHTS-OPEN SOURCE SOFTWARE The Government's rights to use, modify, reproduce, release, perform, display, or disclose this software are subject to the terms of the Apache License as provided in Contract No. 8F-30005. Any reproduction of computer software, computer software documentation, or portions thereof marked with this legend must also reproduce the markings.

Index

Constants

View Source
const (
	DefaultLogLevel = LogLevelInfo
)

Variables

This section is empty.

Functions

func MustCreateSyslogger

func MustCreateSyslogger(prio syslog.Priority, flags int) *log.Logger

MustCreateSyslogger attempts to create a *log.Logger configured for output to the system log daemon. If it fails, it will panic.

func NewTestLogger

func NewTestLogger(prefix string) (*LeveledLogger, *LogBuffer)

NewTestLogger returns a logger and a *LogBuffer, with the logger configured to send all output into the buffer. The logger's level is set to DEBUG by default.

Types

type DebugLogger

type DebugLogger interface {
	Debugf(format string, args ...interface{})
}

DebugLogger defines an interface to be implemented by Debug loggers.

type DefaultDebugLogger

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

DefaultDebugLogger implements the DebugLogger interface.

func NewDebugLogger

func NewDebugLogger(dest io.Writer) *DefaultDebugLogger

NewDebugLogger returns a DebugLogger configured for outputting debugging messages.

func (*DefaultDebugLogger) Debugf

func (l *DefaultDebugLogger) Debugf(format string, args ...interface{})

Debugf emits a formatted debug message.

func (*DefaultDebugLogger) WithJSONOutput

func (l *DefaultDebugLogger) WithJSONOutput() DebugLogger

WithJSONOutput switches the logger's output to use structured JSON formatting.

func (*DefaultDebugLogger) WithSyslogOutput

func (l *DefaultDebugLogger) WithSyslogOutput() DebugLogger

WithSyslogOutput switches the logger's output to emit messages via the system logging service.

type DefaultErrorLogger

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

DefaultErrorLogger implements the ErrorLogger interface.

func NewCommandLineErrorLogger

func NewCommandLineErrorLogger(output io.Writer) *DefaultErrorLogger

NewCommandLineErrorLogger returns an ErrorLogger configured for outputting unadorned error messages (i.e. no timestamps, source info, etc); typically used for CLI utility logging.

func NewErrorLogger

func NewErrorLogger(prefix string, output io.Writer) *DefaultErrorLogger

NewErrorLogger returns an ErrorLogger configured for outputting error messages with standard formatting (e.g. to stderr, logfile, etc.)

func (*DefaultErrorLogger) Errorf

func (l *DefaultErrorLogger) Errorf(format string, args ...interface{})

Errorf emits a formatted error message.

func (*DefaultErrorLogger) WithJSONOutput

func (l *DefaultErrorLogger) WithJSONOutput() ErrorLogger

WithJSONOutput switches the logger's output to use structured JSON formatting.

func (*DefaultErrorLogger) WithSyslogOutput

func (l *DefaultErrorLogger) WithSyslogOutput() ErrorLogger

WithSyslogOutput switches the logger's output to emit messages via the system logging service.

type DefaultInfoLogger

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

DefaultInfoLogger implements the InfoLogger interface.

func NewCommandLineInfoLogger

func NewCommandLineInfoLogger(output io.Writer) *DefaultInfoLogger

NewCommandLineInfoLogger returns an InfoLogger configured for outputting unadorned informational messages (i.e. no timestamps, source info, etc); typically used for CLI utility logging.

func NewInfoLogger

func NewInfoLogger(prefix string, output io.Writer) *DefaultInfoLogger

NewInfoLogger returns an InfoLogger configured for outputting informational messages with standard formatting (e.g. to stderr, logfile, etc.)

func (*DefaultInfoLogger) Infof

func (l *DefaultInfoLogger) Infof(format string, args ...interface{})

Infof emits a formatted informational message.

func (*DefaultInfoLogger) WithJSONOutput

func (l *DefaultInfoLogger) WithJSONOutput() InfoLogger

WithJSONOutput switches the logger's output to use structured JSON formatting.

func (*DefaultInfoLogger) WithSyslogOutput

func (l *DefaultInfoLogger) WithSyslogOutput() InfoLogger

WithSyslogOutput switches the logger's output to emit messages via the system logging service.

type ErrorLogger

type ErrorLogger interface {
	Errorf(format string, args ...interface{})
}

ErrorLogger defines an interface to be implemented by Error loggers.

type InfoLogger

type InfoLogger interface {
	Infof(format string, args ...interface{})
}

InfoLogger defines an interface to be implemented by Info loggers.

type JSONFormatter

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

JSONFormatter emits JSON-formatted log output

func NewJSONFormatter

func NewJSONFormatter(output io.Writer, level, extraData string, flags int) *JSONFormatter

NewJSONFormatter returns a *JSONFormatter configured to emit JSON-formatted output.

func (*JSONFormatter) Output

func (f *JSONFormatter) Output(callDepth int, msg string) error

Output emulates log.Logger's Output(), but formats the message as a JSON-structured log entry.

type LeveledLogger

type LeveledLogger struct {
	sync.RWMutex
	// contains filtered or unexported fields
}

LeveledLogger provides a logging implementation which can emit log messages to multiple destinations with different output formats.

func NewCombinedLogger

func NewCombinedLogger(prefix string, output io.Writer) *LeveledLogger

NewCombinedLogger returns a logger configured to send all output to the supplied io.Writer.

func NewCommandLineLogger

func NewCommandLineLogger() *LeveledLogger

NewCommandLineLogger returns a logger configured to send non-error output to stdout and error output to stderr. The output format is suitable for command line utilities which don't want output to include timestamps and filenames.

func NewStdoutLogger

func NewStdoutLogger(prefix string) *LeveledLogger

NewStdoutLogger returns a logger configured to send all output to stdout (suitable for containerized/systemd operation).

func (*LeveledLogger) AddDebugLogger

func (ll *LeveledLogger) AddDebugLogger(newLogger DebugLogger)

AddDebugLogger adds the specified Debug logger to the logger.

func (*LeveledLogger) AddErrorLogger

func (ll *LeveledLogger) AddErrorLogger(newLogger ErrorLogger)

AddErrorLogger adds the specified Error logger to the logger.

func (*LeveledLogger) AddInfoLogger

func (ll *LeveledLogger) AddInfoLogger(newLogger InfoLogger)

AddInfoLogger adds the specified Info logger to the logger.

func (*LeveledLogger) Debug

func (ll *LeveledLogger) Debug(msg string)

Debug emits an unformatted message at Debug level, if the logger is configured to do so.

func (*LeveledLogger) Debugf

func (ll *LeveledLogger) Debugf(format string, args ...interface{})

Debugf emits a formatted message at Debug level, if the logger is configured to do so.

func (*LeveledLogger) Error

func (ll *LeveledLogger) Error(msg string)

Error emits an unformatted message at Error level, if the logger is configured to do so.

func (*LeveledLogger) Errorf

func (ll *LeveledLogger) Errorf(format string, args ...interface{})

Errorf emits a formatted message at Error level, if the logger is configured to do so.

func (*LeveledLogger) Info

func (ll *LeveledLogger) Info(msg string)

Info emits an unformatted message at Info level, if the logger is configured to do so.

func (*LeveledLogger) Infof

func (ll *LeveledLogger) Infof(format string, args ...interface{})

Infof emits a formatted message at Info level, if the logger is configured to do so.

func (*LeveledLogger) Level

func (ll *LeveledLogger) Level() LogLevel

Level returns the logger's current LogLevel.

func (*LeveledLogger) SetLevel

func (ll *LeveledLogger) SetLevel(newLevel LogLevel)

SetLevel sets the logger's LogLevel, at or above which messages will be emitted.

func (*LeveledLogger) WithDebugLogger

func (ll *LeveledLogger) WithDebugLogger(newLogger DebugLogger) *LeveledLogger

WithDebugLogger adds the specified Debug logger to the logger as part of a chained method call.

func (*LeveledLogger) WithErrorLogger

func (ll *LeveledLogger) WithErrorLogger(newLogger ErrorLogger) *LeveledLogger

WithErrorLogger adds the specified Error logger to the logger as part of a chained method call.

func (*LeveledLogger) WithInfoLogger

func (ll *LeveledLogger) WithInfoLogger(newLogger InfoLogger) *LeveledLogger

WithInfoLogger adds the specified Info logger to the logger as part of a chained method call.

func (*LeveledLogger) WithJSONOutput

func (ll *LeveledLogger) WithJSONOutput() *LeveledLogger

WithJSONOutput is a convenience method to set all logging outputs to the JSON formatter.

func (*LeveledLogger) WithLogLevel

func (ll *LeveledLogger) WithLogLevel(level LogLevel) *LeveledLogger

WithLogLevel allows the logger's LogLevel to be set as part of a chained method call.

func (*LeveledLogger) WithSyslogOutput

func (ll *LeveledLogger) WithSyslogOutput() *LeveledLogger

WithSyslogOutput is a convenience method to set all logging outputs to the Syslog formatter.

type LogBuffer

type LogBuffer struct {
	sync.Mutex
	// contains filtered or unexported fields
}

LogBuffer provides a thread-safe wrapper for bytes.Buffer. It only wraps a subset of bytes.Buffer's methods; just enough to implement io.Reader, io.Writer, and fmt.Stringer. The Reset() method is also wrapped in order to make it useful for testing.

func (*LogBuffer) Read

func (lb *LogBuffer) Read(p []byte) (int, error)

func (*LogBuffer) Reset

func (lb *LogBuffer) Reset()

func (*LogBuffer) String

func (lb *LogBuffer) String() string

func (*LogBuffer) Write

func (lb *LogBuffer) Write(p []byte) (int, error)

type LogLevel

type LogLevel int32

LogLevel represents the level at which the logger will emit log messages

const (
	// LogLevelDisabled disables any logging output
	LogLevelDisabled LogLevel = iota
	// LogLevelError emits messages at ERROR or higher
	LogLevelError
	// LogLevelInfo emits messages at INFO or higher
	LogLevelInfo
	// LogLevelDebug emits messages at DEBUG or higher
	LogLevelDebug
)

func (*LogLevel) Get

func (ll *LogLevel) Get() LogLevel

Get returns the current log level

func (*LogLevel) Set

func (ll *LogLevel) Set(newLevel LogLevel)

Set safely sets the log level to the supplied level

func (*LogLevel) SetString

func (ll *LogLevel) SetString(in string) error

SetString sets the log level from the supplied string.

func (LogLevel) String

func (ll LogLevel) String() string

type Logger

type Logger interface {
	DebugLogger
	Debug(msg string)
	InfoLogger
	Info(msg string)
	ErrorLogger
	Error(msg string)
}

Logger defines a standard logging interface

type Outputter

type Outputter interface {
	Output(callDepth int, msg string) error
}

Outputter defines an interface to be implemented by output formatters.

Jump to

Keyboard shortcuts

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