Documentation ¶
Index ¶
- Constants
- Variables
- func AddTransport(t Transport) error
- func Close()
- func Debugf(ctx context.Context, f string, args ...interface{})
- func Errorf(ctx context.Context, f string, args ...interface{})
- func Fatalf(ctx context.Context, f string, args ...interface{})
- func GetTenantID(ctx context.Context) uuid.UUID
- func Hostname() string
- func IncrementEvent(ctx context.Context, eventName string)
- func IncrementEventWithPayload(ctx context.Context, eventName string, payload string)
- func Infof(ctx context.Context, f string, args ...interface{})
- func InitForService(name service.Service, transports []Transport, fetcher EventMetadataFetcher)
- func InitForTools(ctx context.Context, toolName string, fileLogName string, ...)
- func Log(ctx context.Context, event LogEvent)
- func PreInit(transports []Transport)
- func RemoveTransport(name string) error
- func Verbosef(ctx context.Context, f string, args ...interface{})
- func Warningf(ctx context.Context, f string, args ...interface{})
- type EventCategory
- type EventCode
- type EventMetadataFetcher
- type EventMetadataMap
- type LocalStatus
- type LogEvent
- type LogEventTypeInfo
- type LogLevel
- type LogRecordArray
- type LogRecordContent
- type LogTransportStats
- type Transport
- type TransportConfig
Constants ¶
const EventNameNone string = "System.unused"
EventNameNone is name of default non counter logging event i.e. message only
const EventNameUnknown string = "System.unknown"
EventNameUnknown is name of default event which is not found in the map
Variables ¶
var HeaderSDKVersion = "X-Usercloudssdk-Version"
HeaderSDKVersion is the header name for the UserClouds SDK version
Functions ¶
func AddTransport ¶
AddTransport adds another transport to the logger
func Debugf ¶
Debugf logs a string with optional format-string parsing by default these are internal-to-Userclouds logs
func GetTenantID ¶
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 ¶
IncrementEvent records a UserClouds event without message or payload
func IncrementEventWithPayload ¶
IncrementEventWithPayload logs event related to security that carry a payload
func InitForService ¶
func InitForService(name service.Service, transports []Transport, fetcher EventMetadataFetcher)
InitForService sets up logging transports for long running serving
func InitForTools ¶
InitForTools configures logging to the screen and file if desired for a tool
func PreInit ¶
func PreInit(transports []Transport)
PreInit sets up logging to the screen before config file was read
func RemoveTransport ¶
RemoveTransport removes named transport if it is active
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 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
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 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