com.splunk.modularinput
Class EventWriter

java.lang.Object
  extended by com.splunk.modularinput.EventWriter

public class EventWriter
extends java.lang.Object

The EventWriter class encapsulates writing events and error messages to Splunk from a modular input. Its two important methods are writeEvent, which takes an Event object, and log, which takes a severity and an error message.


Field Summary
static java.lang.String DEBUG
           
static java.lang.String ERROR
           
static java.lang.String FATAL
           
static java.lang.String INFO
           
static java.lang.String WARN
           
 
Constructor Summary
EventWriter()
           
EventWriter(java.io.Writer outputWriter, java.io.Writer errorWriter)
           
 
Method Summary
 boolean checkError()
          Returns whether there was an IOException on this EventWriter.
protected  void clearError()
          Clears the error state on this EventWriter.
 void close()
          Writes the closing </stream> tag to make this XML well formed.
 void log(java.lang.String severity, java.lang.String errorMessage)
          Logs messages about the state of this modular input to Splunk.
protected  void setError()
          Declares that this EventWriter had an IOException.
 void synchronizedLog(java.lang.String severity, java.lang.String errorMessage)
          Thread safe version of log.
 void synchronizedWriteEvent(Event event)
          Thread safe version of writeEvent.
 void writeEvent(Event event)
          Writes an Event object to Splunk.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

DEBUG

public static java.lang.String DEBUG

INFO

public static java.lang.String INFO

WARN

public static java.lang.String WARN

ERROR

public static java.lang.String ERROR

FATAL

public static java.lang.String FATAL
Constructor Detail

EventWriter

public EventWriter()
            throws javax.xml.stream.XMLStreamException
Throws:
javax.xml.stream.XMLStreamException

EventWriter

public EventWriter(java.io.Writer outputWriter,
                   java.io.Writer errorWriter)
            throws javax.xml.stream.XMLStreamException
Throws:
javax.xml.stream.XMLStreamException
Method Detail

clearError

protected void clearError()
Clears the error state on this EventWriter. EventWriter does not throw IOException errors, but does not ignore them entirely either. Instead it operates the same way as PrintStream in the standard library. You can always check if an IOException has been thrown by calling checkError.


setError

protected void setError()
Declares that this EventWriter had an IOException. EventWriter does not throw IOException errors, but does not ignore them entirely either. Instead it operates the same way as PrintStream in the standard library. You can always check if an IOException has been thrown by calling checkError.


checkError

public boolean checkError()
Returns whether there was an IOException on this EventWriter. EventWriter does not throw IOException errors, but does not ignore them entirely either. Instead it operates the same way as PrintStream in the standard library. You can always check if an IOException has been thrown by calling checkError.


synchronizedWriteEvent

public void synchronizedWriteEvent(Event event)
                            throws MalformedDataException
Thread safe version of writeEvent.

Throws:
MalformedDataException
See Also:
writeEvent(com.splunk.modularinput.Event)

writeEvent

public void writeEvent(Event event)
                throws MalformedDataException
Writes an Event object to Splunk. This method is not thread safe. If you need a thread safe version, use synchronizedWriteEvent. If you try to write an Event with null data, throws MalformedDataException.

Parameters:
event - The Event object to write.
Throws:
MalformedDataException
See Also:
synchronizedWriteEvent(com.splunk.modularinput.Event)

synchronizedLog

public void synchronizedLog(java.lang.String severity,
                            java.lang.String errorMessage)
Thread safe version of log.

See Also:
log(java.lang.String, java.lang.String)

log

public void log(java.lang.String severity,
                java.lang.String errorMessage)
Logs messages about the state of this modular input to Splunk. These messages will show up in Splunk's internal logs.

Parameters:
severity - The severity (e.g., EventWriter.WARN, EventWriter.FATAL) of this message.
errorMessage - The message that should appear in the logs.
See Also:
synchronizedLog(java.lang.String, java.lang.String)

close

public void close()
Writes the closing </stream> tag to make this XML well formed.