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

Log #7

Open
wants to merge 12 commits into
base: master
Choose a base branch
from
Open
9 changes: 9 additions & 0 deletions .idea/19p-tp2-stringcalculatorlog-DelphSchwartz.iml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 4 additions & 0 deletions .idea/encodings.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 6 additions & 0 deletions .idea/misc.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 8 additions & 0 deletions .idea/modules.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 6 additions & 0 deletions .idea/vcs.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

26 changes: 26 additions & 0 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,32 @@
<artifactId>commons-text</artifactId>
<version>1.4</version>
</dependency>
<dependency>
<groupId>org.apache.logging.log4j</groupId>
<artifactId>log4j-api</artifactId>
<version>2.11.1</version>
</dependency>
<dependency>
<groupId>org.apache.logging.log4j</groupId>
<artifactId>log4j-core</artifactId>
<version>2.11.1</version>
</dependency>

</dependencies>

<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.8.0</version>
<configuration>
<source>1.8</source>
<target>1.8</target>
</configuration>
</plugin>
</plugins>
</build>


</project>
Original file line number Diff line number Diff line change
@@ -1,13 +1,17 @@
package ch.hearc.ig.odi.stringcalculatortdd;

import org.apache.commons.lang3.StringUtils;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;

import java.util.ArrayList;
import java.util.List;
import java.util.regex.Pattern;

public class StringCalculator {

private static final Logger LOGGER = LogManager.getLogger(StringCalculator.class);


public StringCalculator() {
}

Expand All @@ -19,6 +23,7 @@ public int add(final String numbers) {
//if it begins by '//' then it's a personalize delimiter(s)
if (numbers.startsWith("//")) {
delimiter = this.extractDelimiter(numbers);
LOGGER.info("Un délimiteur personnalisé est détecté :" );
//"cut" the beginning of the string so that the personalize delimiter is removed
numbersUpdated = numbers.substring(numbers.indexOf("\n") + 1);
}
Expand All @@ -36,9 +41,12 @@ private int add(final String numbersWithoutDelimiter, final String delimiter) {
//test if the numbers array is not empty
if (!(number.trim().length() == 0)) {
Integer numberInt = Integer.parseInt(number);
if (numberInt < 0)
if (numberInt < 0) {
LOGGER.fatal("Exception des nombres négatifs est survenue !");
negativeNumbers.add(numberInt);
}
else if (numberInt <= 1000)
LOGGER.warn("Un chiffre plus grand que 1'000 est utilisé");
returnValue += numberInt;
}
}
Expand Down
24 changes: 24 additions & 0 deletions src/ressources/log4j2.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
<?xml version="1.0" encoding="UTF-8"?>
<Configuration>
<Appenders>
<Console name="Console" target="SYSTEM_OUT">
<PatternLayout pattern="%d{HH:mm:ss} [%t] %-5level %c{10} - %msg%n"/>
<LevelRangeFilter minLevel="Info" maxLevel="Info" onMatch="ACCEPT" onMismatch="DENY"/>
</Console>
<File name="FileFatal" fileName="log/fatal.log">
<PatternLayout pattern="%d{HH:mm:ss} [%t] %-5level %c{10} - %msg%n"/>
<LevelRangeFilter minLevel="Fatal" maxLevel="Fatal" onMatch="ACCEPT" onMismatch="DENY"/>
</File>
<File name="FileWarning" fileName="log/warning.log">
<PatternLayout pattern="%d{HH:mm:ss} [%t] %-5level %c{10} - %msg%n"/>
<LevelRangeFilter minLevel="Warn" maxLevel="Warn" onMatch="ACCEPT" onMismatch="DENY"/>
</File>
</Appenders>
<Loggers>
<Root level="ALL">
<AppenderRef ref="Console"/>
<AppenderRef ref="FileFatal"/>
<AppenderRef ref="FileWarning"/>
</Root>
</Loggers>
</Configuration>