cloudlog

package module
v1.1.0 Latest Latest
Warning

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

Go to latest
Published: Jun 21, 2018 License: MIT Imports: 13 Imported by: 2

README

go-cloudlog

GoDoc Build Status codecov Go Report Card

go-cloudlog is a client library for Anexia CloudLog.

Currently it only provides to push events to CloudLog. Querying is possible in a future release.

Install

With a correctly configured Go toolchain:

go get -u github.com/anexia-it/go-cloudlog

Quickstart

package main

import cloudlog "github.com/anexia-it/go-cloudlog"

func main() {

  // Init CloudLog client
  client, err := cloudlog.InitCloudLog("index", "ca.pem", "cert.pem", "cert.key")
  if err != nil {
    panic(err)
  }

  // Push simple message
  client.PushEvent("My first CloudLog event")

  // Push document as map
  logger.PushEvent(map[string]interface{}{
	"timestamp": time.Now(),
	"user":      "test",
	"severity":  1,
	"message":   "My first CloudLog event",
  })

  // Push document as map
  type Document struct {
	Timestamp uint64 `cloudlog:"timestamp"`
	User      string `cloudlog:"user"`
	Severity  int    `cloudlog:"severity"`
	Message   string `cloudlog:"message"`
  }
  logger.PushEvent(&Document{
 	Timestamp: 1495171849463,
	User:      "test",
	Severity:  1,
	Message:   "My first CloudLog event",
  })
}

Documentation

Overview

Package cloudlog provides a CloudLog client library

Index

Constants

View Source
const DefaultTagName = "cloudlog"

DefaultTagName defines the default tag name to use

Variables

View Source
var (
	// ErrCACertificateInvalid indicates that the supplied CA certificate is invalid
	ErrCACertificateInvalid = errors.New("CA certificate is invalid")

	// ErrCertificateMissing indicates that the client certificate is missing
	ErrCertificateMissing = errors.New("Client certificate is missing")

	// ErrIndexNotDefined indicates that the target index has not been defined
	ErrIndexNotDefined = errors.New("Target index is not defined")

	// ErrBrokersNotSpecified indicates that no brokers have been specified
	ErrBrokersNotSpecified = errors.New("Brokers not specified")
)
View Source
var DefaultBrokerAddresses = []string{
	"kafka0401.bdp.anexia-it.com:8443",
}

DefaultBrokerAddresses defines the default broker addresses

Functions

func ConvertToTimestamp added in v1.0.1

func ConvertToTimestamp(value interface{}) interface{}

ConvertToTimestamp takes an empty interface and tries to convert the value to a timestamp as expected by CloudLog (Unix millisecond timestamp). Besides being a no-op for int64 values, this function is able to convert time.Time values correctly.

If conversion is not possible this function returns the original value.

func GetDefaultSaramaConfig

func GetDefaultSaramaConfig() sarama.Config

GetDefaultSaramaConfig returns a copy of the default sarama config. The configuration returned by this function should be used as a basline configuration for modifications and changes.

func IsEventEncodingError

func IsEventEncodingError(err error) (ok bool, event interface{})

IsEventEncodingError checks if a supplied error is an EventEncodingError and returns a boolean flag and the event that caused the error

Types

type AutomaticEventEncoder added in v1.0.2

type AutomaticEventEncoder struct {
	Encoders []EventEncoder
}

AutomaticEventEncoder tries to find the right encoder for the given input

func NewAutomaticEventEncoder added in v1.0.2

func NewAutomaticEventEncoder() *AutomaticEventEncoder

NewAutomaticEventEncoder returns a new encoder that supports all available encoders

func (*AutomaticEventEncoder) EncodeEvent added in v1.0.2

func (e *AutomaticEventEncoder) EncodeEvent(event interface{}) (map[string]interface{}, error)

EncodeEvent encodes the given event

type CloudLog

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

CloudLog is the CloudLog object to send logs

func InitCloudLog

func InitCloudLog(index string, ca string, cert string, key string) (*CloudLog, error)

InitCloudLog validates and initializes the CloudLog client

func NewCloudLog

func NewCloudLog(indexName string, options ...Option) (cl *CloudLog, err error)

NewCloudLog initializes a new CloudLog instance

func (*CloudLog) Close

func (cl *CloudLog) Close() (err error)

Close closes the connection

func (*CloudLog) PushEvent

func (cl *CloudLog) PushEvent(event interface{}) error

PushEvent sends an event to CloudLog

func (*CloudLog) PushEventKey added in v1.1.0

func (cl *CloudLog) PushEventKey(key string, event interface{}) error

PushEventKey sends an event to CloudLog using the specified key as topic key

func (*CloudLog) PushEvents

func (cl *CloudLog) PushEvents(events ...interface{}) (err error)

PushEvents sends the supplied events to CloudLog

func (*CloudLog) PushEventsKey added in v1.1.0

func (cl *CloudLog) PushEventsKey(key string, events ...interface{}) (err error)

PushEventsKey sends the supplied events to CloudLog

type Event

type Event interface {
	// Encode encodes the given event to a map[string]interface{}
	Encode() map[string]interface{}
}

Event defines the interface events may optionally implement to provide their own encoding logic

type EventEncoder

type EventEncoder interface {
	// EncodeEvent encodes the given event
	EncodeEvent(event interface{}) (map[string]interface{}, error)
}

EventEncoder defines the interface for encoding events

type EventEncodingError

type EventEncodingError struct {
	Message string
	Event   interface{}
}

EventEncodingError indicates that an event could not be encoded

func NewUnsupportedEventType

func NewUnsupportedEventType(event interface{}) *EventEncodingError

NewUnsupportedEventType constructs a new EventEncodingError that indicates that the supplied event type is unsupported

func (*EventEncodingError) Error

func (e *EventEncodingError) Error() string

type MarshalError

type MarshalError struct {
	// EventMap contains the events data map
	EventMap map[string]interface{}
	// Parent contains the parent error
	Parent error
}

MarshalError represents a marshalling error

func NewMarshalError

func NewMarshalError(eventMap map[string]interface{}, parent error) *MarshalError

NewMarshalError returns a new MarshalError

func (*MarshalError) Error

func (e *MarshalError) Error() string

func (*MarshalError) WrappedErrors

func (e *MarshalError) WrappedErrors() []error

WrappedErrors returns the wrapped parent error

type Option

type Option func(*CloudLog) error

Option defines the type used for applying options to CloudLog

func OptionBrokers

func OptionBrokers(brokers ...string) Option

OptionBrokers defines the list of event brokers to use

func OptionCACertificate

func OptionCACertificate(pemBlock []byte) Option

OptionCACertificate sets the CA certificate CloudLog uses

func OptionCACertificateFile

func OptionCACertificateFile(path string) Option

OptionCACertificateFile loads the CA certificate from the supplied paths and configures CloudLog to use this CA certificate

func OptionClientCertificateFile

func OptionClientCertificateFile(certFile, keyFile string) Option

OptionClientCertificateFile configures CloudLog to use the certificate and key contained in the supplied paths as client certificate

func OptionClientCertificates

func OptionClientCertificates(certs []tls.Certificate) Option

OptionClientCertificates configures CloudLog to use the supplied tls.Certificates as client certificates

func OptionEventEncoder

func OptionEventEncoder(encoder EventEncoder) Option

OptionEventEncoder configures the EventEncoder to use for encoding events

func OptionSaramaConfig

func OptionSaramaConfig(config sarama.Config) Option

OptionSaramaConfig sets the sarama configuration

func OptionSourceHost

func OptionSourceHost(hostname string) Option

OptionSourceHost configures the sources' hostname

func OptionTLSConfig

func OptionTLSConfig(tlsConfig *tls.Config) Option

OptionTLSConfig defines the TLS configuration CloudLog uses

type SimpleEventEncoder

type SimpleEventEncoder struct {
}

SimpleEventEncoder implements a simple event encoder This encoder only supports map[string]interface{}, string and []byte events. A more sophisticated encoder providing support for encoding structs as well is available from the structencoder sub-package.

func (*SimpleEventEncoder) EncodeEvent

func (e *SimpleEventEncoder) EncodeEvent(event interface{}) (map[string]interface{}, error)

EncodeEvent encodes the given event

type StructEncoder added in v1.0.3

type StructEncoder struct{}

func NewStructEncoder added in v1.0.3

func NewStructEncoder() (*StructEncoder, error)

NewStructEncoder returns a new encoder that supports structs

func (*StructEncoder) EncodeEvent added in v1.0.3

func (e *StructEncoder) EncodeEvent(event interface{}) (m map[string]interface{}, err error)

EncodeEvent encodes the given event

Jump to

Keyboard shortcuts

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