logging

package
v1.0.0-bc5 Latest Latest
Warning

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

Go to latest
Published: Nov 15, 2019 License: Apache-2.0 Imports: 6 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Agent

type Agent struct {
	Version     string `json:"version,omitempty"`
	Name        string `json:"name,omitempty"`
	ID          string `json:"id,omitempty"`
	EphemeralID string `json:"ephemeral_id,omitempty"`
}

Agent is the structure of an agent

func NewAgent

func NewAgent() Agent

NewAgent creates a new Agent and properly initializes all required fields

func (Agent) WithEphemeralID

func (agent Agent) WithEphemeralID(id string) Agent

WithEphemeralID sets the ephemeral id field and returns the agent itself

func (Agent) WithID

func (agent Agent) WithID(id string) Agent

WithID sets the id field and returns the agent itself

func (Agent) WithName

func (agent Agent) WithName(name string) Agent

WithName sets the name field and returns the agent itself

func (Agent) WithVersion

func (agent Agent) WithVersion(version string) Agent

WithVersion sets the version field and returns the agent itself

type Dispatcher

type Dispatcher interface {
	Dispatch(msg LogMessage) error
	Add(loggers ...Logger)
	WithLogLevel(level LogLevel) Dispatcher
}

Dispatcher is the common Log dispatcher interface

type ECS

type ECS struct {
	Version string `json:"version,omitempty"`
}

ECS is the structure of Meta-information specific to ECS

func NewECS

func NewECS() ECS

NewECS creates a new ECS and properly initializes all required fields

type Error

type Error struct {
	Message string `json:"message,omitempty"`
	ID      string `json:"id,omitempty"`
	Code    string `json:"code,omitempty"`
}

Error is the structure of an error These fields can represent errors of any kind. Use them for errors that happen while fetching events or in cases where the event itself contains an error.

func NewError

func NewError() Error

NewError creates a new Error and properly initializes all required fields

func (Error) WithCode

func (err Error) WithCode(code string) Error

WithCode sets the Code field and returns the error itself

func (Error) WithID

func (err Error) WithID(id string) Error

WithID sets the ID field and returns the error itself

func (Error) WithMessage

func (err Error) WithMessage(msg string) Error

WithMessage sets the message field and returns the error itself

type HTTP

type HTTP struct {
	Version  string   `json:"version,omitempty"`
	Response Response `json:"response,omitempty"`
	Request  Request  `json:"request,omitempty"`
}

HTTP is the structure of an http request and response Fields related to HTTP requests and responses.

func NewHTTP

func NewHTTP() HTTP

NewHTTP creates a new HTTP and properly initializes all required fields

func (HTTP) WithRequest

func (httpInfo HTTP) WithRequest(req Request) HTTP

WithRequest sets the request object field and returns the http itself

func (HTTP) WithResponse

func (httpInfo HTTP) WithResponse(resp Response) HTTP

WithResponse sets the response object field and returns the http itself

func (HTTP) WithVersion

func (httpInfo HTTP) WithVersion(version string) HTTP

WithVersion sets the version field and returns the http itself

type Log

type Log struct {
	Level    string `json:"level,omitempty"`
	Original string `json:"original,omitempty"`

	Line   uint32 `json:"line,omitempty"`
	Offset uint32 `json:"offset,omitempty"`
	// contains filtered or unexported fields
}

Log is the structure of a Log event

func NewLog

func NewLog() Log

NewLog creates a new Log and properly initializes all required fields

func (Log) WithLevel

func (log Log) WithLevel(level LogLevel) Log

WithLevel sets the log level field and returns the log itself

func (Log) WithLine

func (log Log) WithLine(line uint32) Log

WithLine sets the log line field and returns the log itself

func (Log) WithOffset

func (log Log) WithOffset(offset uint32) Log

WithOffset sets the log offset field and returns the log itself

func (Log) WithOriginal

func (log Log) WithOriginal(original string) Log

WithOriginal sets the log original message field and returns the log itself

type LogLevel

type LogLevel int

LogLevel defines the logging level as untyped int

const (
	// ERROR defines the error log level as int value of 1
	ERROR LogLevel = iota + 1
	// WARNING defines the warning log level as int value of 2
	WARNING
	// INFO defines the info log level as int value of 3
	INFO
	// DEBUG defines the debug log level as int value of 4
	DEBUG
	// TRACE defines the trace log level as int value of 5
	TRACE
)

type LogMessage

type LogMessage struct {
	Timestamp strfmt.DateTime   `json:"@timestamp,omitempty"`
	Tags      []string          `json:"tags,omitempty"`
	Labels    map[string]string `json:"labels,omitempty"`
	Message   string            `json:"message,omitempty"`
	Agent     Agent             `json:"agent,omitempty"`
	Error     Error             `json:"error,omitempty"`
	HTTP      HTTP              `json:"http,omitempty"`
	Log       Log               `json:"log,omitempty"`
	ECS       ECS               `json:"ecs,omitempty"`
}

LogMessage is the top-level structure The base set contains all fields which are on the top level. These fields are common across all types of events.

func NewLogMessage

func NewLogMessage() LogMessage

NewLogMessage creates a new LogMessage and properly initializes all required fields

func (*LogMessage) Marshall

func (msg *LogMessage) Marshall() ([]byte, error)

Marshall returns the json representation of a LogMessage

func (LogMessage) WithAgent

func (msg LogMessage) WithAgent(agent Agent) LogMessage

WithAgent sets the agent object field and returns the message itself

func (LogMessage) WithError

func (msg LogMessage) WithError(err Error) LogMessage

WithError sets the agent object field and returns the message itself

func (LogMessage) WithHTTP

func (msg LogMessage) WithHTTP(httpInfo HTTP) LogMessage

WithHTTP sets the http object field and returns the message itself

func (LogMessage) WithLabels

func (msg LogMessage) WithLabels(labels map[string]string) LogMessage

WithLabels sets the labels field and returns the message itself

func (LogMessage) WithLog

func (msg LogMessage) WithLog(log Log) LogMessage

WithLog sets the log object field and returns the message itself

func (LogMessage) WithMessage

func (msg LogMessage) WithMessage(message string) LogMessage

WithMessage sets the message field and returns the message itself

func (LogMessage) WithTags

func (msg LogMessage) WithTags(tags []string) LogMessage

WithTags sets the tags field and returns the message itself

type Logger

type Logger interface {
	Log(msg LogMessage) error
}

Logger is the interface describing a loggers's behavior

type Mock

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

Mock is a mock logger to be used in tests

func (*Mock) GetLoggedMessages

func (logger *Mock) GetLoggedMessages() []LogMessage

GetLoggedMessages returns a slice of all logged messages

func (*Mock) Log

func (logger *Mock) Log(msg LogMessage) error

Log mocks logging used the mock logger implementation

type MockDispatcher

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

MockDispatcher is a mock log dispatcher to be used in tests

func NewMockDispatcher

func NewMockDispatcher() *MockDispatcher

NewMockDispatcher creates a new mock log dispatcher to be used in testing

func (*MockDispatcher) Add

func (ld *MockDispatcher) Add(loggers ...Logger)

Add is a dummy implementation for mocking

func (*MockDispatcher) Dispatch

func (ld *MockDispatcher) Dispatch(msg LogMessage) error

Dispatch iterates over dispatcher loggers and logs the given message for each one of them

func (*MockDispatcher) GetDispatchedMessages

func (ld *MockDispatcher) GetDispatchedMessages() []string

GetDispatchedMessages returns a slice of all dispatched messages

func (*MockDispatcher) WithLogLevel

func (ld *MockDispatcher) WithLogLevel(level LogLevel) Dispatcher

WithLogLevel sets the log dispatcher level and returns the dispatcher

type MuxDispatcher

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

MuxDispatcher holds is a concurrent-safe collection of loggers

func NewLogDispatcher

func NewLogDispatcher(loggers ...Logger) *MuxDispatcher

NewLogDispatcher properly creates a new log dispatcher initializing the mutex and loggers slice

func (*MuxDispatcher) Add

func (ld *MuxDispatcher) Add(loggers ...Logger)

Add adds aa logger to the dispatcher

func (*MuxDispatcher) Dispatch

func (ld *MuxDispatcher) Dispatch(msg LogMessage) error

Dispatch iterates over dispatcher loggers and logs the given message for each one of them

func (*MuxDispatcher) WithLogLevel

func (ld *MuxDispatcher) WithLogLevel(level LogLevel) Dispatcher

WithLogLevel sets the log dispatcher level and returns the dispatcher

type Request

type Request struct {
	Method string `json:"method,omitempty"`
}

Request is the structure of an http request

func NewRequest

func NewRequest() Request

NewRequest creates a new Request and properly initializes all required fields

func (Request) WithMethod

func (req Request) WithMethod(method string) Request

WithMethod sets the request method field and returns the request itself

type Response

type Response struct {
	Body       string `json:"method,omitempty"`
	StatusCode uint16 `json:"status_code,omitempty"`
}

Response is the structure of an http response

func NewResponse

func NewResponse() Response

NewResponse creates a new Response and properly initializes all required fields

func (Response) WithBody

func (resp Response) WithBody(body string) Response

WithBody sets the response body field and returns the request itself

func (Response) WithStatusCode

func (resp Response) WithStatusCode(sc uint16) Response

WithStatusCode sets the response status code field and returns the request itself

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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