service

package
v1.0.11 Latest Latest
Warning

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

Go to latest
Published: Apr 9, 2021 License: BSD-3-Clause Imports: 18 Imported by: 0

Documentation

Overview

Package service holds the methods necessary to support implementation of loggers that write to alt4.

Index

Constants

View Source
const ModeDebug = "debug"
View Source
const ModeRelease = "release"
View Source
const ModeSilent = "silent"
View Source
const ModeTesting = "testing"

Variables

View Source
var SyncWriter = alt4SyncWriter{}

SyncWriter can be used to override a normal/default go logger to write it's output to alt4 This method writes logs synchronously. Unless you really need to we instead advice on Opening and Closing a group at the end of your routines which will wait for all writes started within the routine to complete Example log.SetOutput(SyncWriter)

View Source
var Writer = alt4Writer{}

Writer can be used to override a normal/default go logger to write it's output to alt4 This method writes logs asynchronously. Opening and Closing a group at the end of your routines ensure waits for all writes to finish. Example log.SetOutput(Writer)

Functions

func CloseGroup

func CloseGroup()

func LogTime added in v1.0.11

func LogTime() time.Time

func SetAuthToken

func SetAuthToken(token string)

SetAuthToken Used to set the auth token for writing to alt4. This setting can be done via config file ALT4_CONFIG or setting environment variable ALT4_AUTH_TOKEN

func SetDebugOutput

func SetDebugOutput(w io.Writer)

SetDebugOutput Is used to specify where alt4 emits additional output e.g. when facing network errors. Defaults os.Stderr

func SetMode

func SetMode(mode string)

SetMode Sets the behaviour of alt4 based on the following: `release` - Under this mode logs are written to alt4 and not emitted to stdout `debug` - Under this mode logs are written to alt4 and emitted to stdout `testing` - Under this mode logs are not written to alt4, just emitted to stdout `silent` - Under this mode logs are not written to alt4 or emitted to stdout `json`(coming soon) - Under this mode all logs are written to a JSON file which you can later upload to alt4 Mode can also be set via a config file ALT4_CONFIG or setting environment variable ALT4_MODE Default mode is `release`

func SetSource added in v1.0.2

func SetSource(source string)

SetSource Sets an id to identify where your logs are coming from By setting the source you distinguish logs from different sources e.g. Languages, services, servers e.t.c.

func WaitGroup

func WaitGroup() *sync.WaitGroup

Provide wait groups per go routine ID. Closing a group will wait for all write ops to finish.

Types

type DefaultHelper added in v1.0.2

type DefaultHelper struct{}

func (DefaultHelper) QueryAudit added in v1.0.2

func (helper DefaultHelper) QueryAudit(query proto.Query) (result *proto.QueryResult, err error)

func (DefaultHelper) WriteAudit added in v1.0.2

func (helper DefaultHelper) WriteAudit(msg *proto.AuditLog, result *LogResult)

func (DefaultHelper) WriteLog added in v1.0.2

func (helper DefaultHelper) WriteLog(msg *proto.Log, result *LogResult)

type LogResult

type LogResult struct {
	R *proto.Result

	Err error
	// contains filtered or unexported fields
}

LogResult Object returned when you create a log entry.

func Log

func Log(calldepth int, asGroup bool, message string, claims []*proto.Claim, level proto.Log_Level, logTime time.Time) *LogResult

Log Creates a log entry and writes it to alt4 in the background. This function should not be called directly and should instead be used from helper functions under the `log` package.

func (*LogResult) Result

func (result *LogResult) Result() (*proto.Result, error)

Result Returns actual Result from alt4. This will block and wait for the Result if not done

type RemoteHelper added in v1.0.2

type RemoteHelper interface {
	// WriteLog function will be called with the Message to be sent to alt4 and an empty LogResult to fill once done
	WriteLog(msg *proto.Log, result *LogResult)
	// WriteAudit function will be called with an audit message to be sent to alt4 and an empty LogResult to fill once done.
	WriteAudit(msg *proto.AuditLog, result *LogResult)
	// QueryAudit function will be called when you query audit logs. This function is synchronous.
	QueryAudit(query proto.Query) (result *proto.QueryResult, err error)
}

RemoteWriter an interface for functions called when writing to alt4. You can implement this function to mock writes to alt4 for better testing of your system.

var Alt4RemoteHelper RemoteHelper = DefaultHelper{}

Alt4RemoteWriter For testing purposes, implement your own RemoteHelper and equate it to this variable

Jump to

Keyboard shortcuts

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