service

package
v1.0.1 Latest Latest
Warning

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

Go to latest
Published: Oct 17, 2020 License: BSD-3-Clause Imports: 17 Imported by: 0

Documentation

Overview

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

Index

Constants

This section is empty.

Variables

View Source
var LEVEL = struct {
	INFO     uint8
	DEBUG    uint8
	WARNING  uint8
	ERROR    uint8
	FATAL    uint8
	CRITICAL uint8
}{
	INFO:     0,
	DEBUG:    1,
	WARNING:  2,
	ERROR:    3,
	CRITICAL: 4,
	FATAL:    5,
}
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 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 `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 SetSink

func SetSink(sink string)

SetSink Sets the sink to write your logs to Sinks can help you distinguish logs from different sources e.g. Languages, services, servers e.t.c. Default sink is `default`

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 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, threadInit bool, message string, claims []*proto.Claim, level uint8) *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 RemoteWriter

type RemoteWriter interface {
	// Write function will be called with the Message to be sent to alt4 and an empty R to fill once done
	Write(msg *proto.Message, result *LogResult)
}

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 Alt4RemoteWriter RemoteWriter = writer{}

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

Jump to

Keyboard shortcuts

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