gosteno

package module
v0.0.0-...-0c8581c Latest Latest
Warning

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

Go to latest
Published: Apr 23, 2015 License: Apache-2.0 Imports: 14 Imported by: 0

README

Gosteno Build Status

Gosteno is a golang implementation of the steno log tool. The feature set of Gosteno is very similar with that of ruby steno.

Overview

Core concepts behind Gosteno includes codec, sink, level, tag.

codec

A codec encodes log entries to structural data, more specifically, JSON format data. Besides JSON codecs, Gosteno provides prettified codec which generates more human-readable data.

sink

Roughly speaking, a sink is the destination where you store your log data. It's an abstraction of the underlying data storage systems. Currently Gosteno supports two kinds of sinks, namely IOSink and SyslogSink. IOSink includes files and standard output while SyslogSink streams your log data to syslog daemons such as rsyslogd. You can register as many sinks as you want. Everytime you log information, it will be written to all the sinks you have registered.

level

Gosteno supports 9 levels(from low to high): all, debug2, debug1, debug, info, warn, error, fatal, off. You can change the level on the fly without respawning the process.

tag

In gosteno, tags are extended information that will be encoded together with other normal log information. You can add as many tags as you want. Tag makes the log information extensive.

Get Gosteno

go get -u github.com/cloudfoundry/gosteno

Getting started

Here is a short but complete program showing how to registering sinks, chosing codec, tagging the information.

package main

import (
    "github.com/cloudfoundry/gosteno"
    "os"
)

func main() {
    c := &gosteno.Config{
        Sinks: []gosteno.Sink{
            gosteno.NewFileSink("./a.log"),
            gosteno.NewIOSink(os.Stdout),
            gosteno.NewSyslogSink("foobar"),
        },
        Level:     gosteno.LOG_INFO,
        Codec:     gosteno.NewJsonCodec(),
        EnableLOC: true,
    }
    gosteno.Init(c)
    logger := gosteno.NewLogger("test")
    t := gosteno.NewTaggedLogger(logger, map[string]string{"foo": "bar", "hello": "world"})
    t.Info("Hello")
}

Supported platforms

Currently targeting modern flavors of darwin and linux.

License

Apache 2.0

Documentation

Index

Constants

View Source
const (
	EXCLUDE_NONE = 0

	EXCLUDE_LEVEL = 1 << (iota - 1)
	EXCLUDE_TIMESTAMP
	EXCLUDE_FILE
	EXCLUDE_LINE
	EXCLUDE_METHOD
	EXCLUDE_DATA
	EXCLUDE_MESSAGE
)
View Source
const (
	MaxMessageSize  = 1024 * 3
	TruncatePostfix = "..."
)

Variables

View Source
var (
	LOG_OFF    = defineLogLevel("off", 0)
	LOG_FATAL  = defineLogLevel("fatal", 1)
	LOG_ERROR  = defineLogLevel("error", 5)
	LOG_WARN   = defineLogLevel("warn", 10)
	LOG_INFO   = defineLogLevel("info", 15)
	LOG_DEBUG  = defineLogLevel("debug", 16)
	LOG_DEBUG1 = defineLogLevel("debug1", 17)
	LOG_DEBUG2 = defineLogLevel("debug2", 18)
	LOG_ALL    = defineLogLevel("all", 30)
)

Functions

func ClearLoggerRegexp

func ClearLoggerRegexp()

func EnterTestMode

func EnterTestMode(logLevel ...LogLevel)

func Init

func Init(c *Config)

func SetLoggerRegexp

func SetLoggerRegexp(pattern string, level LogLevel) error

Types

type BaseLogger

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

func (*BaseLogger) Level

func (l *BaseLogger) Level() LogLevel

func (*BaseLogger) Log

func (l *BaseLogger) Log(x LogLevel, m string, d map[string]interface{})

type Codec

type Codec interface {
	EncodeRecord(record *Record) ([]byte, error)
}

func NewJsonCodec

func NewJsonCodec() Codec

type Config

type Config struct {
	Sinks     []Sink
	Level     LogLevel
	Codec     Codec
	EnableLOC bool
}

type IOSink

type IOSink struct {
	sync.Mutex
	// contains filtered or unexported fields
}

func NewFileSink

func NewFileSink(path string) *IOSink

func NewIOSink

func NewIOSink(file *os.File) *IOSink

func (*IOSink) AddRecord

func (x *IOSink) AddRecord(record *Record)

func (*IOSink) Flush

func (x *IOSink) Flush()

func (*IOSink) GetCodec

func (x *IOSink) GetCodec() Codec

func (*IOSink) SetCodec

func (x *IOSink) SetCodec(codec Codec)

type JsonCodec

type JsonCodec struct {
}

func (*JsonCodec) EncodeRecord

func (j *JsonCodec) EncodeRecord(record *Record) ([]byte, error)

type JsonPrettifier

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

func NewJsonPrettifier

func NewJsonPrettifier(flag int) *JsonPrettifier

func (*JsonPrettifier) DecodeJsonLogEntry

func (p *JsonPrettifier) DecodeJsonLogEntry(logEntry string) (*Record, error)

func (*JsonPrettifier) EncodeRecord

func (p *JsonPrettifier) EncodeRecord(record *Record) ([]byte, error)

type L

type L interface {
	Level() LogLevel
	Log(x LogLevel, m string, d map[string]interface{})
}

type LogLevel

type LogLevel struct {
	Name     string
	Priority int
}

func GetLogLevel

func GetLogLevel(name string) (LogLevel, error)

func (LogLevel) MarshalJSON

func (x LogLevel) MarshalJSON() ([]byte, error)

func (LogLevel) String

func (l LogLevel) String() string

func (*LogLevel) UnmarshalJSON

func (x *LogLevel) UnmarshalJSON(data []byte) error

type Logger

type Logger struct {
	sync.Mutex
	L
	// contains filtered or unexported fields
}

func NewLogger

func NewLogger(name string) *Logger

func (*Logger) Copy

func (l *Logger) Copy() (rv *Logger)

func (*Logger) Debug

func (l *Logger) Debug(m string)

func (*Logger) Debug1

func (l *Logger) Debug1(m string)

func (*Logger) Debug1d

func (l *Logger) Debug1d(d map[string]interface{}, m string)

func (*Logger) Debug1df

func (l *Logger) Debug1df(d map[string]interface{}, f string, a ...interface{})

func (*Logger) Debug1f

func (l *Logger) Debug1f(f string, a ...interface{})

func (*Logger) Debug2

func (l *Logger) Debug2(m string)

func (*Logger) Debug2d

func (l *Logger) Debug2d(d map[string]interface{}, m string)

func (*Logger) Debug2df

func (l *Logger) Debug2df(d map[string]interface{}, f string, a ...interface{})

func (*Logger) Debug2f

func (l *Logger) Debug2f(f string, a ...interface{})

func (*Logger) Debugd

func (l *Logger) Debugd(d map[string]interface{}, m string)

func (*Logger) Debugdf

func (l *Logger) Debugdf(d map[string]interface{}, f string, a ...interface{})

func (*Logger) Debugf

func (l *Logger) Debugf(f string, a ...interface{})

func (*Logger) Error

func (l *Logger) Error(m string)

func (*Logger) Errord

func (l *Logger) Errord(d map[string]interface{}, m string)

func (*Logger) Errordf

func (l *Logger) Errordf(d map[string]interface{}, f string, a ...interface{})

func (*Logger) Errorf

func (l *Logger) Errorf(f string, a ...interface{})

func (*Logger) Fatal

func (l *Logger) Fatal(m string)

func (*Logger) Fatald

func (l *Logger) Fatald(d map[string]interface{}, m string)

func (*Logger) Fataldf

func (l *Logger) Fataldf(d map[string]interface{}, f string, a ...interface{})

func (*Logger) Fatalf

func (l *Logger) Fatalf(f string, a ...interface{})

func (*Logger) Get

func (l *Logger) Get(k string) (rv interface{})

func (*Logger) Info

func (l *Logger) Info(m string)

func (*Logger) Infod

func (l *Logger) Infod(d map[string]interface{}, m string)

func (*Logger) Infodf

func (l *Logger) Infodf(d map[string]interface{}, f string, a ...interface{})

func (*Logger) Infof

func (l *Logger) Infof(f string, a ...interface{})

func (*Logger) Log

func (l *Logger) Log(x LogLevel, m string, d map[string]interface{})

func (*Logger) Set

func (l *Logger) Set(k string, v interface{})

func (*Logger) Warn

func (l *Logger) Warn(m string)

func (*Logger) Warnd

func (l *Logger) Warnd(d map[string]interface{}, m string)

func (*Logger) Warndf

func (l *Logger) Warndf(d map[string]interface{}, f string, a ...interface{})

func (*Logger) Warnf

func (l *Logger) Warnf(f string, a ...interface{})

type Record

type Record struct {
	Timestamp RecordTimestamp        `json:"timestamp"`
	Pid       int                    `json:"process_id"`
	Source    string                 `json:"source"`
	Level     LogLevel               `json:"log_level"`
	Message   string                 `json:"message"`
	Data      map[string]interface{} `json:"data"`
	File      string                 `json:"file,omitempty"`
	Line      int                    `json:"line,omitempty"`
	Method    string                 `json:"method,omitempty"`
}

func NewRecord

func NewRecord(s string, l LogLevel, m string, d map[string]interface{}) *Record

type RecordTimestamp

type RecordTimestamp float64

func (RecordTimestamp) MarshalJSON

func (t RecordTimestamp) MarshalJSON() ([]byte, error)

type Sink

type Sink interface {
	AddRecord(record *Record)
	Flush()

	SetCodec(codec Codec)
	GetCodec() Codec
}

type Syslog

type Syslog struct {
	sync.Mutex
	// contains filtered or unexported fields
}

func NewSyslogSink

func NewSyslogSink(namespace string) *Syslog

func (*Syslog) AddRecord

func (s *Syslog) AddRecord(record *Record)

func (*Syslog) Flush

func (s *Syslog) Flush()

func (*Syslog) GetCodec

func (s *Syslog) GetCodec() Codec

func (*Syslog) SetCodec

func (s *Syslog) SetCodec(codec Codec)

type TestingSink

type TestingSink struct {
	sync.RWMutex
	// contains filtered or unexported fields
}

func GetMeTheGlobalTestSink

func GetMeTheGlobalTestSink() *TestingSink

func NewTestingSink

func NewTestingSink() *TestingSink

func (*TestingSink) AddRecord

func (tSink *TestingSink) AddRecord(record *Record)

func (*TestingSink) Flush

func (tSink *TestingSink) Flush()

func (*TestingSink) GetCodec

func (tSink *TestingSink) GetCodec() Codec

func (*TestingSink) Records

func (tSink *TestingSink) Records() []*Record

func (*TestingSink) SetCodec

func (tSink *TestingSink) SetCodec(codec Codec)

Directories

Path Synopsis
Package syslog provides a simple interface to the system log service.
Package syslog provides a simple interface to the system log service.

Jump to

Keyboard shortcuts

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