Hi @sudhakar
You might want to override the driver log method.
You mentioned that you were using Eclipse so I assume you are using Java.
If so, see the attached code that extends the driver classes and overrides the log method:
iOS
import io.appium.java_client.ios.IOSDriver;
import org.openqa.selenium.Capabilities;
import org.openqa.selenium.remote.SessionId;
import java.net.URL;
import java.text.SimpleDateFormat;
import java.util.Date;
public class NewIOSDriver extends IOSDriver {
private String deviceID = null;
private String deviceName = null;
SimpleDateFormat sdf = new SimpleDateFormat("HH:mm:ss");
public NewIOSDriver(URL remoteAddress, Capabilities desiredCapabilities) {
super(remoteAddress, desiredCapabilities);
try {
this.deviceID = (String) desiredCapabilities.getCapability("udid");
this.deviceName = ((String) desiredCapabilities.getCapability("deviceName")).replace(" ", "_").replace("'", "-").trim();
} catch (Exception e) {
System.out.println("No Id or Name");
}
}
@Override
protected void log(SessionId sessionId, String commandName, Object toLog, When when) {
if (commandName.equals("newSession")) sdf = new SimpleDateFormat("HH:mm:ss");
System.out.println(sdf.format(new Date(System.currentTimeMillis())) + ": " + deviceID + " - " + when + ": " + commandName + " toLog:" + toLog);
super.log(sessionId, commandName, toLog, when);
if (deviceName != null) {
System.out.println(deviceName +" - "+ sdf.format(new Date(System.currentTimeMillis())) + when + ": " + commandName + " toLog:" + toLog);
}
}
}
Android
import io.appium.java_client.android.AndroidDriver;
import org.openqa.selenium.Capabilities;
import org.openqa.selenium.remote.SessionId;
import java.net.URL;
import java.text.SimpleDateFormat;
import java.util.Date;
public class NewAndroidDriver extends AndroidDriver {
private final String deviceID;
private String deviceName = "";
SimpleDateFormat sdf = new SimpleDateFormat("HH:mm:ss");
public NewAndroidDriver(URL remoteAddress, Capabilities desiredCapabilities) {
super(remoteAddress, desiredCapabilities);
this.deviceID = (String) desiredCapabilities.getCapability("udid");
try {
this.deviceName = ((String) desiredCapabilities.getCapability("deviceName")).replace(" ", "_").replace("'", "-").trim();
} catch (Exception e) {
this.deviceName = deviceID;
}
}
@Override
protected void log(SessionId sessionId, String commandName, Object toLog, When when) {
if (commandName.equals("newSession")) sdf = new SimpleDateFormat("HH:mm:ss");
super.log(sessionId, commandName, toLog, when);
System.out.println(sdf.format(new Date(System.currentTimeMillis())) + ": " + deviceID + " - " + when + ": " + commandName + " toLog:" + toLog);
if (deviceName != null) {
System.out.println(deviceName + sdf.format(new Date(System.currentTimeMillis())) + when + ": " + commandName + " toLog:" + toLog);
}
}
}
Add them in your project and initialize the driver accordingly:
driver = new NewIOSDriver(new URL(“http://localhost:4723/wd/hub”), dc);
OR
driver = new NewAndroidDriver(new URL(“http://localhost:4723/wd/hub”), dc);