Class PerSessionLogHandler
- java.lang.Object
-
- java.util.logging.Handler
-
- org.openqa.selenium.remote.server.log.PerSessionLogHandler
-
public class PerSessionLogHandler extends java.util.logging.Handler
RestishHandler which keeps in memory the log records per session so that users can retrieve logs per session.
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description protected static class
PerSessionLogHandler.ThreadKey
-
Constructor Summary
Constructors Constructor Description PerSessionLogHandler(int capacity, java.util.logging.Formatter formatter, boolean captureLogsOnQuit)
New handler keeping track of log records per session.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description 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, org.openqa.selenium.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.java.lang.String
getLog(org.openqa.selenium.remote.SessionId sessionId)
This returns Selenium Remote Control logs associated with the sessionId.java.util.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(java.util.logging.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)
-
-
-
Constructor Detail
-
PerSessionLogHandler
public PerSessionLogHandler(int capacity, java.util.logging.Formatter formatter, boolean captureLogsOnQuit)
New handler keeping track of log records per session.- Parameters:
capacity
- The capacityformatter
- Formatter to use when retrieving log messages.captureLogsOnQuit
- Whether to enable log capture on quit.
-
-
Method Detail
-
attachToCurrentThread
public void attachToCurrentThread(org.openqa.selenium.remote.SessionId sessionId)
-
transferThreadTempLogsToSessionLogs
public void transferThreadTempLogsToSessionLogs(org.openqa.selenium.remote.SessionId sessionId)
-
detachFromCurrentThread
public void detachFromCurrentThread()
-
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.- 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.
-
getLog
public java.lang.String getLog(org.openqa.selenium.remote.SessionId sessionId) throws java.io.IOException
This returns Selenium Remote Control logs associated with the sessionId.- Parameters:
sessionId
- session-id for which the RC logs will be returned.- Returns:
- String RC logs for the sessionId
- Throws:
java.io.IOException
- when the elves go bad
-
getLoggedSessions
public java.util.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.- 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.- Parameters:
sessionId
- The id of the session.- Returns:
- The logs for the session, ordered after log types in a session logs object.
-
getSessionLog
public org.openqa.selenium.logging.LogEntries getSessionLog(org.openqa.selenium.remote.SessionId sessionId) throws java.io.IOException
Returns the server log for the given session id.- Parameters:
sessionId
- The session id.- Returns:
- The available server log entries for the session.
- Throws:
java.io.IOException
- If there was a problem reading from file.
-
fetchAndStoreLogsFromDriver
public void fetchAndStoreLogsFromDriver(org.openqa.selenium.remote.SessionId sessionId, org.openqa.selenium.WebDriver driver) throws java.io.IOException
Fetches and stores available logs from the given session and driver.- Parameters:
sessionId
- The id of the session.driver
- The driver to get the logs from.- Throws:
java.io.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.- Parameters:
prefs
- The logging preferences object.
-
publish
public void publish(java.util.logging.LogRecord record)
- Specified by:
publish
in classjava.util.logging.Handler
-
flush
public void flush()
- Specified by:
flush
in classjava.util.logging.Handler
-
close
public void close() throws java.lang.SecurityException
- Specified by:
close
in classjava.util.logging.Handler
- Throws:
java.lang.SecurityException
-
-