cloudflare/cloudflared · error

unable to unmarshal LogLevel

Error message

unable to unmarshal LogLevel

What it means

Returned by LogLevel.UnmarshalJSON when the JSON value is a string but ParseLogLevel does not recognize it (not one of debug/info/warn/error). The payload is well-formed JSON but carries an unsupported level string, e.g. from a newer or misconfigured peer.

Source

Thrown at management/events.go:184

	default:
		return ""
	}
}

func (l LogLevel) MarshalJSON() ([]byte, error) {
	return json.Marshal(l.String())
}

func (l *LogLevel) UnmarshalJSON(data []byte) error {
	var s string
	if err := json.Unmarshal(data, &s); err != nil {
		return errors.New("unable to unmarshal LogLevel string")
	}
	if level, ok := ParseLogLevel(s); ok {
		*l = level
		return nil
	}
	return fmt.Errorf("unable to unmarshal LogLevel")
}

const (
	// TimeKey aligns with the zerolog.TimeFieldName
	TimeKey = "time"
	// LevelKey aligns with the zerolog.LevelFieldName
	LevelKey = "level"
	// LevelKey aligns with the zerolog.MessageFieldName
	MessageKey = "message"
	// EventTypeKey is the custom JSON key of the LogEventType in ZeroLogEvent
	EventTypeKey = "event"
	// FieldsKey is a custom JSON key to match and store every other key for a zerolog event
	FieldsKey = "fields"
)

// Log is the basic structure of the events that are sent to the client.
type Log struct {
	Time    string                 `json:"time,omitempty"`

View on GitHub (pinned to 2253eeeb25)

Solutions

  1. Check the exact level string in the incoming management event payload.
  2. Only debug, info, warn, and error are accepted by ParseLogLevel.
  3. Update cloudflared if the peer uses a level added in a newer protocol version.
Defensive patterns

Strategy: type-guard

When it happens

Trigger: Thrown at management/events.go:184 when the library encounters an invalid state.

Common situations: See trigger scenarios.


AI-assisted analysis of cloudflare/cloudflared@2253eeeb25 (2026-09-06). Data as JSON: /api/errors/ebb73e3d9393c56f. Report an issue: GitHub.