log4nova

package module
v0.0.0-...-45ce92e Latest Latest
Warning

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

Go to latest
Published: Oct 11, 2017 License: MIT Imports: 15 Imported by: 0

README

Log4Nova

A simple logging library for forwarding your logs into your Nova log store

Setting up Log4Nova

  1. Vendor this library into your go-service
  2. Vendor in the dependencies:
$ make dependencies
  1. Wire up the NovaHandler to your middleware chain with your Nova API Keys:
//Example for standing up the log4nova handler
func setupGlobalMiddleware(handler http.Handler) http.Handler {
	clientID := os.Getenv("NOVA_CLIENT_ID")
	clientSecret := os.Getenv("NOVA_CLIENT_SECRET")
	novaLogger := log4nova.NewNovaLogger(clientID, clientSecret)
    log4nova.NewNovaHandler(novaLogger,
        handlers.SomeOtherHandler(handler))
}

Usage

To log any data to your splunk instance, first initialize a log4nova instance:

	clientID := os.Getenv("NOVA_CLIENT_ID")
	clientSecret := os.Getenv("NOVA_CLIENT_SECRET")
	novaLogger := log4nova.NewNovaLogger(clientID, clientSecret)
	
	//Batch logs every 5 secs
	novaLogger.SendInterval = 5000
	
	//Mirror all data to stdout
	novaLogger.SendToStdOut = true
	
	//Start the logger.  If the logger is not started, logs will not be sent to the logstore
	novaLogger.Start()
	
	//Send my logs off to nova
	novaLogger.WithFields({
	    SomeField: "Some important value"    
    }).Errorf("Error! %v", e)
    
    //Stop the logger
    novaLogger.Stop()

Troubleshooting

TBD

Documentation

Index

Constants

View Source
const (
	MaxBufferSize        = 400
	DefaultFlushInterval = 2000
)

Variables

This section is empty.

Functions

This section is empty.

Types

type Fields

type Fields map[string]interface{}

Fields allows passing key value pairs to Logrus

type INovaLogger

type INovaLogger interface {
	Start()
	Stop()
	Write(p []byte) (n int, err error)
	WithField(key string, value interface{}) *logrus.Entry
	WithFields(fields Fields) *logrus.Entry
	WithError(err error) *logrus.Entry
	Debugf(format string, v ...interface{})
	Infof(format string, v ...interface{})
	Warningf(format string, v ...interface{})
	Errorf(format string, v ...interface{})
	Error(v ...interface{})
	Warning(v ...interface{})
	Info(v ...interface{})
	Debug(v ...interface{})
	SetDebug()
	SetInfo()
	SetWarn()
	SetError()
}

type NovaHandler

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

func NewNovaHandler

func NewNovaHandler(logger INovaLogger, handler http.Handler) *NovaHandler

NewNovaHandler creates a new instance of the Nova Logging Handler

func (*NovaHandler) ServeHTTP

func (nl *NovaHandler) ServeHTTP(w http.ResponseWriter, r *http.Request)

type NovaLogger

type NovaLogger struct {
	SendInterval int

	SendToStdOut bool
	// contains filtered or unexported fields
}

Stats data structure

func NewNovaLogger

func NewNovaLogger(clientID, clientSecret string) (*NovaLogger, error)

NewNovaLoggerWithHost creates a Nova Logging instance with the default host

func NewNovaLoggerWithCustom

func NewNovaLoggerWithCustom(eventsClient events.ClientInterface, logger *logrus.Logger,
	clientID, clientSecret, host string) (*NovaLogger, error)

NewNovaLogger creates a new instance of the NovaLogger

func NewNovaLoggerWithHost

func NewNovaLoggerWithHost(clientID, clientSecret, host string) (*NovaLogger, error)

func (*NovaLogger) Debug

func (nl *NovaLogger) Debug(v ...interface{})

Debug logs a message at level Debug on the standard logger.

func (*NovaLogger) Debugf

func (nl *NovaLogger) Debugf(format string, v ...interface{})

Debugf logs a message at level Debug on the standard logger.

func (*NovaLogger) Error

func (nl *NovaLogger) Error(v ...interface{})

Error logs a message at level Error on the standard logger.

func (*NovaLogger) Errorf

func (nl *NovaLogger) Errorf(format string, v ...interface{})

Errorf logs a message at level Error on the standard logger.

func (*NovaLogger) Info

func (nl *NovaLogger) Info(v ...interface{})

Info logs a message at level Info on the standard logger.

func (*NovaLogger) Infof

func (nl *NovaLogger) Infof(format string, v ...interface{})

Infof logs a message at level Info on the standard logger.

func (*NovaLogger) SetDebug

func (nl *NovaLogger) SetDebug()

SetDebug sets the log level to debug

func (*NovaLogger) SetError

func (nl *NovaLogger) SetError()

SetError sets the log level to error

func (*NovaLogger) SetInfo

func (nl *NovaLogger) SetInfo()

SetDebug sets the log level to debug

func (*NovaLogger) SetWarn

func (nl *NovaLogger) SetWarn()

SetWarn sets the log level to warn

func (*NovaLogger) Start

func (nl *NovaLogger) Start()

Start kicks off the logger to feed data off to nova as available

func (*NovaLogger) Stop

func (nl *NovaLogger) Stop()

Stop ends the logging

func (*NovaLogger) Warning

func (nl *NovaLogger) Warning(v ...interface{})

Warning logs a message at level Warn on the standard logger.

func (*NovaLogger) Warningf

func (nl *NovaLogger) Warningf(format string, v ...interface{})

Warningf logs a message at level Warn on the standard logger.

func (*NovaLogger) WithError

func (nl *NovaLogger) WithError(err error) *logrus.Entry

WithError adds an error field to the logrus entry

func (*NovaLogger) WithField

func (nl *NovaLogger) WithField(key string, value interface{}) *logrus.Entry

WithField adds a field to the logrus entry

func (*NovaLogger) WithFields

func (nl *NovaLogger) WithFields(fields Fields) *logrus.Entry

WithFields add fields to the logrus entry

func (*NovaLogger) Write

func (nl *NovaLogger) Write(p []byte) (n int, err error)

Write sends all writes to the input channel

Directories

Path Synopsis
mocks
log4nova
Package mock_log4nova is a generated GoMock package.
Package mock_log4nova is a generated GoMock package.
logface-sdk-go/client/events
Package mock_events is a generated GoMock package.
Package mock_events is a generated GoMock package.

Jump to

Keyboard shortcuts

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