Class LogEvent

java.lang.Object
org.jpos.util.LogEvent
Direct Known Subclasses:
FrozenLogEvent, MarkdownLogEvent

public class LogEvent extends Object
A single structured log event that carries a tag, realm, payload items, and optionally a Throwable.
  • Constructor Details

    • LogEvent

      public LogEvent(String tag)
      Constructs an empty event with the given tag.
      Parameters:
      tag - log tag (level/event name)
    • LogEvent

      public LogEvent()
      Default constructor; uses the info tag.
    • LogEvent

      public LogEvent(String tag, Object msg)
      Constructs an event with the given tag and an initial payload entry.
      Parameters:
      tag - log tag (level/event name)
      msg - initial payload entry
    • LogEvent

      public LogEvent(LogSource source, String tag)
      Constructs an event tied to a LogSource.
      Parameters:
      source - source whose logger and realm govern this event
      tag - log tag (level/event name)
    • LogEvent

      public LogEvent(LogSource source, String tag, Object msg)
      Constructs an event tied to a LogSource with an initial payload entry.
      Parameters:
      source - source whose logger and realm govern this event
      tag - log tag (level/event name)
      msg - initial payload entry
  • Method Details

    • getTag

      public String getTag()
      Returns the log tag.
      Returns:
      the event tag
    • setTag

      public void setTag(String tag)
      Sets the log tag for this event.
      Parameters:
      tag - the log tag to set
    • addMessage

      public void addMessage(Object msg)
      Adds a message or object to this event's payload.
      Parameters:
      msg - the message or object to add
    • addMessage

      public void addMessage(String tagname, String message)
      Adds a message wrapped in an XML tag to this event's payload.
      Parameters:
      tagname - the XML tag name to wrap the message in
      message - the message text
    • getSource

      public LogSource getSource()
      Returns the LogSource associated with this event, if any.
      Returns:
      the source, or null if not set
    • setSource

      public void setSource(LogSource source)
      Replaces the LogSource associated with this event.
      Parameters:
      source - new source (may be null)
    • setNoArmor

      public void setNoArmor(boolean noArmor)
      Controls whether the XML wrapper is suppressed in log output.
      Parameters:
      noArmor - if true, suppress the XML wrapper
    • dumpHeader

      protected String dumpHeader(PrintStream p, String indent)
      Writes the log event header to the given PrintStream.
      Parameters:
      p - the PrintStream to write the header to
      indent - the indentation prefix
      Returns:
      the inner indentation string for nested content
    • dumpTrailer

      protected void dumpTrailer(PrintStream p, String indent)
      Writes the log event trailer to the given PrintStream.
      Parameters:
      p - the PrintStream to write the trailer to
      indent - the indentation prefix
    • dump

      public void dump(PrintStream p, String outer)
      Dumps the full log event to the given PrintStream.
      Parameters:
      p - the PrintStream to dump to
      outer - the outer indentation string
    • getRealm

      public String getRealm()
      Returns the realm of the associated source, or empty when no source is set.
      Returns:
      the source's realm, or an empty string
    • withTraceId

      public LogEvent withTraceId(String traceId)
      Sets the trace-id tag explicitly.
      Parameters:
      traceId - trace identifier
      Returns:
      this event for chaining
    • withTraceId

      public LogEvent withTraceId(UUID uuid)
      Sets the trace-id tag from a UUID (dashes stripped).
      Parameters:
      uuid - trace UUID
      Returns:
      this event for chaining
    • withTag

      public LogEvent withTag(String key, String value)
      Adds or overwrites a tag on this event.
      Parameters:
      key - tag name
      value - tag value
      Returns:
      this event for chaining
    • withTags

      Adds the supplied tags to this event.
      Parameters:
      map - tags to add (ignored if null or empty)
      Returns:
      this event for chaining
    • getTags

      public Map<String,String> getTags()
      Returns an unmodifiable view of this event's tags.
      Returns:
      event tags, or an empty map if none have been set
    • withSource

      public LogEvent withSource(LogSource source)
      Sets the LogSource associated with this event and returns it for chaining.
      Parameters:
      source - new source
      Returns:
      this event for chaining
    • add

      public LogEvent add(Object o)
      Appends a payload entry and returns this event for chaining.
      Parameters:
      o - payload entry
      Returns:
      this event for chaining
    • withTraceId

      Ensures a trace-id tag is present, generating one if needed.
      Returns:
      this event for chaining
    • getTraceId

      public String getTraceId()
      Returns the current trace-id, generating one if absent.
      Returns:
      the trace-id (never null)
    • getPayLoad

      public List<Object> getPayLoad()
      WARNING: payLoad is a SynchronizedList. If you intend to get a reference to it in order to iterate over the list, you need to synchronize on the returned object.
          synchronized (evt.getPayLoad()) {
             Iterator iter = evt.getPayLoad().iterator();
             while (iter.hasNext()) {
                 ...
                 ...
      
             }
          }
      
      Returns:
      payLoad, which is a SynchronizedList
    • toString

      public String toString(String indent)
      Renders this event to a string with the given indent prefix.
      Parameters:
      indent - indent prefix to apply to every emitted line
      Returns:
      string rendering of this event
    • toString

      public String toString()
      Renders this event to a string with no leading indent.
      Overrides:
      toString in class Object
      Returns:
      string rendering of this event
    • hasException

      public boolean hasException()
      Indicates whether the payload contains a Throwable.
      Returns:
      true if any payload entry is a Throwable
    • isHonorSourceLogger

      public boolean isHonorSourceLogger()
      This is a hack for backward compatibility after accepting PR67
      Returns:
      true if ISOSource has been set
      See Also:
    • getDumpedAt

      public Instant getDumpedAt()
      Returns the time at which this event was first dumped, capturing it on first call.
      Returns:
      the dump timestamp
    • getCreatedAt

      Returns the time at which this event was constructed.
      Returns:
      the creation timestamp