Class Event

  • Direct Known Subclasses:
    Event0, Event1, Event2, Event3

    public abstract class Event
    extends Object
    Represents an event of a program execution that can be logged. Examples of events that can be modeled by instances of this class are
    • the application start;
    • the operation to be performed by a class completes abruptly because of exception e; and
    • the service implemented by a class receives a message with values x and y.

    This class represents the event specification, not the event instance; a logging message is an invocation of instances of this class. From this, a logging message is (logically) composed of a logging event (instances of this class) and zero or more arguments.

    As an example, suppose that you want to log the successful GET responses of a HTTP server. The log message should contain the client's IP address, the path name of the resource and the total number of bytes sents. The following could be the event specification

     Event3<InetAddress, String, Integer> GET_OK = Events.info(
         HttpServer.class, "HTTP_GET_OK", InetAddress.class, String.class, Integer.class
     );

    While the invocation of this event, i.e., the actual log message would be in the form

     logger.log(GET_OK, clientAddress, pathName, bytes.length);
    Therefore, an Event instance indicates:
    • the source of a log message. The source is the class from which a log message originated;
    • the level of a log message;
    • the key of the event. The event key is a name that uniquely identifies the event within a source. It also serves as a description of the event itself; and
    • the number and the types of the arguments that should be supplied to a Logger instance when invoking this event.
    Since:
    2
    • Method Detail

      • equals

        public final boolean equals​(Object obj)

        Compares the specified object with this event for equality. Returns true if and only if

        • the specified object is also a Event;
        • the specified object is of the same subclass of Event;
        • both events have keys that are equal to each other; and
        • both events have source classes that are equal to each other.
        Overrides:
        equals in class Object
        Parameters:
        obj - the object to be compared for equality with this event
        Returns:
        true if the specified object is equal to this event
      • getKey

        public final String getKey()
        Returns the key of this event.
        Returns:
        the key of this event
      • getLevel

        public final Level getLevel()
        Returns the logging level of this event.
        Returns:
        the logging level of this event
      • getSource

        public final Class<?> getSource()
        Returns the source class of this event.
        Returns:
        the source class of this event
      • hashCode

        public final int hashCode()
        Returns the hash code value of this event.
        Overrides:
        hashCode in class Object
        Returns:
        the hash code value of this event
      • isEnabled

        public final boolean isEnabled​(Level level)
        Returns true if this event would be logged at the specified level.
        Parameters:
        level - the level to check against
        Returns:
        true if this event would be logged at the specified level
      • toString

        public final String toString()
        Returns a string representation of this event.
        Overrides:
        toString in class Object
        Returns:
        a string representation of this event