Documentation
¶
Index ¶
- Constants
- func ToZap(logger Logger) *zap.Logger
- type JSONLogEntry
- type LogLevel
- type Logger
- type Sink
- type SinkLogger
- type TestLogEntry
- type TestLogger
- func (c *TestLogger) Debug(msg string, args ...interface{})
- func (c *TestLogger) Error(msg string, args ...interface{})
- func (c *TestLogger) Fatal(msg string, args ...interface{})
- func (c *TestLogger) Info(msg string, args ...interface{})
- func (c *TestLogger) IsDebugEnabled() bool
- func (c *TestLogger) IsErrorEnabled() bool
- func (c *TestLogger) IsInfoEnabled() bool
- func (c *TestLogger) IsLevelEnabled(level LogLevel) bool
- func (c *TestLogger) IsTraceEnabled() bool
- func (c *TestLogger) IsWarnEnabled() bool
- func (c *TestLogger) Log(level string, msg string, args ...interface{})
- func (c *TestLogger) Stack(next Logger) Logger
- func (c *TestLogger) Trace(msg string, args ...interface{})
- func (c *TestLogger) Warn(msg string, args ...interface{})
- func (c *TestLogger) With(metadata map[string]interface{}) Logger
- func (c *TestLogger) WithContext(ctx context.Context) Logger
- func (c *TestLogger) WithPrefix(prefix string) Logger
- func (c *TestLogger) WithSink(sink Sink, level LogLevel) Logger
Constants ¶
const ( Reset = "\033[0m" Black = "\033[1;30m" Red = "\033[31m" Green = "\033[32m" Yellow = "\033[33m" Blue = "\033[34m" Magenta = "\033[35m" Cyan = "\033[36m" White = "\033[37m" BlueBold = "\033[34;1m" MagentaBold = "\033[35;1m" RedBold = "\033[31;1m" YellowBold = "\033[33;1m" WhiteBold = "\033[37;1m" CyanBold = "\033[36;1m" Gray = "\033[1;90m" // This is actually "bright black" but Robin said that's a oximoron. Purple = "\u001b[38;5;200m" )
Variables ¶
This section is empty.
Functions ¶
Types ¶
type JSONLogEntry ¶
type JSONLogEntry struct {
Timestamp time.Time `json:"timestamp,omitempty"`
Message string `json:"message"`
Severity string `json:"severity,omitempty"`
Trace string `json:"logging.googleapis.com/trace,omitempty"`
Metadata map[string]interface{} `json:"metadata,omitempty"`
// Logs Explorer allows filtering and display of this as `jsonPayload.component`.
Component string `json:"component,omitempty"`
}
JSONLogEntry defines a log entry this is modeled after the JSON format expected by Cloud Logging https://github.com/GoogleCloudPlatform/golang-samples/blob/08bc985b4973901c09344eabbe9d7d5add7dc656/run/logging-manual/main.go
func (JSONLogEntry) String ¶
func (e JSONLogEntry) String() string
String renders an entry structure to the JSON format expected by Cloud Logging.
type LogLevel ¶
type LogLevel int
LogLevel defines the level of logging
func GetLevelFromEnv ¶
func GetLevelFromEnv() LogLevel
GetLevelFromEnv will look at the environment var `AGENTUITY_LOG_LEVEL` and convert it into the appropriate LogLevel
type Logger ¶
type Logger interface {
// With will return a new logger using metadata as the base context
With(metadata map[string]interface{}) Logger
// WithPrefix will return a new logger with a prefix prepended to the message
WithPrefix(prefix string) Logger
// WithContext will return a new logger with the given context
WithContext(ctx context.Context) Logger
// Trace level logging
Trace(msg string, args ...interface{})
// Debug level logging
Debug(msg string, args ...interface{})
// Info level logging
Info(msg string, args ...interface{})
// Warning level logging
Warn(msg string, args ...interface{})
// Error level logging
Error(msg string, args ...interface{})
// Fatal level logging and exit with code 1
Fatal(msg string, args ...interface{})
// Stack will return a new logger that logs to the given logger as well as the current logger
Stack(next Logger) Logger
// IsLevelEnabled returns true if the given log level is enabled
IsLevelEnabled(level LogLevel) bool
// IsTraceEnabled returns true if trace level logging is enabled
IsTraceEnabled() bool
// IsDebugEnabled returns true if debug level logging is enabled
IsDebugEnabled() bool
// IsInfoEnabled returns true if info level logging is enabled
IsInfoEnabled() bool
// IsWarnEnabled returns true if warn level logging is enabled
IsWarnEnabled() bool
// IsErrorEnabled returns true if error level logging is enabled
IsErrorEnabled() bool
}
Logger is an interface for logging
func NewJSONLogger ¶
NewJSONLogger returns a new Logger instance which can be used for structured logging
func NewOtelLogger ¶ added in v1.0.8
type SinkLogger ¶
type SinkLogger interface {
Logger
// SetSink will set the sink, and level to sink
SetSink(sink Sink, level LogLevel)
}
func NewConsoleLogger ¶
func NewConsoleLogger(levels ...LogLevel) SinkLogger
NewConsoleLogger returns a new Logger instance which will log to the console
func NewJSONLoggerWithSink ¶
func NewJSONLoggerWithSink(sink Sink, level LogLevel) SinkLogger
NewJSONLoggerWithSink returns a new Logger instance using a sink and suppressing the console logging
type TestLogEntry ¶
type TestLogger ¶
type TestLogger struct {
Logs []TestLogEntry
// contains filtered or unexported fields
}
func NewTestLogger ¶
func NewTestLogger() *TestLogger
NewTestLogger returns a new Logger instance useful for testing
func (*TestLogger) Debug ¶
func (c *TestLogger) Debug(msg string, args ...interface{})
func (*TestLogger) Error ¶
func (c *TestLogger) Error(msg string, args ...interface{})
func (*TestLogger) Fatal ¶
func (c *TestLogger) Fatal(msg string, args ...interface{})
func (*TestLogger) Info ¶
func (c *TestLogger) Info(msg string, args ...interface{})
func (*TestLogger) IsDebugEnabled ¶ added in v1.0.135
func (c *TestLogger) IsDebugEnabled() bool
func (*TestLogger) IsErrorEnabled ¶ added in v1.0.135
func (c *TestLogger) IsErrorEnabled() bool
func (*TestLogger) IsInfoEnabled ¶ added in v1.0.135
func (c *TestLogger) IsInfoEnabled() bool
func (*TestLogger) IsLevelEnabled ¶ added in v1.0.135
func (c *TestLogger) IsLevelEnabled(level LogLevel) bool
func (*TestLogger) IsTraceEnabled ¶ added in v1.0.135
func (c *TestLogger) IsTraceEnabled() bool
func (*TestLogger) IsWarnEnabled ¶ added in v1.0.135
func (c *TestLogger) IsWarnEnabled() bool
func (*TestLogger) Log ¶
func (c *TestLogger) Log(level string, msg string, args ...interface{})
func (*TestLogger) Stack ¶ added in v1.0.8
func (c *TestLogger) Stack(next Logger) Logger
func (*TestLogger) Trace ¶
func (c *TestLogger) Trace(msg string, args ...interface{})
func (*TestLogger) Warn ¶
func (c *TestLogger) Warn(msg string, args ...interface{})
func (*TestLogger) With ¶
func (c *TestLogger) With(metadata map[string]interface{}) Logger
func (*TestLogger) WithContext ¶ added in v1.0.8
func (c *TestLogger) WithContext(ctx context.Context) Logger
func (*TestLogger) WithPrefix ¶
func (c *TestLogger) WithPrefix(prefix string) Logger
WithPrefix will return a new logger with a prefix prepended to the message