appiumappium-androidappium-iosappium-desktop

how to generate logs in separate file when starting the appium server programmatically


With this code appium logs are printed in console, how to generate appium logs in a separate file.

public class TestBaseclass {
static AppiumDriverLocalService appiumService;

@BeforeClass
public static void startserver() throws Exception {
      appiumService = AppiumDriverLocalService.buildDefaultService();
        appiumService.start();
}

@AfterClass
public static void stopServer() throws Exception {
    
    System.out.println("Stop appium service");
    appiumService.stop();

}

Solution

  • /**
     * Configures the appium server to write log to the given file.
     *
     * @param logFile A file to write log to.
     * @return A self reference.
     */
    @Override
    public AppiumServiceBuilder withLogFile(File logFile) {
        return super.withLogFile(logFile);
    }
    

    https://github.com/appium/java-client/blob/master/src/main/java/io/appium/java_client/service/local/AppiumServiceBuilder.java

    AppiumServiceBuilder expose a method called withLogFile() that will write the logs into a given file.