logger.go 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  1. package storageos
  2. import (
  3. "context"
  4. "encoding/json"
  5. "net/url"
  6. "github.com/storageos/go-api/types"
  7. )
  8. var (
  9. // LoggerAPIPrefix is a partial path to the HTTP endpoint.
  10. LoggerAPIPrefix = "logs"
  11. )
  12. // LoggerConfig returns every cluster node's logging configuration.
  13. func (c *Client) LoggerConfig(opts types.ListOptions) ([]*types.Logger, error) {
  14. listOpts := doOptions{
  15. fieldSelector: opts.FieldSelector,
  16. labelSelector: opts.LabelSelector,
  17. context: opts.Context,
  18. }
  19. if opts.LabelSelector != "" {
  20. query := url.Values{}
  21. query.Add("labelSelector", opts.LabelSelector)
  22. listOpts.values = query
  23. }
  24. resp, err := c.do("GET", LoggerAPIPrefix+"/cluster/config", listOpts)
  25. if err != nil {
  26. return nil, err
  27. }
  28. defer resp.Body.Close()
  29. var loggers []*types.Logger
  30. if err := json.NewDecoder(resp.Body).Decode(&loggers); err != nil {
  31. return nil, err
  32. }
  33. return loggers, nil
  34. }
  35. // LoggerUpdate patches updates to logging configuration. Fields to update must
  36. // be listed in the Fields value, and if a list of Nodes is given it will only
  37. // apply to the nodes listed. Returns the updated configuration.
  38. func (c *Client) LoggerUpdate(opts types.LoggerUpdateOptions) ([]*types.Logger, error) {
  39. resp, err := c.do("PATCH", LoggerAPIPrefix+"/cluster/config", doOptions{
  40. data: opts,
  41. context: context.Background(),
  42. })
  43. if err != nil {
  44. return nil, err
  45. }
  46. defer resp.Body.Close()
  47. var loggers []*types.Logger
  48. if err := json.NewDecoder(resp.Body).Decode(&loggers); err != nil {
  49. return nil, err
  50. }
  51. return loggers, nil
  52. }