org.openqa.selenium.server.log
Class DefaultPerSessionLogHandler

java.lang.Object
  extended by java.util.logging.Handler
      extended by org.openqa.selenium.server.log.PerSessionLogHandler
          extended by org.openqa.selenium.server.log.DefaultPerSessionLogHandler

public class DefaultPerSessionLogHandler
extends PerSessionLogHandler

RestishHandler which keeps in memory the log records per session so that users can retrieve logs per session.


Constructor Summary
DefaultPerSessionLogHandler(int capacity, Level minimumLevel, Formatter formatter, boolean captureLogsOnQuit)
          New handler keeping track of log records per session.
 
Method Summary
 void attachToCurrentThread(org.openqa.selenium.remote.SessionId sessionId)
           
 void clearThreadTempLogs()
          Clears the logging events attached to the thread.
 void close()
           
 void configureLogging(org.openqa.selenium.logging.LoggingPreferences prefs)
          Configures logging using a logging preferences object.
 void detachFromCurrentThread()
           
 void fetchAndStoreLogsFromDriver(org.openqa.selenium.remote.SessionId sessionId, WebDriver driver)
          Fetches and stores available logs from the given session and driver.
 void flush()
           
 org.openqa.selenium.logging.SessionLogs getAllLogsForSession(org.openqa.selenium.remote.SessionId sessionId)
          Gets all logs for a session.
 String getLog(org.openqa.selenium.remote.SessionId sessionId)
          This returns Selenium Remote Control logs associated with the sessionId.
 List<org.openqa.selenium.remote.SessionId> getLoggedSessions()
          Returns a list of session IDs for which there are logs.
 org.openqa.selenium.logging.LogEntries getSessionLog(org.openqa.selenium.remote.SessionId sessionId)
          Returns the server log for the given session id.
 void publish(LogRecord record)
           
 void removeSessionLogs(org.openqa.selenium.remote.SessionId sessionId)
          Removes session logs for the given session id.
 void transferThreadTempLogsToSessionLogs(org.openqa.selenium.remote.SessionId sessionId)
           
 
Methods inherited from class java.util.logging.Handler
getEncoding, getErrorManager, getFilter, getFormatter, getLevel, isLoggable, reportError, setEncoding, setErrorManager, setFilter, setFormatter, setLevel
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

DefaultPerSessionLogHandler

public DefaultPerSessionLogHandler(int capacity,
                                   Level minimumLevel,
                                   Formatter formatter,
                                   boolean captureLogsOnQuit)
New handler keeping track of log records per session.

Parameters:
capacity - The capacity
minimumLevel - Only keep track of records whose level is equal or greater than minimumLevel.
formatter - Formatter to use when retrieving log messages.
captureLogsOnQuit - Whether to enable log capture on quit.
Method Detail

publish

public void publish(LogRecord record)
Specified by:
publish in class PerSessionLogHandler

flush

public void flush()
Specified by:
flush in class Handler

close

public void close()
           throws SecurityException
Specified by:
close in class Handler
Throws:
SecurityException

attachToCurrentThread

public void attachToCurrentThread(org.openqa.selenium.remote.SessionId sessionId)
Specified by:
attachToCurrentThread in class PerSessionLogHandler

transferThreadTempLogsToSessionLogs

public void transferThreadTempLogsToSessionLogs(org.openqa.selenium.remote.SessionId sessionId)
Specified by:
transferThreadTempLogsToSessionLogs in class PerSessionLogHandler

detachFromCurrentThread

public void detachFromCurrentThread()
Specified by:
detachFromCurrentThread in class PerSessionLogHandler

removeSessionLogs

public void removeSessionLogs(org.openqa.selenium.remote.SessionId sessionId)
Removes session logs for the given session id. NB! If the handler has been configured to capture logs on quit no logs will be removed.

Specified by:
removeSessionLogs in class PerSessionLogHandler
Parameters:
sessionId - The session id to use.

clearThreadTempLogs

public void clearThreadTempLogs()
Clears the logging events attached to the thread. The logging is globally added to the jvm and is effectively used by both classic selenium and WebDriver. WebDriver must call this to avoid leaking memory, even though it is not really used. Ideally we should probably attach the *request* somewhere we could pick it up, so we could attach the pre-session logging to the request instead of the logging. Unfortunately this is no small task.

Specified by:
clearThreadTempLogs in class PerSessionLogHandler

getLog

public String getLog(org.openqa.selenium.remote.SessionId sessionId)
              throws IOException
This returns Selenium Remote Control logs associated with the sessionId.

Specified by:
getLog in class PerSessionLogHandler
Parameters:
sessionId - session-id for which the RC logs will be returned.
Returns:
String RC logs for the sessionId
Throws:
IOException - when the elves go bad

getSessionLog

public org.openqa.selenium.logging.LogEntries getSessionLog(org.openqa.selenium.remote.SessionId sessionId)
                                                     throws IOException
Returns the server log for the given session id.

Specified by:
getSessionLog in class PerSessionLogHandler
Parameters:
sessionId - The session id.
Returns:
The available server log entries for the session.
Throws:
IOException - If there was a problem reading from file.

getLoggedSessions

public List<org.openqa.selenium.remote.SessionId> getLoggedSessions()
Returns a list of session IDs for which there are logs. The type of logs that are available depends on the log types provided by the driver. An included session id will at least have server logs.

Specified by:
getLoggedSessions in class PerSessionLogHandler
Returns:
The list of session IDs.

getAllLogsForSession

public org.openqa.selenium.logging.SessionLogs getAllLogsForSession(org.openqa.selenium.remote.SessionId sessionId)
Gets all logs for a session.

Specified by:
getAllLogsForSession in class PerSessionLogHandler
Parameters:
sessionId - The id of the session.
Returns:
The logs for the session, ordered after log types in a session logs object.

fetchAndStoreLogsFromDriver

public void fetchAndStoreLogsFromDriver(org.openqa.selenium.remote.SessionId sessionId,
                                        WebDriver driver)
                                 throws IOException
Fetches and stores available logs from the given session and driver.

Specified by:
fetchAndStoreLogsFromDriver in class PerSessionLogHandler
Parameters:
sessionId - The id of the session.
driver - The driver to get the logs from.
Throws:
IOException - If there was a problem reading from file.

configureLogging

public void configureLogging(org.openqa.selenium.logging.LoggingPreferences prefs)
Configures logging using a logging preferences object.

Specified by:
configureLogging in class PerSessionLogHandler
Parameters:
prefs - The logging preferences object.


Copyright © 2013. All Rights Reserved.