Package com.yahoo.log

Class LogMessage


  • public class LogMessage
    extends java.lang.Object
    This class implements the common ground log message used by the logserver. A LogMessage is immutable. Note that we have chosen the name LogMessage to avoid confusion with LogRecord which is used in java.util.logging.
    Author:
    Bjorn Borud, bjorncs
    • Method Detail

      • of

        public static LogMessage of​(java.time.Instant time,
                                    java.lang.String host,
                                    long processId,
                                    long threadId,
                                    java.lang.String service,
                                    java.lang.String component,
                                    java.util.logging.Level level,
                                    java.lang.String payload)
      • getTimestamp

        public java.time.Instant getTimestamp()
      • getTime

        @Deprecated(since="7",
                    forRemoval=true)
        public long getTime()
        Deprecated, for removal: This API element is subject to removal in a future version.
      • getTimeInSeconds

        @Deprecated(since="7",
                    forRemoval=true)
        public long getTimeInSeconds()
        Deprecated, for removal: This API element is subject to removal in a future version.
      • getHost

        public java.lang.String getHost()
      • getProcessId

        public long getProcessId()
      • getThreadId

        public java.util.OptionalLong getThreadId()
      • getThreadProcess

        @Deprecated(since="7",
                    forRemoval=true)
        public java.lang.String getThreadProcess()
        Deprecated, for removal: This API element is subject to removal in a future version.
      • getService

        public java.lang.String getService()
      • getComponent

        public java.lang.String getComponent()
      • getLevel

        public java.util.logging.Level getLevel()
      • getPayload

        public java.lang.String getPayload()
      • parseNativeFormat

        public static LogMessage parseNativeFormat​(java.lang.String msg)
                                            throws InvalidLogFormatException
        Make a log message from the native format of the logging package.
        Parameters:
        msg - The log message
        Returns:
        Returns a LogMessage instance
        Throws:
        InvalidLogFormatException - if the log message can not be parsed, ie. is invalid, we throw this exception.
      • getEvent

        public Event getEvent()
                       throws MalformedEventException
        If the LogMessage was an EVENT then this method can be used to get the Event instance representing the event. The event instance created the first time this method is called and then cached. TODO: make sure this throws exception!
        Returns:
        Returns Event instance if this is an event message and the payload is correctly formatted. Otherwise it will return null.
        Throws:
        MalformedEventException
      • toString

        public java.lang.String toString()
        Return valid representation of log message.
        Overrides:
        toString in class java.lang.Object
      • equals

        public boolean equals​(java.lang.Object o)
        Overrides:
        equals in class java.lang.Object
      • hashCode

        public int hashCode()
        Overrides:
        hashCode in class java.lang.Object