- java.lang.Object
-
- br.com.objectos.logging.Event
-
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
xandy.
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, anEventinstance indicates:- the
sourceof a log message. Thesourceis the class from which a log message originated; - the
levelof a log message; - the
keyof the event. The event key is a name that uniquely identifies the event within asource. 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
Loggerinstance when invoking this event.
- Since:
- 2
-
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description booleanequals(Object obj)Compares the specified object with this event for equality.StringgetKey()Returns the key of this event.LevelgetLevel()Returns the logging level of this event.Class<?>getSource()Returns the source class of this event.inthashCode()Returns the hash code value of this event.booleanisEnabled(Level level)Returnstrueif this event would be logged at the specifiedlevel.StringtoString()Returns a string representation of this event.
-
-
-
Method Detail
-
equals
public final boolean equals(Object obj)
Compares the specified object with this event for equality. Returns
trueif 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.
- the specified object is also a
-
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.
-
isEnabled
public final boolean isEnabled(Level level)
Returnstrueif this event would be logged at the specifiedlevel.- Parameters:
level- the level to check against- Returns:
trueif this event would be logged at the specifiedlevel
-
-