Skip to content

Commit

Permalink
Extract logging options from the RemoteControlConfiguration, removing…
Browse files Browse the repository at this point in the history
… a dependency on RC code from the remote webdriver server
  • Loading branch information
shs96c committed Mar 4, 2013
1 parent e84ab8e commit b2e9ecb
Show file tree
Hide file tree
Showing 9 changed files with 133 additions and 106 deletions.
2 changes: 1 addition & 1 deletion .idea/libraries/bouncycastle.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion .idea/libraries/operadriver.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

42 changes: 2 additions & 40 deletions android/gen/org/openqa/selenium/android/app/R.java
Original file line number Diff line number Diff line change
@@ -1,43 +1,5 @@
/* AUTO-GENERATED FILE. DO NOT MODIFY.
*
* This class was automatically generated by the
* aapt tool from the resource data it found. It
* should not be modified by hand.
*/

package org.openqa.selenium.android.app;

/* This stub is for using by IDE only. It is NOT the R class actually packed into APK */
public final class R {
public static final class attr {
}
public static final class drawable {
public static final int alert_dialog_icon=0x7f020000;
public static final int ic_menu_add=0x7f020001;
public static final int ic_menu_delete=0x7f020002;
public static final int ic_menu_share=0x7f020003;
public static final int selenium_icon=0x7f020004;
}
public static final class id {
public static final int rssWebView=0x7f060002;
public static final int status=0x7f060000;
public static final int webview=0x7f060001;
}
public static final class layout {
public static final int single_session_layout=0x7f030000;
}
public static final class string {
public static final int app_name=0x7f050009;
public static final int ctx_menu_navigate=0x7f050001;
public static final int default_session_status=0x7f050002;
public static final int httpd_already_started=0x7f050005;
public static final int httpd_not_running=0x7f050008;
public static final int httpd_not_started=0x7f050004;
public static final int httpd_not_stopped=0x7f050007;
public static final int httpd_started=0x7f050003;
public static final int httpd_stopped=0x7f050006;
public static final int main_title=0x7f050000;
}
public static final class xml {
public static final int preferences=0x7f040000;
}
}
}
2 changes: 1 addition & 1 deletion android/project.properties
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,4 @@
# project structure.

# Project target.
target=android-16
target=android-15
34 changes: 17 additions & 17 deletions java/server/src/org/openqa/grid/web/Hub.java
Original file line number Diff line number Diff line change
Expand Up @@ -17,19 +17,6 @@

package org.openqa.grid.web;

import java.io.File;
import java.io.IOException;
import java.net.MalformedURLException;
import java.net.URL;
import java.util.Map;
import java.util.logging.ConsoleHandler;
import java.util.logging.FileHandler;
import java.util.logging.Handler;
import java.util.logging.Level;
import java.util.logging.Logger;

import javax.servlet.Servlet;

import com.google.common.collect.Maps;

import org.openqa.grid.internal.Registry;
Expand All @@ -45,12 +32,25 @@
import org.openqa.grid.web.servlet.ResourceServlet;
import org.openqa.grid.web.servlet.TestSessionStatusServlet;
import org.openqa.grid.web.utils.ExtraServletUtil;
import org.openqa.selenium.net.NetworkUtils;
import org.openqa.selenium.server.log.LoggingOptions;
import org.openqa.selenium.server.log.TerseFormatter;
import org.seleniumhq.jetty7.server.Server;
import org.seleniumhq.jetty7.server.bio.SocketConnector;
import org.seleniumhq.jetty7.servlet.ServletContextHandler;
import org.openqa.selenium.net.NetworkUtils;
import org.openqa.selenium.server.RemoteControlConfiguration;
import org.openqa.selenium.server.log.TerseFormatter;

import java.io.File;
import java.io.IOException;
import java.net.MalformedURLException;
import java.net.URL;
import java.util.Map;
import java.util.logging.ConsoleHandler;
import java.util.logging.FileHandler;
import java.util.logging.Handler;
import java.util.logging.Level;
import java.util.logging.Logger;

import javax.servlet.Servlet;

/**
* Jetty server. Main entry point for everything about the grid. <p/> Except for unit tests, this
Expand Down Expand Up @@ -90,7 +90,7 @@ public Hub(GridHubConfiguration config) {

String logFilename =
config.getLogFilename() == null
? RemoteControlConfiguration.getDefaultLogOutFile()
? LoggingOptions.getDefaultLogOutFile()
: config.getLogFilename();
if (logFilename != null) {
try {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
import org.openqa.selenium.Capabilities;
import org.openqa.selenium.remote.CapabilityType;
import org.openqa.selenium.remote.DesiredCapabilities;
import org.openqa.selenium.server.log.LoggingOptions;

import java.io.File;

Expand Down Expand Up @@ -67,18 +68,12 @@ public class RemoteControlConfiguration {
private String dontInjectRegex;
private File firefoxProfileTemplate;
private boolean reuseBrowserSessions;
private boolean captureLogsOnQuit;
private String logOutFileName;
private String forcedBrowserMode;
private boolean honorSystemProxy;
private int timeoutInSeconds;
private int browserTimeoutInMs;
private int retryTimeoutInSeconds;
/**
* useful for situations where Selenium is being invoked programatically and the outside container
* wants to own logging
*/
private boolean dontTouchLogging = false;
private LoggingOptions loggingOptions;
private boolean ensureCleanSession;
private boolean avoidProxy;
private boolean debugMode;
Expand All @@ -91,7 +86,6 @@ public class RemoteControlConfiguration {

public RemoteControlConfiguration() {
this.port = getDefaultPort();
this.logOutFileName = getDefaultLogOutFile();
this.profilesLocation = null;
this.proxyInjectionModeArg = false;
this.portDriversShouldContact = USE_SAME_PORT;
Expand All @@ -100,7 +94,7 @@ public RemoteControlConfiguration() {
this.debugURL = "";
this.dontInjectRegex = null;
this.firefoxProfileTemplate = null;
this.dontTouchLogging = false;
this.loggingOptions = new LoggingOptions();
}

public int getPort() {
Expand Down Expand Up @@ -243,37 +237,27 @@ public boolean reuseBrowserSessions() {
}

public void setCaptureLogsOnQuit(boolean captureLogs) {
captureLogsOnQuit = captureLogs;
loggingOptions.setCaptureLogsOnQuit(captureLogs);
}

public boolean isCaptureOfLogsOnQuitEnabled() {
return captureLogsOnQuit;
return loggingOptions.isCaptureOfLogsOnQuitEnabled();
}

public void setLogOutFileName(String newLogOutFileName) {
logOutFileName = newLogOutFileName;
loggingOptions.setLogOutFileName(newLogOutFileName);
}

public String getLogOutFileName() {
return logOutFileName;
return loggingOptions.getLogOutFileName();
}

public void setLogOutFile(File newLogOutFile) {
logOutFileName = (null == newLogOutFile) ? null : newLogOutFile.getAbsolutePath();
loggingOptions.setLogOutFile(newLogOutFile);
}

public File getLogOutFile() {
return (null == logOutFileName) ? null : new File(logOutFileName);
}

public static String getDefaultLogOutFile() {
final String logOutFileProperty;

logOutFileProperty = System.getProperty("selenium.LOGGER");
if (null == logOutFileProperty) {
return null;
}
return new File(logOutFileProperty).getAbsolutePath();
return loggingOptions.getLogOutFile();
}

public void setForcedBrowserMode(String newForcedBrowserMode) {
Expand Down Expand Up @@ -335,15 +319,15 @@ public void setRetryTimeoutInSeconds(int newRetryTimeoutInSeconds) {
}

public boolean dontTouchLogging() {
return dontTouchLogging;
return loggingOptions.dontTouchLogging();
}

public void setDontTouchLogging(boolean newValue) {
this.dontTouchLogging = newValue;
loggingOptions.setDontTouchLogging(newValue);
}

public int shortTermMemoryLoggerCapacity() {
return 30;
return loggingOptions.shortTermMemoryLoggerCapacity();
}


Expand Down Expand Up @@ -421,4 +405,8 @@ private void setSafely(DesiredCapabilities caps, String key, Object value) {

caps.setCapability(key, value);
}

public LoggingOptions getLoggingOptions() {
return loggingOptions;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -269,7 +269,7 @@ public SeleniumServer(boolean slowResources, RemoteControlConfiguration configur
this.configuration = configuration;
debugMode = configuration.isDebugMode();
jettyThreads = configuration.getJettyThreads();
LOGGER = LoggingManager.configureLogging(configuration, debugMode);
LOGGER = LoggingManager.configureLogging(configuration.getLoggingOptions(), debugMode);
logStartupInfo();
sanitizeProxyConfiguration();
createJettyServer(slowResources);
Expand Down
33 changes: 16 additions & 17 deletions java/server/src/org/openqa/selenium/server/log/LoggingManager.java
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@

import org.apache.commons.logging.Log;
import org.openqa.jetty.log.LogFactory;
import org.openqa.selenium.server.RemoteControlConfiguration;

import java.io.File;
import java.io.IOException;
Expand All @@ -47,28 +46,28 @@ public class LoggingManager {
private static PerSessionLogHandler perSessionLogHandler = new NoOpSessionLogHandler();


public static synchronized Log configureLogging(RemoteControlConfiguration configuration,
public static synchronized Log configureLogging(LoggingOptions options,
boolean debugMode) {
final Log seleniumServerJettyLogger;
final Logger currentLogger;

if (configuration.dontTouchLogging()) {
if (options.dontTouchLogging()) {
return LogFactory.getLog("org.openqa.selenium.server.SeleniumServer");
}

currentLogger = Logger.getLogger("");
resetLoggerToOriginalState();
overrideSimpleFormatterWithTerseOneForConsoleHandler(currentLogger, debugMode);
addInMemoryLogger(currentLogger, configuration);
addPerSessionLogger(currentLogger, configuration, debugMode);
addInMemoryLogger(currentLogger, options);
addPerSessionLogger(currentLogger, options, debugMode);
if (debugMode) {
currentLogger.setLevel(Level.FINE);
}

seleniumServerJettyLogger = LogFactory.getLog("org.openqa.selenium.server.SeleniumServer");
if (null != configuration.getLogOutFile()) {
addNewSeleniumFileHandler(currentLogger, configuration);
seleniumServerJettyLogger.info("Writing debug logs to " + configuration.getLogOutFile());
if (null != options.getLogOutFile()) {
addNewSeleniumFileHandler(currentLogger, options);
seleniumServerJettyLogger.info("Writing debug logs to " + options.getLogOutFile());
}

return seleniumServerJettyLogger;
Expand All @@ -86,33 +85,33 @@ public static synchronized PerSessionLogHandler perSessionLogHandler() {
return perSessionLogHandler;
}

private static void addInMemoryLogger(Logger logger, RemoteControlConfiguration configuration) {
private static void addInMemoryLogger(Logger logger, LoggingOptions options) {
shortTermMemoryHandler = new ShortTermMemoryHandler(
configuration.shortTermMemoryLoggerCapacity(), Level.INFO, new TerseFormatter(true));
options.shortTermMemoryLoggerCapacity(), Level.INFO, new TerseFormatter(true));
logger.addHandler(shortTermMemoryHandler);
}

private static void addPerSessionLogger(Logger logger,
RemoteControlConfiguration configuration, boolean debugMode) {
LoggingOptions options, boolean debugMode) {
if (debugMode) {
perSessionLogHandler =
new DefaultPerSessionLogHandler(configuration.shortTermMemoryLoggerCapacity(),
Level.FINE, new TerseFormatter(true), configuration.isCaptureOfLogsOnQuitEnabled());
new DefaultPerSessionLogHandler(options.shortTermMemoryLoggerCapacity(),
Level.FINE, new TerseFormatter(true), options.isCaptureOfLogsOnQuitEnabled());
} else {
perSessionLogHandler =
new DefaultPerSessionLogHandler(configuration.shortTermMemoryLoggerCapacity(),
Level.INFO, new TerseFormatter(true), configuration.isCaptureOfLogsOnQuitEnabled());
new DefaultPerSessionLogHandler(options.shortTermMemoryLoggerCapacity(),
Level.INFO, new TerseFormatter(true), options.isCaptureOfLogsOnQuitEnabled());
}
logger.addHandler(perSessionLogHandler);
}

private static File addNewSeleniumFileHandler(Logger currentLogger,
RemoteControlConfiguration configuration) {
LoggingOptions options) {
try {
FileHandler fileHandler;
final File logFile;

logFile = configuration.getLogOutFile();
logFile = options.getLogOutFile();
fileHandler = seleniumFileHandlers.get(logFile);
if (fileHandler == null) {
fileHandler = registerNewSeleniumFileHandler(logFile);
Expand Down
Loading

0 comments on commit b2e9ecb

Please sign in to comment.