logging

package
v0.85.0 Latest Latest
Warning

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

Go to latest
Published: Mar 26, 2024 License: MIT Imports: 15 Imported by: 10

README

Using the logging client

package main

import (
        "net/http"
        "fmt"
        "time"
        "github.com/philips-software/go-hsdp-api/logging"
)

func main() {
        client, err := logging.NewClient(http.DefaultClient, &logging.Config{
                SharedKey:    "YourSharedKeyHere=",
                SharedSecret: "YourSharedSecretHere==",
                BaseURL:      "https://logingestor-xx.host.com",
                ProductKey:   "product-akey-4bf2-9f2c-herec37ffake",
        })
        if err != nil {
            fmt.Printf("Error: %v\n", err)
            return
        }
        var logResource = logging.Resource{
           ID: "856b1142-6df5-4c84-b11d-da3f0a794e84",
           EventID: "1",
           Category: "ApplicationLog",
           Component: "TestApp",
           TransactionID: "1f12f95c-77a0-48da-835d-e95aa116198f", // traceability
           ServiceName: "TestApp",
           ApplicationInstance: "7248e79e-ba0b-4d0e-82a9-fb7a47d26c23",
           OriginatingUser: "729e83bb-ce7d-4052-92f8-077a376d774c",
           Severity: "Info",
           LogTime: time.Now().Format("2006-01-02T15:04:05.000Z07:00"),
           LogData: logging.LogData{
               Message: "Test log message",
           },
        }
        _, err = client.StoreResources([]logging.Resource{ logResource }, 1)
        if err != nil {
            fmt.Printf("Batch flushing failed: %v\n", err)
        }
}

Issues

Author

Andy Lo-A-Foe (andy.lo-a-foe@philips.com)

License

License is MIT. See LICENSE file

Documentation

Overview

Package logging provides support for HSDP Logging services

Index

Constants

View Source
const (
	// TimeFormat is the time format used for the LogTime field
	TimeFormat = "2006-01-02T15:04:05.000Z07:00"
)

Variables

View Source
var (
	ErrMissingCredentialsOrIAMClient = errors.New("missing signing credentials or IAM client")
	ErrNothingToPost                 = errors.New("nothing to post")
	ErrMissingSharedKey              = errors.New("missing shared key")
	ErrMissingSharedSecret           = errors.New("missing shared secret")
	ErrMissingBaseURL                = errors.New("missing base URL")
	ErrMissingProductKey             = errors.New("missing ProductKey")
	ErrBatchErrors                   = errors.New("batch errors. check Invalid map for details")
	ErrResponseError                 = errors.New("unexpected HSDP response error")
)

Functions

This section is empty.

Types

type Bundle

type Bundle struct {
	ResourceType string    `json:"resourceType"`
	Type         string    `json:"type"`
	Total        int       `json:"total"`
	ProductKey   string    `json:"productKey,omitempty"`
	Entry        []Element `json:"entry"`
}

Bundle is a FHIR bundle resource There is just enough there to create the logging payload

type Client

type Client struct {
	*iam.Client
	// contains filtered or unexported fields
}

Client holds the client state

func NewClient

func NewClient(httpClient *http.Client, config *Config) (*Client, error)

NewClient returns an instance of the logger client with the given Config

func (*Client) StoreResources

func (c *Client) StoreResources(msgs []Resource, count int) (*StoreResponse, error)

StoreResources posts one or more log messages In case invalid resources are detected StoreResources will return with ErrBatchErrors and the Response.Failed map will contain the resources This also happens in case the HSDP Ingestor API flags resources. In both cases the complete batch should be considered as not persisted and the LogEvents should be resubmitted for storage

type Config

type Config struct {
	Region       string
	Environment  string
	SharedKey    string
	SharedSecret string
	IAMClient    *iam.Client
	BaseURL      string
	ProductKey   string
	Debug        bool
	DebugLog     io.Writer
}

Config the client

func (*Config) Valid

func (c *Config) Valid() (bool, error)

Valid returns if all required config fields are present, false otherwise

type CustomIndexBody added in v0.6.0

type CustomIndexBody []struct {
	Fieldname string `json:"fieldname"`
	Fieldtype string `json:"fieldtype"`
}

CustomIndexBody describes the custom index request payload

type Element

type Element struct {
	Resource Resource `json:"resource"`
}

Element is a FHIR element resource

type ErrorResponse

type ErrorResponse struct {
	Response *http.Response
	Message  string
}

ErrorResponse holds an error response from the server

func (*ErrorResponse) Error

func (e *ErrorResponse) Error() string

type LogData

type LogData struct {
	Message string `json:"message"`
}

LogData is the payload of a log message

type Resource

type Resource struct {
	ResourceType        string                 `json:"resourceType"`                  // LogEvent
	ID                  string                 `json:"id"`                            // 7f4c85a8-e472-479f-b772-2916353d02a4
	ApplicationName     string                 `json:"applicationName,omitempty"`     // OPS
	EventID             string                 `json:"eventId"`                       // 110114
	Category            string                 `json:"category,omitempty"`            // TRACELOG
	Component           string                 `json:"component,omitempty"`           // "TEST"
	TransactionID       string                 `json:"transactionId"`                 // 2abd7355-cbdd-43e1-b32a-43ec19cd98f0
	ServiceName         string                 `json:"serviceName,omitempty"`         // OPS
	ApplicationInstance string                 `json:"applicationInstance,omitempty"` // INST-00002
	ApplicationVersion  string                 `json:"applicationVersion,omitempty"`  // 1.0.0
	OriginatingUser     string                 `json:"originatingUser,omitempty"`     // SomeUser
	ServerName          string                 `json:"serverName,omitempty"`          // app.example.com
	LogTime             string                 `json:"logTime"`                       // 2017-01-31T08:00:00Z
	Severity            string                 `json:"severity"`                      // INFO
	TraceID             string                 `json:"traceId,omitempty"`             // xxx
	SpanID              string                 `json:"spanId,omitempty"`              // yyy
	LogData             LogData                `json:"logData"`                       // Log data
	Custom              json.RawMessage        `json:"custom,omitempty"`              // Custom log fields
	Meta                map[string]interface{} `json:"-"`
	Error               error                  `json:"-"`
}

Resource is a logging resource

func (*Resource) Valid

func (r *Resource) Valid() bool

Valid returns true if a resource is valid according to HSDP rules, false otherwise

type StoreResponse added in v0.15.0

type StoreResponse struct {
	*http.Response
	Message string
	Failed  []Resource
}

StoreResponse holds a LogEvent response

func (*StoreResponse) StatusCode added in v0.78.7

func (r *StoreResponse) StatusCode() int

type Storer

type Storer interface {
	StoreResources(msgs []Resource, count int) (*StoreResponse, error)
}

Storer defines the store operations for logging

Jump to

Keyboard shortcuts

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