redis15

package module
v0.0.0-...-af7e2fb Latest Latest
Warning

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

Go to latest
Published: Feb 20, 2017 License: Apache-2.0 Imports: 10 Imported by: 0

README

log15-redis-handler (package redis15)

Build Status Go Report Card GoDoc

How to send log messages to Logstash via Redis

package main

import (
	"os"

	redis15 "github.com/bolcom/log15-redis-handler"
	"github.com/inconshreveable/log15"
)

func main() {
	logger := log15.New()
	f := redis15.LogstashFormat{}
	f.Application = "daxy"
	f.Role = "webservice"
	f.Instance = "ps34"
	f.SourceHost = "MacErnest"
	f.Pretty = true // e.g. hook to verbose flag

	redisHandler , _ := NewRedisHandler([]string{"localhost:6379}, "logs", f) 
	// must handle err

	logger.SetHandler(redisHandler)
	logger.Debug("hello", "pi", 3.14)
}

Example output

{
		"@source_host": "MacErnest",
		"@timestamp": "2017-02-17T09:57:37.028587577+01:00",
		"@fields": {
				"application": "daxy",
				"file": "redis15.go",
				"instance": "ps34",
				"level": "DEBUG",
				"line": "22",
				"pi": "3.14",
				"role": "webservice"
		},
		"@message": "hello"
}

Note that most values are converted to a String. Use NoStringConvert on the LogstashFormat value to specify the exceptions. For application logging, the logtype, level and message are reserved.

© 2017 bol.com. Apache v2 Licensed. Contributions are welcome.

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func StreamWithNewlineHandler

func StreamWithNewlineHandler(wr io.Writer, fmtr log15.Format) log15.Handler

StreamWithNewlineHandler writes log records to an io.Writer with the given format and appends a newline (\n).

StreamWithNewlineHandler wraps itself with LazyHandler and SyncHandler to evaluate Lazy objects and perform safe concurrent writes.

Types

type BufferingHandler

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

func NewBufferingHandler

func NewBufferingHandler(delegate log15.Handler, capacity int, interval time.Duration) *BufferingHandler

func (*BufferingHandler) Flush

func (b *BufferingHandler) Flush()

Flush can be called to explicitly send all pending records.

func (*BufferingHandler) Log

func (b *BufferingHandler) Log(r *log15.Record) error

Log implements log15.Handler

type LogstashFormat

type LogstashFormat struct {
	SourceHost  string
	Instance    string
	Role        string
	Application string
	Pretty      bool
	OmitEmpty   bool
	// NoStringConvertSet holds keys for which no string conversion must be applied
	// Not go-routine safe
	NoStringConvertSet map[string]bool
}

func (LogstashFormat) Format

func (f LogstashFormat) Format(r *log15.Record) (data []byte)

Format implements log15.Format

func (*LogstashFormat) NoStringConvert

func (f *LogstashFormat) NoStringConvert(keys ...string)

NoStringConvert registers keys for which the context value should not be converted to a string.

type RedisConnection

type RedisConnection interface {
	Send(string, ...interface{}) error
	Close() error
	Err() error
	Flush() error
}

RedisConnection is the interface of functions we use from redis.

type RedisHandler

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

RedisHandler is a log15.Handler implementation that sends JSON documents to a Redis queue (key).

func NewRedisHandler

func NewRedisHandler(endpoints []string, key string, format log15.Format) (*RedisHandler, error)

NewRedisHandler return a new connected RedisHandler. endpoints is a list of strings using the format host:port

func (*RedisHandler) Close

func (h *RedisHandler) Close()

Close closes the open connection to redis.

func (*RedisHandler) Log

func (h *RedisHandler) Log(r *log15.Record) error

Log implements log15.Handler

Jump to

Keyboard shortcuts

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