Select the log types you want and also the log level, below is the code I used:
LoggingPreferences logs = new LoggingPreferences();
logs.enable(LogType.BROWSER, Level.ALL);
logs.enable(LogType.CLIENT, Level.ALL);
logs.enable(LogType.DRIVER, Level.ALL);
logs.enable(LogType.PERFORMANCE, Level.ALL);
logs.enable(LogType.PROFILER, Level.ALL);
logs.enable(LogType.SERVER, Level.ALL);
DesiredCapabilities desiredCapabilities = DesiredCapabilities.firefox();
desiredCapabilities.setCapability(CapabilityType.LOGGING_PREFS, logs);
WebDriver driver = new FirefoxDriver(desiredCapabilities);
After running the test you can collect the logs,as shown:
Logs logs = driver.manage().logs();
LogEntries logEntries = logs.get(LogType.DRIVER);
for (LogEntry logEntry : logEntries) {
System.out.println(logEntry.getMessage());
}