Skip to content

Commit

Permalink
log4j2 first version
Browse files Browse the repository at this point in the history
  • Loading branch information
mosser committed Jan 1, 2024
1 parent f445d14 commit 5573f1d
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 9 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/build.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ name: build
on:
# Triggers the workflow on push and pull request events but only for the "main" branch
push:
branches: [ "main" ]
branches: [ "main", "solution", "tutorial" ]

env:
JAVA_ENV_VERSION: '21'
Expand Down
25 changes: 17 additions & 8 deletions src/main/java/ca/mcscert/se2aa4/demos/tennis/Main.java
Original file line number Diff line number Diff line change
Expand Up @@ -6,29 +6,38 @@
import org.apache.commons.cli.Options;
import org.apache.commons.cli.ParseException;

import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;

public class Main {

public static int PLAYER1_STRENGTH;
public static int PLAYER2_STRENGTH;

protected static final Logger logger = LogManager.getLogger();

public static void main(String[] args) {
System.out.println("** Starting Tennis Counter Assistant");
System.out.println("**** Reading Command-Line Arguments");
logger.info("** Starting Tennis Counter Assistant");
logger.info("**** Reading Command-Line Arguments");
Options options = new Options();
options.addOption("p1", true, "Strength of Player 1 in [0,100]");
options.addOption("p2", true, "Strength of Player 2 in [0,100]");
CommandLineParser parser = new DefaultParser();
try {
CommandLine cmd = parser.parse(options, args);
PLAYER1_STRENGTH = Integer.parseInt(cmd.getOptionValue("p1","50"));
System.out.println("****** P1's Strength is " + PLAYER1_STRENGTH+"/100");
logger.info("****** P1's Strength is " + PLAYER1_STRENGTH+"/100");
PLAYER2_STRENGTH = Integer.parseInt(cmd.getOptionValue("p2","50"));
System.out.println("****** P2's Strength is " + PLAYER2_STRENGTH+"/100");
logger.info("****** P2's Strength is " + PLAYER2_STRENGTH+"/100");
} catch (ParseException pe) {
System.err.println("An error has occurred");
logger.info("An error has occurred");
}
System.out.println("**** Starting game");
System.out.println("** TODO...");
System.out.println("** Closing Tennis Counter Assistant");
logger.info("**** Starting game");
logger.info("** TODO...");
logger.info("** Closing Tennis Counter Assistant");
}




}
14 changes: 14 additions & 0 deletions src/main/resources/log4j2.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
<?xml version="1.0" encoding="UTF-8"?>
<Configuration status="INFO">
<Appenders>
<Console name="console" target="SYSTEM_OUT">
<PatternLayout pattern="[%level] %logger{0} %msg%n" />
</Console>
</Appenders>

<Loggers>
<Root level="trace">
<AppenderRef ref="console" />
</Root>
</Loggers>
</Configuration>

0 comments on commit 5573f1d

Please sign in to comment.