services

package
v0.0.0-...-a34dc26 Latest Latest
Warning

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

Go to latest
Published: May 5, 2016 License: Apache-2.0 Imports: 12 Imported by: 0

Documentation

Overview

Package services provides services that allow logging and tracing targeted to microservices.

Index

Constants

View Source
const (
	// ErrInsertLogEntryCode defines the log entry code for database errors.
	ErrInsertLogEntryCode = "insert_db_log_entry"

	// ErrInsertLogEntryMessage defines the log entry message for database errors.
	ErrInsertLogEntryMessage = "Error inserting a new log entry"

	// LoggerServiceName defines the service name for events from LoggerMongo.
	LoggerServiceName = "LoggerMongo"
)

Variables

This section is empty.

Functions

This section is empty.

Types

type Entry

type Entry struct {
	ID           bson.ObjectId `bson:"_id"`
	Level        tlog.Level    `bson:"level"`
	Time         time.Time     `bson:"time"`
	AppName      string        `bson:"app"`
	AppVersion   string        `bson:"appver"`
	SvcName      string        `bson:"svc,omitempty"`
	Stack        []string      `bson:"stack,omitempty"`
	NumCPU       int           `bson:"numcpu,omitempty"`
	NumThreads   int           `bson:"numthr,omitempty"`
	Host         string        `bson:"host,omitempty"`
	ReqMethod    string        `bson:"method,omitempty"`
	ReqURL       string        `bson:"url,omitempty"`
	ReqIP        string        `bson:"ip,omitempty"`
	ReqUserAgent string        `bson:"usragent,omitempty"`
	ReqReferer   string        `bson:"reqref,omitempty"`
	ReqClientIP  string        `bson:"cliip,omitempty"`
	AccountID    string        `bson:"actid,omitempty"`
	AccountName  string        `bson:"actname,omitempty"`
	AccountPlan  string        `bson:"actplan,omitempty"`
	AccountEmail string        `bson:"actmail,omitempty"`
	Code         string        `bson:"code"`
	Message      string        `bson:"msg"`
	InnerError   string        `bson:"err,omitempty"`
}

A Entry represents a logging entry.

func (*Entry) SetError

func (e *Entry) SetError(err error)

SetError decodes specified error to InnerError field.

func (*Entry) ToLogfmt

func (e *Entry) ToLogfmt() string

ToLogfmt returns the Logfmt encoding of current entry.

type Logger

type Logger interface {
	// LogEntry adds a new logging entry.
	LogEntry(*Entry)

	// NewContext creates a new context that allows to services log its events not
	// knowing current context.
	NewContext() *TracerContext

	// SetApplication sets the name and version of current application.
	SetApplication(name, version string)
}

A Logger represents a service that allows to log events.

type LoggerMongo

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

A LoggerMongo represents a service that allows to log events to MongoDB database.

func NewLoggerMongo

func NewLoggerMongo(col *mgo.Collection) *LoggerMongo

NewLoggerMongo creates a new instance of LoggerMongo.

func (*LoggerMongo) LogEntry

func (l *LoggerMongo) LogEntry(entry *Entry)

LogEntry adds a new logging entry.

func (*LoggerMongo) NewContext

func (l *LoggerMongo) NewContext() *TracerContext

NewContext creates a new context that allows to services log its events not knowing current context.

func (*LoggerMongo) SetApplication

func (l *LoggerMongo) SetApplication(name, version string)

SetApplication sets the name and version of current application.

type TracerContext

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

A TracerContext represents a Tracer context that allows to services log its events not knowing current context.

func NewEntryContext

func NewEntryContext(logger Logger, appName, appVersion string) *TracerContext

NewEntryContext creates a new instance of TracerContext.

func (*TracerContext) AddEntry

func (ctx *TracerContext) AddEntry(
	level tlog.Level, code, msg string,
	htStatus int, err error,
	svcname string, stack ...string,
) *tlog.TracerEntry

AddEntry appends a new event to current container.

func (*TracerContext) SetAccount

func (ctx *TracerContext) SetAccount(
	actID string,
	actName string,
	actPlan string,
	actEmail string,
)

SetAccount sets user account details.

func (*TracerContext) SetFilter

func (ctx *TracerContext) SetFilter(level tlog.Level)

SetFilter sets the minimum severity level for logging. Events that its severity level is less than specified value will be ignored.

func (*TracerContext) SetRequest

func (ctx *TracerContext) SetRequest(req *http.Request)

SetRequest sets the HTTP request to get context values.

func (*TracerContext) SetSync

func (ctx *TracerContext) SetSync(status bool)

SetSync determines whether log writes are synchronous or not. Default false (asynchronous).

Jump to

Keyboard shortcuts

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