java-client
java-client copied to clipboard
EBUSY: resource busy or locked; Not able to attach log to file
Description
Getting below issue:
Tried to attach logging to file 'D:\Automation-Framework\Generic\generic\Logs\Server.logs' but an error occurred: EBUSY: resource busy or locked, unlink 'D:\Automation-Framework\Generic\generic\Logs\Server.logs'
Environment
- Java client build version or git revision if you use some snapshot: 8.5.1
- Appium server version or git revision if you use some snapshot: 2.1.3
- Desktop OS/version used to run Appium if necessary: Windows 10
- Node.js version (unless using Appium.app|exe) or Appium CLI or Appium.app|exe: v18.18.0
- Mobile platform/version under test: Android
- Real device or emulator/simulator:
Details
I am starting and stopping the Appium server programmatically and this is working properly. The Appium logs displayed properly in console. but when tried to capture this log into file as that time I am getting error EBUSY: resource busy or locked. Folder Logs and file Server.logs is present.
Code To Reproduce Issue [ Good To Have ]
private AppiumDriverLocalService getAppiumDriverService() {
return AppiumDriverLocalService.buildService(new AppiumServiceBuilder()
.withIPAddress("127.0.0.1")
.usingPort(DEFAULT_APPIUM_SERVER_PORT)
.withArgument(GeneralServerFlag.BASEPATH, "/wd/hub/")
.withArgument(GeneralServerFlag.USE_DRIVERS, "UiAutomator2")
.withArgument(GeneralServerFlag.ALLOW_INSECURE, "adb_shell")
.withArgument(GeneralServerFlag.RELAXED_SECURITY)
.withArgument(GeneralServerFlag.USE_PLUGINS, "images")
.withArgument(GeneralServerFlag.SESSION_OVERRIDE)
.withArgument(GeneralServerFlag.LOG_LEVEL, "info")
.withLogFile(new File(System.getProperty("user.dir") + File.separator + "Logs" + File.separator + "Server.logs")));
}
Appium Server Log:
Tried to attach logging to file 'D:\Automation-Framework\Generic\generic\Logs\Server.logs' but an error occurred: EBUSY: resource busy or locked, unlink 'D:\Automation-Framework\Generic\generic\Logs\Server.logs'
[Appium] Attempting to load plugin images...
[Appium] Welcome to Appium v2.1.3
[Appium] Non-default server args:
[Appium] { address: '127.0.0.1',
[Appium] allowInsecure: [ 'adb_shell' ],
[Appium] basePath: '/wd/hub/',
[Appium] loglevel: 'info',
[Appium] relaxedSecurityEnabled: true,
[Appium] sessionOverride: true,
[Appium] useDrivers: [ 'UiAutomator2' ],
[Appium] usePlugins: [ 'images' ] }
[Appium] Appium REST http interface listener started on http://127.0.0.1:4723/wd/hub
[Appium] Available drivers:
[Appium] - [email protected] (automationName 'UiAutomator2')
[Appium] - [email protected] (automationName 'Espresso')
[Appium] Available plugins:
[Appium] - [email protected] (ACTIVE)
[Appium] - [email protected]
[HTTP] --> GET /wd/hub/status
[HTTP] {}
[AppiumDriver@19a4] Plugins which can handle cmd 'getStatus': images
[AppiumDriver@19a4] Plugin images is now handling cmd 'getStatus'
[AppiumDriver@19a4] Executing default handling behavior for command 'getStatus'
APPIUM SERVER STARTED
[HTTP] <-- GET /wd/hub/status 200 6 ms - 110
[HTTP]
@dipakkumar1225 check "Logs" folder is created or not (System.getProperty("user.dir") + File.separator + "Logs" + File.separator + "Server.logs")). If not create the Logs folder and try!!
@dipakkumar1225 check "Logs" folder is created or not (System.getProperty("user.dir") + File.separator + "Logs" + File.separator + "Server.logs")). If not create the Logs folder and try!!
@ashwithpoojary98 Folder and files both are present.
For safety, I am checking the folder present or not, But still getting same error
private static AppiumDriverLocalService getAppiumDriverService() {
File logDir = new File(System.getProperty("user.dir") + File.separator + "Logs");
if (!logDir.exists()) {
logDir.mkdirs();
}
return AppiumDriverLocalService.buildService(new AppiumServiceBuilder()
.withIPAddress("127.0.0.1")
.usingPort(DEFAULT_APPIUM_SERVER_PORT)
.withArgument(GeneralServerFlag.BASEPATH, "/wd/hub/")
.withArgument(GeneralServerFlag.LOG_LEVEL, "info:debug")
.withArgument(GeneralServerFlag.USE_DRIVERS, "UiAutomator2")
.withArgument(GeneralServerFlag.ALLOW_INSECURE, "adb_shell")
.withArgument(GeneralServerFlag.RELAXED_SECURITY)
.withArgument(GeneralServerFlag.USE_PLUGINS, "images")
.withArgument(GeneralServerFlag.SESSION_OVERRIDE)
.withLogFile(new File(System.getProperty("user.dir") + File.separator + "Logs" + File.separator + "Server.logs")));
}
please try below code,
File logDir = new File(System.getProperty("user.dir") + File.separator + "Logs"); if (!logDir.exists()) { logDir.mkdirs(); }
return AppiumDriverLocalService.buildService(new AppiumServiceBuilder()
.withIPAddress("127.0.0.1")
.usingPort(DEFAULT_APPIUM_SERVER_PORT)
.withArgument(GeneralServerFlag.BASEPATH, "/wd/hub/")
.withArgument(GeneralServerFlag.LOG_LEVEL, "info:debug")
.withArgument(GeneralServerFlag.USE_DRIVERS, "UiAutomator2")
.withArgument(GeneralServerFlag.ALLOW_INSECURE, "adb_shell")
.withArgument(GeneralServerFlag.RELAXED_SECURITY)
.withArgument(GeneralServerFlag.USE_PLUGINS, "images")
.withArgument(GeneralServerFlag.SESSION_OVERRIDE)
.withLogFile(logDir+ "Server.logs"));
}
please try below code,
File logDir = new File(System.getProperty("user.dir") + File.separator + "Logs"); if (!logDir.exists()) { logDir.mkdirs(); }
return AppiumDriverLocalService.buildService(new AppiumServiceBuilder() .withIPAddress("127.0.0.1") .usingPort(DEFAULT_APPIUM_SERVER_PORT) .withArgument(GeneralServerFlag.BASEPATH, "/wd/hub/") .withArgument(GeneralServerFlag.LOG_LEVEL, "info:debug") .withArgument(GeneralServerFlag.USE_DRIVERS, "UiAutomator2") .withArgument(GeneralServerFlag.ALLOW_INSECURE, "adb_shell") .withArgument(GeneralServerFlag.RELAXED_SECURITY) .withArgument(GeneralServerFlag.USE_PLUGINS, "images") .withArgument(GeneralServerFlag.SESSION_OVERRIDE) .withLogFile(logDir+ "Server.logs"));
}
I tried this too, but still getting same error.
private static AppiumDriverLocalService getAppiumDriverService() {
File logDir = new File(System.getProperty("user.dir") + File.separator + "Logs");
if (!logDir.exists()) {
logDir.mkdirs();
}
File serverLogsFile = new File(logDir, "Servers.logs");
if (!serverLogsFile.exists()) {
try {
serverLogsFile.createNewFile();
} catch (IOException e) {
e.printStackTrace();
}
}
return AppiumDriverLocalService.buildService(new AppiumServiceBuilder()
.withIPAddress("127.0.0.1")
.usingPort(DEFAULT_APPIUM_SERVER_PORT)
.withLogFile(serverLogsFile)
.withArgument(GeneralServerFlag.BASEPATH, "/wd/hub/")
.withArgument(GeneralServerFlag.LOG_LEVEL, "info:debug")
.withArgument(GeneralServerFlag.USE_DRIVERS, "UiAutomator2")
.withArgument(GeneralServerFlag.ALLOW_INSECURE, "adb_shell")
.withArgument(GeneralServerFlag.RELAXED_SECURITY)
.withArgument(GeneralServerFlag.USE_PLUGINS, "images")
.withArgument(GeneralServerFlag.SESSION_OVERRIDE));
}
File serverLogsFile = new File(logDir, "Servers.logs"); if (!serverLogsFile.exists()) { try { serverLogsFile.createNewFile(); } catch (IOException e) { e.printStackTrace(); } } don't create a log file directly use it!!
return AppiumDriverLocalService.buildService(new AppiumServiceBuilder() .withIPAddress("127.0.0.1") .usingPort(DEFAULT_APPIUM_SERVER_PORT) .withArgument(GeneralServerFlag.BASEPATH, "/wd/hub/") .withArgument(GeneralServerFlag.LOG_LEVEL, "info:debug") .withArgument(GeneralServerFlag.USE_DRIVERS, "UiAutomator2") .withArgument(GeneralServerFlag.ALLOW_INSECURE, "adb_shell") .withArgument(GeneralServerFlag.RELAXED_SECURITY) .withArgument(GeneralServerFlag.USE_PLUGINS, "images") .withArgument(GeneralServerFlag.SESSION_OVERRIDE) .withLogFile(logDir+ "Server.logs"));
File serverLogsFile = new File(logDir, "Servers.logs"); if (!serverLogsFile.exists()) { try { serverLogsFile.createNewFile(); } catch (IOException e) { e.printStackTrace(); } } don't create a log file directly use it!!
return AppiumDriverLocalService.buildService(new AppiumServiceBuilder() .withIPAddress("127.0.0.1") .usingPort(DEFAULT_APPIUM_SERVER_PORT) .withArgument(GeneralServerFlag.BASEPATH, "/wd/hub/") .withArgument(GeneralServerFlag.LOG_LEVEL, "info:debug") .withArgument(GeneralServerFlag.USE_DRIVERS, "UiAutomator2") .withArgument(GeneralServerFlag.ALLOW_INSECURE, "adb_shell") .withArgument(GeneralServerFlag.RELAXED_SECURITY) .withArgument(GeneralServerFlag.USE_PLUGINS, "images") .withArgument(GeneralServerFlag.SESSION_OVERRIDE) .withLogFile(logDir+ "Server.logs"));
This also not working. Please explain "don't create a log file directly use it!!" .withLogFile()); this accept File as a parameter
@mykola-mokhnach Can you please guide me on this?
Today I tried by simply creating Java application and with these too getting the same error.
public static void main(String[] args) {
AppiumDriverLocalService appiumDriverLocalService = AppiumDriverLocalService.buildService(new AppiumServiceBuilder()
.withIPAddress("127.0.0.1")
.usingPort(4723)
.withArgument(GeneralServerFlag.BASEPATH, "/wd/hub/")
.withArgument(GeneralServerFlag.LOG_LEVEL, "info:debug")
.withLogFile(new File("Logs" + File.separator + "Server.log")));
appiumDriverLocalService.start();
appiumDriverLocalService.stop();
}
<dependencies>
<dependency>
<groupId>io.appium</groupId>
<artifactId>java-client</artifactId>
<version>8.5.1</version>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.11.0</version>
<configuration>
<source>15</source>
<target>15</target>
</configuration>
</plugin>
</plugins>
</build>
Error:
SLF4J: No SLF4J providers were found.
SLF4J: Defaulting to no-operation (NOP) logger implementation
SLF4J: See https://www.slf4j.org/codes.html#noProviders for further details.
Tried to attach logging to file 'D:\Automation-Framework\Trial\Logs\Server.log' but an error occurred: EBUSY: resource busy or locked, unlink 'D:\Automation-Framework\Trial\Logs\Server.log'
[Appium] Welcome to Appium v2.1.3
[Appium] Non-default server args:
[Appium] { address: '127.0.0.1', basePath: '/wd/hub/', loglevel: 'info:debug' }
[Appium] Attempting to load driver uiautomator2...
[Appium] Attempting to load driver espresso...
[Appium] Appium REST http interface listener started on http://127.0.0.1:4723/wd/hub
[Appium] Available drivers:
[Appium] - [email protected] (automationName 'UiAutomator2')
[Appium] - [email protected] (automationName 'Espresso')
[Appium] Available plugins:
[Appium] - [email protected]
[Appium] - [email protected]
[Appium] - [email protected]
[Appium] - [email protected]
[Appium] No plugins activated. Use the --use-plugins flag with names of plugins to activate
[HTTP] --> GET /wd/hub/status
[HTTP] {}
[HTTP] <-- GET /wd/hub/status 200 6 ms - 110
[HTTP]
File serverLogsFile = new File(logDir, "Servers.logs"); if (!serverLogsFile.exists()) { try { serverLogsFile.createNewFile(); } catch (IOException e) { e.printStackTrace(); } } don't create a log file directly use it!! return AppiumDriverLocalService.buildService(new AppiumServiceBuilder() .withIPAddress("127.0.0.1") .usingPort(DEFAULT_APPIUM_SERVER_PORT) .withArgument(GeneralServerFlag.BASEPATH, "/wd/hub/") .withArgument(GeneralServerFlag.LOG_LEVEL, "info:debug") .withArgument(GeneralServerFlag.USE_DRIVERS, "UiAutomator2") .withArgument(GeneralServerFlag.ALLOW_INSECURE, "adb_shell") .withArgument(GeneralServerFlag.RELAXED_SECURITY) .withArgument(GeneralServerFlag.USE_PLUGINS, "images") .withArgument(GeneralServerFlag.SESSION_OVERRIDE) .withLogFile(logDir+ "Server.logs"));
This also not working. Please explain "don't create a log file directly use it!!" .withLogFile()); this accept File as a parameter
@dipakkumar1225 I'm not sure what the exact issue is, but the error clearly says that the file write operation is not allowed. Try renaming the project folder, "D:\Automation-Framework", to "AutomationFramework" (without the special character).
File serverLogsFile = new File(logDir, "Servers.logs"); if (!serverLogsFile.exists()) { try { serverLogsFile.createNewFile(); } catch (IOException e) { e.printStackTrace(); } } don't create a log file directly use it!! return AppiumDriverLocalService.buildService(new AppiumServiceBuilder() .withIPAddress("127.0.0.1") .usingPort(DEFAULT_APPIUM_SERVER_PORT) .withArgument(GeneralServerFlag.BASEPATH, "/wd/hub/") .withArgument(GeneralServerFlag.LOG_LEVEL, "info:debug") .withArgument(GeneralServerFlag.USE_DRIVERS, "UiAutomator2") .withArgument(GeneralServerFlag.ALLOW_INSECURE, "adb_shell") .withArgument(GeneralServerFlag.RELAXED_SECURITY) .withArgument(GeneralServerFlag.USE_PLUGINS, "images") .withArgument(GeneralServerFlag.SESSION_OVERRIDE) .withLogFile(logDir+ "Server.logs"));
This also not working. Please explain "don't create a log file directly use it!!" .withLogFile()); this accept File as a parameter
@dipakkumar1225 I'm not sure what the exact issue is, but the error clearly says that the file write operation is not allowed. Try renaming the project folder, "D:\Automation-Framework", to "AutomationFramework" (without the special character).
@ashwithpoojary98
Tried the suggested approach still the same error
Tried to attach logging to file 'D:\Trial\Logs\Server.log' but an error occurred: EBUSY: resource busy or locked, unlink 'D:\Trial\Logs\Server.log'
[Appium] Welcome to Appium v2.1.3
[Appium] Non-default server args:
[Appium] { address: '127.0.0.1', basePath: '/wd/hub/', loglevel: 'info:debug' }
[Appium] Attempting to load driver uiautomator2...
[Appium] Attempting to load driver espresso...
[Appium] Appium REST http interface listener started on http://127.0.0.1:4723/wd/hub
[Appium] Available drivers:
[Appium] - [email protected] (automationName 'UiAutomator2')
[Appium] - [email protected] (automationName 'Espresso')
[Appium] Available plugins:
[Appium] - [email protected]
[Appium] - [email protected]
[Appium] - [email protected]
[Appium] - [email protected]
[Appium] No plugins activated. Use the --use-plugins flag with names of plugins to activate
[HTTP] --> GET /wd/hub/status
[HTTP] {}
[HTTP] <-- GET /wd/hub/status 200 9 ms - 110
[HTTP]
Process finished with exit code 0
@ashwithpoojary98 @mykola-mokhnach
Today, I tested by downgrading the Selenium version to 4.12.0, and logs attached successfully to file. Additionally, if the "Logs" folder is not present, it gets created at runtime. But if I change the selenium version 4.12.0 onwards then started getting issue EBUSY: resource busy or locked
<dependencies>
<dependency>
<groupId>io.appium</groupId>
<artifactId>java-client</artifactId>
<version>8.6.0</version>
<exclusions>
<exclusion>
<groupId>org.seleniumhq.selenium</groupId>
<artifactId>selenium-remote-driver</artifactId>
</exclusion>
<exclusion>
<groupId>org.seleniumhq.selenium</groupId>
<artifactId>selenium-support</artifactId>
</exclusion>
<exclusion>
<groupId>org.seleniumhq.selenium</groupId>
<artifactId>selenium-api</artifactId>
</exclusion>
<exclusion>
<groupId>org.seleniumhq.selenium</groupId>
<artifactId>selenium-http</artifactId>
</exclusion>
<exclusion>
<groupId>org.seleniumhq.selenium</groupId>
<artifactId>selenium-json</artifactId>
</exclusion>
<exclusion>
<groupId>org.seleniumhq.selenium</groupId>
<artifactId>selenium-manager</artifactId>
</exclusion>
<exclusion>
<groupId>org.seleniumhq.selenium</groupId>
<artifactId>selenium-os</artifactId>
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>org.seleniumhq.selenium</groupId>
<artifactId>selenium-java</artifactId>
<version>4.12.0</version>
</dependency>
</dependencies>
Logs
[Appium] Welcome to Appium v2.1.3
[Appium] Non-default server args:
[Appium] { address: '127.0.0.1', basePath: '/wd/hub/', loglevel: 'info:debug' }
[Appium] Attempting to load driver uiautomator2...
[Appium] Attempting to load driver espresso...
[Appium] Appium REST http interface listener started on http://127.0.0.1:4723/wd/hub
[Appium] Available drivers:
[Appium] - [email protected] (automationName 'UiAutomator2')
[Appium] - [email protected] (automationName 'Espresso')
[Appium] Available plugins:
[Appium] - [email protected]
[Appium] - [email protected]
[Appium] - [email protected]
[Appium] - [email protected]
[Appium] No plugins activated. Use the --use-plugins flag with names of plugins to activate
[HTTP] --> GET /wd/hub/status
[HTTP] {}
[HTTP] <-- GET /wd/hub/status 200 8 ms - 110
[HTTP]
Process finished with exit code 0
Any change this issue has been looked into?