uclog

package
v0.7.5 Latest Latest
Warning

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

Go to latest
Published: Oct 4, 2023 License: MIT Imports: 12 Imported by: 0

Documentation

Index

Constants

View Source
const EventNameNone string = "System.unused"

EventNameNone is name of default non counter logging event i.e. message only

View Source
const EventNameUnknown string = "System.unknown"

EventNameUnknown is name of default event which is not found in the map

Variables

View Source
var HeaderSDKVersion = "X-Usercloudssdk-Version"

HeaderSDKVersion is the header name for the UserClouds SDK version

Functions

func AddTransport

func AddTransport(t Transport) error

AddTransport adds another transport to the logger

func Close

func Close()

Close shuts down logging transports

func Debugf

func Debugf(ctx context.Context, f string, args ...interface{})

Debugf logs a string with optional format-string parsing by default these are internal-to-Userclouds logs

func Errorf

func Errorf(ctx context.Context, f string, args ...interface{})

Errorf logs an error with optional format-string parsing

func Fatalf

func Fatalf(ctx context.Context, f string, args ...interface{})

Fatalf is equivalent to Printf() followed by a call to os.Exit(1).

func GetTenantID

func GetTenantID(ctx context.Context) uuid.UUID

GetTenantID always returns uuid.Nil since SDK relies on the tenantID specified at initialization time

func Hostname

func Hostname() string

Hostname centralizes our code to figure out what machine we're on TODO: this isn't the right place for this to live, but the wrong code already got copy-pasted across logging so at least this will start the fix. It could be in the service package but that ends up importing migrate -> uclog and I don't want to untangle that right now. GetStatus shouldn't live in uclog either but add it to the list. :)

func IncrementEvent

func IncrementEvent(ctx context.Context, eventName string)

IncrementEvent records a UserClouds event without message or payload

func IncrementEventWithPayload

func IncrementEventWithPayload(ctx context.Context, eventName string, payload string)

IncrementEventWithPayload logs event related to security that carry a payload

func Infof

func Infof(ctx context.Context, f string, args ...interface{})

Infof logs a string at info level (default visible in user console)

func InitForService

func InitForService(name service.Service, transports []Transport, fetcher EventMetadataFetcher)

InitForService sets up logging transports for long running serving

func InitForTools

func InitForTools(ctx context.Context, toolName string, fileLogName string, transports []Transport)

InitForTools configures logging to the screen and file if desired for a tool

func Log

func Log(ctx context.Context, event LogEvent)

Log logs a specific event

func PreInit

func PreInit(transports []Transport)

PreInit sets up logging to the screen before config file was read

func RemoveTransport

func RemoveTransport(name string) error

RemoveTransport removes named transport if it is active

func Verbosef

func Verbosef(ctx context.Context, f string, args ...interface{})

Verbosef is the loudest Originally introduced to log DB queries / timing without killing dev console

func Warningf

func Warningf(ctx context.Context, f string, args ...interface{})

Warningf logs a string at info level (default visible in user console)

Types

type EventCategory

type EventCategory string

EventCategory identifies the category of the event

const (
	EventCategoryUnknown       EventCategory = "Unknown"
	EventCategorySystem        EventCategory = "System"
	EventCategoryCall          EventCategory = "Call"
	EventCategoryDuration      EventCategory = "Duration"
	EventCategoryInputError    EventCategory = "InputError"
	EventCategoryInternalError EventCategory = "InternalError"
	EventCategoryResultSuccess EventCategory = "ResultSuccess"
	EventCategoryResultFailure EventCategory = "ResultFailure"
	EventCategoryCount         EventCategory = "Count"

	EventCategoryTODO EventCategory = "TODO" // these are auto-generated events that need classified
)

Different event categories

type EventCode

type EventCode int

EventCode is a unique code for each event

const (
	EventCodeNone    EventCode = 1
	EventCodeUnknown EventCode = -1
)

Two baseline events that have to be in the map

type EventMetadataFetcher

type EventMetadataFetcher interface {
	Init(updateHandler func(updatedMap *EventMetadataMap, tenantID uuid.UUID) error) error
	FetchEventMetadataForTenant(tenantID uuid.UUID)
	Close()
}

EventMetadataFetcher knows how to get the event metadata map

type EventMetadataMap

type EventMetadataMap struct {
	Version int
	Map     map[string]LogEventTypeInfo
}

EventMetadataMap is contains information about a particular event type

type LocalStatus

type LocalStatus struct {
	CallCount          int       `json:"callcount"`           // total calls received by the service
	InputErrorCount    int       `json:"input_errorcount"`    // number of input errors
	InternalErrorCount int       `json:"internal_errorcount"` // number of internal errors
	StartupTime        time.Time `json:"startup_time"`        // time the service started
	LastCall           time.Time `json:"lastcall_time"`       // timestamp of last successful call
	LastErrorCall      time.Time `json:"lasterror_time"`      // timestamp of last error
	LastErrorCode      int       `json:"lasterror_code"`      // last error code
	ComputeTime        int       `json:"computetime"`         // amount of time spent in handlers

	Hostname string        `json:"hostname"` // for understanding the response
	Region   region.Region `json:"region"`

	LoggerStats []LogTransportStats `json:"loggerstats"`
}

LocalStatus contains basic approximate statistics about the service

func GetStatus

func GetStatus() LocalStatus

GetStatus return approximate statistics about the service

type LogEvent

type LogEvent struct {
	LogLevel LogLevel  // Level of logging Error - Warning - Debug - Info
	Name     string    // String name of the event
	Code     EventCode // Unique code for this event of this type
	Count    int       // Reporting multiple events at once
	Message  string    // Message associated with the event
	Payload  string    // Optional payload associated with a counter event
	// Identity of the sender
	TenantID uuid.UUID
	AppID    uuid.UUID
}

LogEvent is a structured event that is passed to the logger to be recorded

func (LogEvent) Validate

func (e LogEvent) Validate() error

Validate validates that filled out event is consistent

type LogEventTypeInfo

type LogEventTypeInfo struct {
	Name     string
	Code     EventCode
	Service  service.Service
	URL      string
	Ignore   bool // Don't send event to the server (only process locally)
	Category EventCategory
}

LogEventTypeInfo is contains information about a particular event type

type LogLevel

type LogLevel int

LogLevel represent the urgency level of the logging event

const (
	LogLevelNone       LogLevel = -1
	LogLevelNonMessage LogLevel = 0
	LogLevelError      LogLevel = 1
	LogLevelWarning    LogLevel = 2
	LogLevelInfo       LogLevel = 3
	LogLevelDebug      LogLevel = 4
	LogLevelVerbose    LogLevel = 5
)

Different log levels

type LogRecordArray

type LogRecordArray struct {
	Service  service.Service    `json:"s"`
	TenantID uuid.UUID          `json:"t"`
	Region   region.Region      `json:"r"`
	Host     string             `json:"h"`
	Records  []LogRecordContent `json:"c"`
}

LogRecordArray represents a set of log messages/events from a same service/tenant/region/host combination It is used for on the wire representation

type LogRecordContent

type LogRecordContent struct {
	Message   string    `json:"m"`
	Code      EventCode `json:"c"`
	Payload   string    `json:"p"`
	Timestamp int       `json:"t"`
}

LogRecordContent represents unique information in log event/message for a fixed service/tenant/region/host combination It is used for on the wire representation

type LogTransportStats

type LogTransportStats struct {
	Name                string
	QueueSize           int64
	DroppedEventCount   int64
	SentEventCount      int64
	FailedAPICallsCount int64
}

LogTransportStats contains statistics about transport operation

func GetStats

func GetStats() []LogTransportStats

GetStats returns the stats for each of the transports

type Transport

type Transport interface {
	Init() (*TransportConfig, error)
	WriteMessage(ctx context.Context, message string, level LogLevel)
	WriteCounter(ctx context.Context, event LogEvent)
	GetStats() LogTransportStats
	GetName() string
	Flush() error
	Close()
}

Transport defines the interface loggers implement

type TransportConfig

type TransportConfig struct {
	Required    bool     `yaml:"required" json:"required"`
	MaxLogLevel LogLevel `yaml:"max_log_level" json:"max_log_level"`
}

TransportConfig defines the shared config for log transports

Jump to

Keyboard shortcuts

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