com.tenduke.diagnostics
Class LogEntry

java.lang.Object
  extended by com.tenduke.diagnostics.LogEntry

public class LogEntry
extends java.lang.Object

Class that represents an application event that needs to be logged.

A log entry is composed of an LogEntry.EventType, LogEntry.DebugLevel, optional message and optional handle to related Exception / Throwable.

LogEntry.EventType defines the category in terms of severity.

LogEntry.DebugLevel defines the verbosity level of the log entry and is commonly used by LogEntrySubscribers to suppress the display / processing of log entries that exceed maximum configured verbosity level.


Nested Class Summary
static class LogEntry.DebugLevel
          Log entry debug level.
static class LogEntry.EventType
          Log entry categorization by event type: (info / warning / error).
 
Constructor Summary
LogEntry(LogEntry.EventType eventType, LogEntry.DebugLevel debugLevel, java.lang.String logMessage)
          Creates a new LogEntry with log message that describes the event.
LogEntry(LogEntry.EventType eventType, LogEntry.DebugLevel debugLevel, java.lang.String logMessage, java.lang.String category)
          Creates a new LogEntry with log message that describes the event.
LogEntry(LogEntry.EventType eventType, LogEntry.DebugLevel debugLevel, java.lang.String logMessage, java.lang.Throwable exception)
          Creates a new LogEntry with log message that describes the event and a related exception.
LogEntry(LogEntry.EventType eventType, LogEntry.DebugLevel debugLevel, java.lang.String logMessage, java.lang.Throwable exception, java.lang.String category)
          Creates a new LogEntry with log message that describes the event and a related exception.
LogEntry(LogEntry.EventType eventType, LogEntry.DebugLevel debugLevel, java.lang.Throwable exception)
          Creates a new LogEntry with log message that describes the event and a related exception.
LogEntry(LogEntry.EventType eventType, LogEntry.DebugLevel debugLevel, java.lang.Throwable exception, java.lang.String category)
          Creates a new LogEntry with log message that describes the event and a related exception.
 
Method Summary
 java.lang.String getCategory()
          Gets log entry category.
 LogEntry.DebugLevel getDebugLevel()
          Gets the debug level for this entry.
 LogEntry.EventType getEventType()
          Gets the event type set for this entry.
 java.lang.Throwable getException()
          Gets the exception set for this entry.
 java.lang.String getLogMessage()
          Gets the log message set for this entry.
 void print(java.lang.String formatString, java.io.Writer outWriter)
           Printing formatted log message.
 void setCategory(java.lang.String category)
          Sets log entry category.
 java.lang.String toString()
          Basic toString implementation.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

LogEntry

public LogEntry(LogEntry.EventType eventType,
                LogEntry.DebugLevel debugLevel,
                java.lang.String logMessage)
Creates a new LogEntry with log message that describes the event.

Parameters:
eventType - Log entry categorization by event type (info / warning / error)
debugLevel - Debug level (1-5): 1 is for the most critical stuff, 5 for very verbose debug output only.
logMessage - Message describing the log event

LogEntry

public LogEntry(LogEntry.EventType eventType,
                LogEntry.DebugLevel debugLevel,
                java.lang.String logMessage,
                java.lang.String category)
Creates a new LogEntry with log message that describes the event.

Parameters:
eventType - Log entry categorization by event type (info / warning / error)
debugLevel - Debug level (1-5): 1 is for the most critical stuff, 5 for very verbose debug output only.
logMessage - Message describing the log event
category - Category of the LogEntry that may be used by LogEntrySubscribes to direct LogEntries to different log files etc. For instance, different extensions may define their own categories. Null category is the default category.

LogEntry

public LogEntry(LogEntry.EventType eventType,
                LogEntry.DebugLevel debugLevel,
                java.lang.String logMessage,
                java.lang.Throwable exception)
Creates a new LogEntry with log message that describes the event and a related exception.

Parameters:
eventType - Log entry categorization by event type (info / warning / error)
debugLevel - Debug level (1-5): 1 is for the most critical stuff, 5 for very verbose debug output only.
logMessage - Message describing the log event
exception - Exception related to the event

LogEntry

public LogEntry(LogEntry.EventType eventType,
                LogEntry.DebugLevel debugLevel,
                java.lang.String logMessage,
                java.lang.Throwable exception,
                java.lang.String category)
Creates a new LogEntry with log message that describes the event and a related exception.

Parameters:
eventType - Log entry categorization by event type (info / warning / error)
debugLevel - Debug level (1-5): 1 is for the most critical stuff, 5 for very verbose debug output only.
logMessage - Message describing the log event
exception - Exception related to the event
category - Category of the LogEntry that may be used by LogEntrySubscribes to direct LogEntries to different log files etc. For instance, different extensions may define their own categories. Null category is the default category.

LogEntry

public LogEntry(LogEntry.EventType eventType,
                LogEntry.DebugLevel debugLevel,
                java.lang.Throwable exception)
Creates a new LogEntry with log message that describes the event and a related exception.

Parameters:
eventType - Log entry categorization by event type (info / warning / error)
debugLevel - Debug level (1-5): 1 is for the most critical stuff, 5 for very verbose debug output only.
exception - Exception related to the event

LogEntry

public LogEntry(LogEntry.EventType eventType,
                LogEntry.DebugLevel debugLevel,
                java.lang.Throwable exception,
                java.lang.String category)
Creates a new LogEntry with log message that describes the event and a related exception.

Parameters:
eventType - Log entry categorization by event type (info / warning / error)
debugLevel - Debug level (1-5): 1 is for the most critical stuff, 5 for very verbose debug output only.
exception - Exception related to the event
category - Category of the LogEntry that may be used by LogEntrySubscribes to direct LogEntries to different log files etc. For instance, different extensions may define their own categories. Null category is the default category.
Method Detail

getCategory

public java.lang.String getCategory()
Gets log entry category.

Returns:
Category of the LogEntry that may be used by LogEntrySubscribes to direct LogEntries to different log files etc. For instance, different extensions may define their own categories. Null category is the default category.

getDebugLevel

public LogEntry.DebugLevel getDebugLevel()
Gets the debug level for this entry.

Returns:
The debug level set for this entry.

getEventType

public LogEntry.EventType getEventType()
Gets the event type set for this entry.

Returns:
The event type set for this entry.

getException

public java.lang.Throwable getException()
Gets the exception set for this entry.

Returns:
The exception set for this entry.

getLogMessage

public java.lang.String getLogMessage()
Gets the log message set for this entry.

Returns:
The log message set for this entry.

print

public void print(java.lang.String formatString,
                  java.io.Writer outWriter)
           throws java.io.IOException

Printing formatted log message.

Supported format modifiers:

  1. {0}: Timestamp of the log entry (printed in ISO 8601 format)
  2. {1}: Event type of the log entry as string ("Error" / "Warning" / "Info")
  3. {2}: Log entry debug level (number 1 - 5)
  4. {3}: Log entry message
  5. {4}: Message of exception attached to the log entry
  6. {5}: Stack trace of exception attached to the log entry

Parameters:
formatString - The string to format (may include format specifiers).
outWriter - Where output goes.
Throws:
java.io.IOException - if an error occurred when writing to outWriter

setCategory

public void setCategory(java.lang.String category)
Sets log entry category.

Parameters:
category - Category of the LogEntry that may be used by LogEntrySubscribes to direct LogEntries to different log files etc. For instance, different extensions may define their own categories. Null category is the default category.

toString

public java.lang.String toString()
Basic toString implementation.

Overrides:
toString in class java.lang.Object
Returns:
String value based on the combination and availability of log message and exception member fields.