Record Class AlertEvent

java.lang.Object
java.lang.Record
io.github.pimak.ntfy.core.AlertEvent
Record Components:
loggerName - the name of the logger that produced the event
formattedMessage - the fully rendered log message (arguments already substituted)
timestampMillis - event time as epoch milliseconds
causeChain - the full exception chain surface→root, each element as a (className, message) pair; empty when the event carries no throwable
rootCauseFrames - the ROOT cause's stack frames pre-rendered as strings (the StackTraceElement.toString() form), UNLIMITED here — the engine applies maxStackFrames; empty when the event carries no throwable
markerNames - the SLF4J marker names attached to the event (flattened, including composite children); empty on frameworks without markers (e.g. JUL)
mdcValues - the ALLOW-LISTED MDC entries only, in configured order, already scrubbed/truncated/capped by MdcProjector — adapters must project via MdcProjector.project(java.util.List<java.lang.String>, java.util.function.Function<java.lang.String, java.lang.String>) and never pass a raw MDC map; empty on frameworks with no MDC (plain JUL) and whenever include-mdc-keys is unset
level - the route this event belongs to; null is normalized to AlertLevel.ERROR

public record AlertEvent(String loggerName, String formattedMessage, long timestampMillis, List<AlertEvent.Cause> causeChain, List<String> rootCauseFrames, Set<String> markerNames, Map<String,String> mdcValues, AlertLevel level) extends Record
Framework-neutral snapshot of a single log event, handed to AlertEngine.submit(io.github.pimak.ntfy.core.AlertEvent). Every field is a plain JDK type so any logging-framework adapter (logback, log4j2, JUL, ...) can assemble one without leaking a framework-specific event type into core.
  • Constructor Details

    • AlertEvent

      public AlertEvent(String loggerName, String formattedMessage, long timestampMillis, List<AlertEvent.Cause> causeChain, List<String> rootCauseFrames, Set<String> markerNames, Map<String,String> mdcValues, AlertLevel level)
      Validates the mandatory fields and normalizes the optional collections so every construction path — direct new, the of(java.lang.String, java.lang.String, long) factory, or an adapter — yields a null-free, defensively copied event.

      mdcValues is re-run through MdcProjector.sanitize(java.util.Map<java.lang.String, java.lang.String>) rather than merely copied: that call is null-safe, order-preserving, and idempotent, so a projection an adapter already produced passes through untouched while an event hand-built by a third party that handed over a raw MDC map is still capped, scrubbed, and truncated here. Only the allow-list SELECTION is the adapter's job; the safety of what ends up in a body is enforced at this boundary.

      A null level normalizes to AlertLevel.ERROR, never AlertLevel.WARN: an adapter (or third-party caller) that omits the field must fall back to the always-on route, not silently divert its events onto the opt-in quiet channel.

    • AlertEvent

      public AlertEvent(String loggerName, String formattedMessage, long timestampMillis, List<AlertEvent.Cause> causeChain, List<String> rootCauseFrames, Set<String> markerNames, Map<String,String> mdcValues)
      The pre-level signature, kept as an explicit constructor for compatibility, exactly like the pre-mdcValues one below: preserving the (String, String, long, List, List, Set, Map) descriptor keeps adapters compiled against an earlier release both source- AND binary-compatible. Delegates at AlertLevel.ERROR, which is the only level those callers could ever have meant.
    • AlertEvent

      public AlertEvent(String loggerName, String formattedMessage, long timestampMillis, List<AlertEvent.Cause> causeChain, List<String> rootCauseFrames, Set<String> markerNames)
      The pre-mdcValues canonical signature, kept as an explicit constructor for compatibility: AlertEvent is public API, and preserving the original (String, String, long, List, List, Set) descriptor keeps adapters compiled against an earlier release both source- AND binary-compatible — they keep linking without recompilation. Delegates with an empty MDC map at AlertLevel.ERROR, which is exactly the behavior those callers already had.
  • Method Details

    • of

      public static AlertEvent of(String loggerName, String formattedMessage, long timestampMillis)
      Convenience factory for the "no throwable, no markers" case: causeChain, rootCauseFrames, markerNames and mdcValues default to empty collections, and the event is an AlertLevel.ERROR one.
    • withLevel

      public AlertEvent withLevel(AlertLevel level)
      Returns a copy of this event on level, leaving every other component untouched. Lets an adapter build the event once and then stamp the route onto it, rather than threading the level through every mapper signature.
    • toString

      public final String toString()
      Returns a string representation of this record class. The representation contains the name of the class, followed by the name and value of each of the record components.
      Specified by:
      toString in class Record
      Returns:
      a string representation of this object
    • hashCode

      public final int hashCode()
      Returns a hash code value for this object. The value is derived from the hash code of each of the record components.
      Specified by:
      hashCode in class Record
      Returns:
      a hash code value for this object
    • equals

      public final boolean equals(Object o)
      Indicates whether some other object is "equal to" this one. The objects are equal if the other object is of the same class and if all the record components are equal. Reference components are compared with Objects::equals(Object,Object); primitive components are compared with '=='.
      Specified by:
      equals in class Record
      Parameters:
      o - the object with which to compare
      Returns:
      true if this object is the same as the o argument; false otherwise.
    • loggerName

      public String loggerName()
      Returns the value of the loggerName record component.
      Returns:
      the value of the loggerName record component
    • formattedMessage

      public String formattedMessage()
      Returns the value of the formattedMessage record component.
      Returns:
      the value of the formattedMessage record component
    • timestampMillis

      public long timestampMillis()
      Returns the value of the timestampMillis record component.
      Returns:
      the value of the timestampMillis record component
    • causeChain

      public List<AlertEvent.Cause> causeChain()
      Returns the value of the causeChain record component.
      Returns:
      the value of the causeChain record component
    • rootCauseFrames

      public List<String> rootCauseFrames()
      Returns the value of the rootCauseFrames record component.
      Returns:
      the value of the rootCauseFrames record component
    • markerNames

      public Set<String> markerNames()
      Returns the value of the markerNames record component.
      Returns:
      the value of the markerNames record component
    • mdcValues

      public Map<String,String> mdcValues()
      Returns the value of the mdcValues record component.
      Returns:
      the value of the mdcValues record component
    • level

      public AlertLevel level()
      Returns the value of the level record component.
      Returns:
      the value of the level record component