MCPcopy Create free account
hub / github.com/couchbase/sync_gateway / handleSetLogging

Method handleSetLogging

rest/admin_api.go:1582–1636  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

1580}
1581
1582func (h *handler) handleSetLogging() error {
1583 base.WarnfCtx(h.ctx(), "Using deprecated /_logging endpoint. Use /_config endpoints instead.")
1584
1585 body, err := h.readBody()
1586 if err != nil {
1587 return nil
1588 }
1589
1590 var newLogLevel base.LogLevel
1591 var setLogLevel bool
1592 if level := h.getQuery("logLevel"); level != "" {
1593 if err := newLogLevel.UnmarshalText([]byte(level)); err != nil {
1594 return base.NewHTTPError(http.StatusBadRequest, err.Error())
1595 }
1596 setLogLevel = true
1597 } else if level := h.getIntQuery("level", 0); level != 0 {
1598 base.WarnfCtx(h.ctx(), "Using deprecated query parameter: %q. Use %q instead.", "level", "logLevel")
1599 switch base.GetRestrictedInt(&level, 0, 1, 3, false) {
1600 case 1:
1601 newLogLevel = base.LevelInfo
1602 case 2:
1603 newLogLevel = base.LevelWarn
1604 case 3:
1605 newLogLevel = base.LevelError
1606 }
1607 setLogLevel = true
1608 }
1609
1610 if setLogLevel {
1611 base.InfofCtx(h.ctx(), base.KeyAll, "Setting log level to: %v", newLogLevel)
1612 base.ConsoleLogLevel().Set(newLogLevel)
1613
1614 // empty body is OK if request is just setting the log level
1615 if len(body) == 0 {
1616 return nil
1617 }
1618 }
1619
1620 var keys map[string]bool
1621 if err := base.JSONUnmarshal(body, &keys); err != nil {
1622
1623 // return a better error if a user is setting log level inside the body
1624 var logLevel map[string]string
1625 if err := base.JSONUnmarshal(body, &logLevel); err == nil {
1626 if _, ok := logLevel["logLevel"]; ok {
1627 return base.HTTPErrorf(http.StatusBadRequest, "Can't set log level in body, please use \"logLevel\" query parameter instead.")
1628 }
1629 }
1630
1631 return base.HTTPErrorf(http.StatusBadRequest, "Invalid JSON or non-boolean values for log key map")
1632 }
1633
1634 base.UpdateLogKeys(h.ctx(), keys, h.rq.Method == "PUT")
1635 return nil
1636}
1637
1638func (h *handler) handleSGCollectStatus() error {
1639 status := "stopped"

Callers

nothing calls this directly

Calls 15

ctxMethod · 0.95
readBodyMethod · 0.95
getQueryMethod · 0.95
UnmarshalTextMethod · 0.95
getIntQueryMethod · 0.95
WarnfCtxFunction · 0.92
NewHTTPErrorFunction · 0.92
GetRestrictedIntFunction · 0.92
InfofCtxFunction · 0.92
ConsoleLogLevelFunction · 0.92
JSONUnmarshalFunction · 0.92
HTTPErrorfFunction · 0.92

Tested by

no test coverage detected