logtap

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

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

Go to latest
Published: Mar 11, 2019 License: MIT Imports: 3 Imported by: 2

README

Logtap

Logtap is an embeddable and configurable log aggregation, storage, and publishing service.

Memory Usage

logtap.Drain

A logtap.Drain is a simple endpoint that accepts logs that are sent through logtap. Multiple drains can be created and added to logvac. A drain can represent logs that are streamed to stdout, a file, a tcp socket, or anything that can be wrapped to accept logtap.Message structs. There are 3 adapters stored at logtap/drain.Adapt* that can be used to adapt common interfaces to the logvac.Drain interface.

logtap.Archive

An Archive is an interface for retreiving a slice of logs from the opaque storage medium. Currently there exists one storage option: BoltDB.

Example

This example will create a logtap that accepts udp syslog packets and stores them on disk in two files, fatal.log and info.log. The file fatal.log will only contain fatal errors and higher, while info.log will contain all message that are info and more severe.


package main

import (
  "github.com/nanobox-io/nanobox-logtap"
  "github.com/nanobox-io/nanobox-logtap/drain"
  "github.com/nanobox-io/nanobox-logtap/collector"
  "os"
  "os/signal"
)

func main(){
  logTap := logtap.New(nil)
  defer logTap.Close()
  
  fatal, err := os.Create("/tmp/fatal.log")
  if err != nil {
    panic(err)
  }
  defer fatal.Close()
  info, err := os.Create("/tmp/info.log")
  if err != nil {
    panic(err)
  }
  defer info.Close()

  logTap.AddDrain("info", drain.Filter(drain.AdaptWriter(info)), 1)
  logTap.AddDrain("fatal", drain.Filter(drain.AdaptWriter(fatal)), 5)

  udpCollector, err := collector.SyslogUDPStart("app-logs", ":514" ,logTap)
  if err != nil {
    panic(err)
  }
  defer udpCollector.Close()

  logTap.Publish("logtap", 1, "listening on udp port 514")

  c := make(chan os.Signal, 1)
  signal.Notify(c, os.Interrupt, os.Kill)

  // wait for a signal to arrive
  <-c
}
Notes:

Documentation

Overview

Copyright (c) 2015 Pagoda Box Inc

This Source Code Form is subject to the terms of the Mozilla Public License, v. 2.0. If a copy of the MPL was not distributed with this file, You can obtain one at http://mozilla.org/MPL/2.0/.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Archive

type Archive interface {
	Slice(name string, offset, limit uint64, level int) ([]Message, error)
}

type Drain

type Drain func(Logger, Message)

type Logger

type Logger interface {
	Fatal(string, ...interface{})
	Error(string, ...interface{})
	Warn(string, ...interface{})
	Info(string, ...interface{})
	Debug(string, ...interface{})
	Trace(string, ...interface{})
}

Logger is a simple interface that's designed to be intentionally generic to allow many different types of Logger's to satisfy its interface

type Logtap

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

func New

func New(log Logger) *Logtap

Establishes a new logtap object and makes sure it has a logger

func (*Logtap) AddDrain

func (l *Logtap) AddDrain(tag string, drain Drain)

AddDrain addes a drain to the listeners and sets its logger

func (*Logtap) Close

func (l *Logtap) Close()

Close logtap and remove all drains

func (*Logtap) Publish

func (l *Logtap) Publish(kind string, priority int, content string)

func (*Logtap) RemoveDrain

func (l *Logtap) RemoveDrain(tag string)

RemoveDrain drops a drain

func (*Logtap) WriteMessage

func (l *Logtap) WriteMessage(msg Message)

WriteMessage broadcasts to all drains in seperate go routines Returns once all drains have received the message, but may not have processed the message yet

type Message

type Message struct {
	Type     string
	Time     time.Time `json:"time"`
	Priority int       `json:"priority"`
	Content  string    `json:"content"`
}

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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