README
Gosteno 
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
- Variables
- func ClearLoggerRegexp()
- func EnterTestMode(logLevel ...LogLevel)
- func Init(c *Config)
- func SetLoggerRegexp(pattern string, level LogLevel) error
- type BaseLogger
- type Codec
- type Config
- type IOSink
- type JsonCodec
- type JsonPrettifier
- type L
- type LogLevel
- type Logger
- func (l *Logger) Copy() (rv *Logger)
- func (l *Logger) Debug(m string)
- func (l *Logger) Debug1(m string)
- func (l *Logger) Debug1d(d map[string]interface{}, m string)
- func (l *Logger) Debug1df(d map[string]interface{}, f string, a ...interface{})
- func (l *Logger) Debug1f(f string, a ...interface{})
- func (l *Logger) Debug2(m string)
- func (l *Logger) Debug2d(d map[string]interface{}, m string)
- func (l *Logger) Debug2df(d map[string]interface{}, f string, a ...interface{})
- func (l *Logger) Debug2f(f string, a ...interface{})
- func (l *Logger) Debugd(d map[string]interface{}, m string)
- func (l *Logger) Debugdf(d map[string]interface{}, f string, a ...interface{})
- func (l *Logger) Debugf(f string, a ...interface{})
- func (l *Logger) Error(m string)
- func (l *Logger) Errord(d map[string]interface{}, m string)
- func (l *Logger) Errordf(d map[string]interface{}, f string, a ...interface{})
- func (l *Logger) Errorf(f string, a ...interface{})
- func (l *Logger) Fatal(m string)
- func (l *Logger) Fatald(d map[string]interface{}, m string)
- func (l *Logger) Fataldf(d map[string]interface{}, f string, a ...interface{})
- func (l *Logger) Fatalf(f string, a ...interface{})
- func (l *Logger) Get(k string) (rv interface{})
- func (l *Logger) Info(m string)
- func (l *Logger) Infod(d map[string]interface{}, m string)
- func (l *Logger) Infodf(d map[string]interface{}, f string, a ...interface{})
- func (l *Logger) Infof(f string, a ...interface{})
- func (l *Logger) Log(x LogLevel, m string, d map[string]interface{})
- func (l *Logger) Set(k string, v interface{})
- func (l *Logger) Warn(m string)
- func (l *Logger) Warnd(d map[string]interface{}, m string)
- func (l *Logger) Warndf(d map[string]interface{}, f string, a ...interface{})
- func (l *Logger) Warnf(f string, a ...interface{})
- type Record
- type RecordTimestamp
- type Sink
- type Syslog
- type TestingSink
Constants ¶
const ( EXCLUDE_NONE = 0 EXCLUDE_LEVEL = 1 << (iota - 1) EXCLUDE_TIMESTAMP EXCLUDE_FILE EXCLUDE_LINE EXCLUDE_METHOD EXCLUDE_DATA EXCLUDE_MESSAGE )
const ( MaxMessageSize = 1024 * 3 TruncatePostfix = "..." )
Variables ¶
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 SetLoggerRegexp ¶
Types ¶
type BaseLogger ¶
type BaseLogger struct {
// contains filtered or unexported fields
}
func (*BaseLogger) Level ¶
func (l *BaseLogger) Level() LogLevel
type Codec ¶
func NewJsonCodec ¶
func NewJsonCodec() Codec
type IOSink ¶
func NewFileSink ¶
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 Logger ¶
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"` }
type RecordTimestamp ¶
type RecordTimestamp float64
func (RecordTimestamp) MarshalJSON ¶
func (t RecordTimestamp) MarshalJSON() ([]byte, error)
type Syslog ¶
func NewSyslogSink ¶
type TestingSink ¶
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)
Source Files
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. |