Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove log4j and replace it with default java logger #130

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 1 addition & 15 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

<groupId>com.github.mmarquee</groupId>
<artifactId>ui-automation</artifactId>
<version>0.7.0</version>
<version>0.8.0</version>
<packaging>jar</packaging>

<name>ui-automation</name>
Expand Down Expand Up @@ -35,7 +35,6 @@
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<jna.version>5.6.0</jna.version>
<mockito.version>3.3.3</mockito.version>
<log4j.version>2.17.1</log4j.version>
</properties>

<dependencies>
Expand All @@ -60,19 +59,6 @@
<version>${jna.version}</version>
</dependency>

<!-- log4j -->

<dependency>
<groupId>org.apache.logging.log4j</groupId>
<artifactId>log4j-api</artifactId>
<version>${log4j.version}</version>
</dependency>
<dependency>
<groupId>org.apache.logging.log4j</groupId>
<artifactId>log4j-core</artifactId>
<version>${log4j.version}</version>
</dependency>

<!-- Mockito -->

<dependency>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,14 +25,13 @@
import mmarquee.automation.pattern.*;
import mmarquee.uiautomation.OrientationType;
import mmarquee.uiautomation.TreeScope;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;

import java.lang.reflect.InvocationTargetException;
import java.util.HashMap;
import java.util.LinkedList;
import java.util.List;
import java.util.Map;
import java.util.logging.Logger;

/**
* The base for automation.
Expand All @@ -47,7 +46,7 @@ public abstract class AutomationBase
* The logger.
*/
private final Logger logger =
LogManager.getLogger(AutomationBase.class.getName());
Logger.getLogger(AutomationBase.class.getName());

/**
* Gets the logger.
Expand Down
4 changes: 2 additions & 2 deletions src/main/java/mmarquee/automation/controls/Tab.java
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ public List<TabItem> getTabItems() {
.automation(this.getAutomation())));
}
} catch (AutomationException ex) {
getLogger().error(ex.getMessage());
getLogger().severe(ex.getMessage());
}

return tabItems;
Expand Down Expand Up @@ -93,7 +93,7 @@ public void selectTabPage(final Pattern namePattern) throws AutomationException,

for (TabItem item: this.getTabItems()) {
final String name = item.getName();

if (name != null && namePattern.matcher(name).matches()) {
found = true;
item.selectItem();
Expand Down
14 changes: 7 additions & 7 deletions src/main/java/mmarquee/automation/controls/Window.java
Original file line number Diff line number Diff line change
Expand Up @@ -186,15 +186,15 @@ public Window getWindow(final String title)
this.createControlTypeCondition(
ControlType.Window)));
} catch (ElementNotFoundException ex) {
getLogger().warn("Failed to find `" + title + "` window");
getLogger().warning("Failed to find `" + title + "` window");
}

if (item != null) {
getLogger().warn("Found window");
getLogger().warning("Found window");
break;
} else {
try {
getLogger().warn(
getLogger().warning(
"Did not find `" + title + "` window, retrying");
// Wait for it
Thread.sleep(SLEEP_DURATION);
Expand Down Expand Up @@ -227,7 +227,7 @@ public Window getWindow(Pattern titlePattern)
this.findAll(new TreeScope(TreeScope.DESCENDANTS),
this.createControlTypeCondition(
ControlType.Window));

for (Element element : collection) {
String name = element.getName();

Expand All @@ -236,12 +236,12 @@ public Window getWindow(Pattern titlePattern)
break retry_loop;
}
}

} catch (AutomationException ex) {
getLogger().info("Failed");
}

getLogger().warn(
getLogger().warning(
"Did not find window matching `" + titlePattern + "`, retrying");
// Wait for it
try {
Expand All @@ -251,7 +251,7 @@ public Window getWindow(Pattern titlePattern)
getLogger().info("interrupted");
}
}

if (item == null) {
throw new ElementNotFoundException(
"matching " + titlePattern.toString());
Expand Down
5 changes: 2 additions & 3 deletions src/main/java/mmarquee/automation/pattern/BasePattern.java
Original file line number Diff line number Diff line change
Expand Up @@ -25,10 +25,9 @@
import mmarquee.uiautomation.IUIAutomationElementArray;
import mmarquee.uiautomation.IUIAutomationElementArrayConverter;
import mmarquee.uiautomation.IUIAutomationElementConverter;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;

import java.util.function.Function;
import java.util.logging.Logger;

/**
* The base pattern functionality, shared for all patterns.
Expand All @@ -42,7 +41,7 @@ public abstract class BasePattern
/**
* The logger.
*/
final Logger logger = LogManager.getLogger(BasePattern.class.getName());
final Logger logger = Logger.getLogger(BasePattern.class.getName());

/**
* The guid of the pattern.
Expand Down
4 changes: 3 additions & 1 deletion src/main/java/mmarquee/demo/ChromeDemo.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
package mmarquee.demo;

import java.util.logging.Level;

import mmarquee.automation.UIAutomation;
import mmarquee.automation.controls.Application;
import mmarquee.automation.controls.ElementBuilder;
Expand All @@ -19,7 +21,7 @@ public void run() {
try {
chrome.launchOrAttach();
} catch (Throwable ex) {
logger.warn("Failed to find application", ex);
logger.log(Level.WARNING, "Failed to find application", ex);
}
}
}
5 changes: 3 additions & 2 deletions src/main/java/mmarquee/demo/DemoCaching.java
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
import mmarquee.uiautomation.TreeScope;

import java.util.List;
import java.util.logging.Level;

/**
* Demo for the caching functionality.
Expand All @@ -41,15 +42,15 @@ public void run() {
application =
automation.launchOrAttach("apps\\Project1.exe");
} catch (Throwable ex) {
logger.warn("Failed to find application", ex);
logger.log(Level.WARNING, "Failed to find application", ex);
}

try {
// Wait for the process to start
assert application != null;
application.waitForInputIdle(Application.SHORT_TIMEOUT);
} catch (Throwable ex) {
logger.error("Failed to wait properly");
logger.log(Level.WARNING, "Failed to wait properly");
}

try {
Expand Down
8 changes: 5 additions & 3 deletions src/main/java/mmarquee/demo/DemoEventHandler.java
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@

package mmarquee.demo;

import java.util.logging.Level;

import mmarquee.automation.UIAutomation;
import mmarquee.automation.controls.Application;
import mmarquee.automation.controls.Button;
Expand All @@ -39,15 +41,15 @@ public void run() {
try {
application = automation.launchOrAttach("apps\\Project1.exe");
} catch (Throwable ex) {
logger.warn("Failed to find application", ex);
logger.log(Level.WARNING, "Failed to find application", ex);
}

try {
// Wait for the process to start
assert application != null;
application.waitForInputIdle(Application.SHORT_TIMEOUT);
} catch (Throwable ex) {
logger.error("Failed to wait properly");
logger.severe("Failed to wait properly");
}

try {
Expand All @@ -64,7 +66,7 @@ public void run() {
new AutomationEventHandler());
*/
} catch (Throwable ex) {
logger.error("Failed to get window properly");
logger.severe("Failed to get window properly");
}
}
}
7 changes: 4 additions & 3 deletions src/main/java/mmarquee/demo/DemoGrid.java
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
import mmarquee.automation.controls.*;

import java.util.List;
import java.util.logging.Level;

/**
* @author Mark Humphreys
Expand All @@ -41,11 +42,11 @@ public void run() {
try {
application.launchOrAttach();
} catch (Throwable ex) {
logger.warn("Failed to find application", ex);
logger.log(Level.WARNING, "Failed to find application", ex);
}

// Check that the attached issue is fixed.
logger.info(application.getIsAttached());
logger.info("attached: " + application.getIsAttached());

// Wait for the process to start
// This doesn't seem to wait for WPF examples
Expand Down Expand Up @@ -77,7 +78,7 @@ public void run() {
try {
boolean val = applicationWindow.isModal();

logger.info(val);
logger.info("isModal: " + val);
} catch (Exception ex) {
logger.info("Ouch");
}
Expand Down
4 changes: 3 additions & 1 deletion src/main/java/mmarquee/demo/DemoPointOver.java
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@

import java.awt.*;

import java.util.logging.Level;

/**
* Example for the PointOver functionality.
*
Expand Down Expand Up @@ -56,7 +58,7 @@ public final void run() {
logger.info("From focus = " + elementFocus.getName());

} catch (Exception ex) {
logger.info(ex.getStackTrace());
logger.log(Level.WARNING, "Exception", ex);
}
} while (true);
}
Expand Down
14 changes: 7 additions & 7 deletions src/main/java/mmarquee/demo/DemoTreeWalker.java
Original file line number Diff line number Diff line change
Expand Up @@ -55,9 +55,9 @@ public void run() {

AutomationElementVisitor logVisitor =
new AutomationElementVisitor() {

int level = 0;

@Override
public boolean visit(AutomationTreeWalker walker,
Element element)
Expand All @@ -73,26 +73,26 @@ public boolean visit(AutomationTreeWalker walker,
indent,
name,
className);

logger.info(message);

if (recurseLevel > level) {
level++;
walker.walk(this, element);
level--;
}

return true;
}
};

walker.walk(logVisitor, root);

logger.info("All done");

} catch (Throwable ex) {
// Smother
logger.error("Exception thrown - " + ex.toString());
logger.severe("Exception thrown - " + ex.toString());
ex.printStackTrace();
}
}
Expand Down
6 changes: 3 additions & 3 deletions src/main/java/mmarquee/demo/TestBase.java
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
package mmarquee.demo;

import java.util.logging.Logger;

import mmarquee.automation.controls.AutomationBase;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;

/**
* @author Mark Humphreys
Expand All @@ -11,7 +11,7 @@
public class TestBase {

protected Logger logger =
LogManager.getLogger(AutomationBase.class.getName());
Logger.getLogger(AutomationBase.class.getName());

protected void rest() {
try {
Expand Down
4 changes: 2 additions & 2 deletions src/main/java/mmarquee/demo/TestExplorer.java
Original file line number Diff line number Diff line change
Expand Up @@ -44,14 +44,14 @@ public final void run() {
application = automation.launchOrAttach("explorer");
} catch (Throwable ex) {
// Smother
logger.error("Failed to launch or attach");
logger.severe("Failed to launch or attach");
}

try {
assert application != null;
application.waitForInputIdle(Application.SHORT_TIMEOUT);
} catch (Throwable ex) {
logger.error("Failed to wait for input idle for some reason");
logger.severe("Failed to wait for input idle for some reason");
}

// Get the main explorer window
Expand Down
Loading