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

Solving 5 issues #7

Open
wants to merge 7 commits 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
28 changes: 22 additions & 6 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,12 @@
<artifactId>ch.hearc.ig.odi.stringcalculatortdd</artifactId>
<version>1.0-SNAPSHOT</version>


<properties>
<maven.compiler.source>1.8</maven.compiler.source>
<maven.compiler.target>1.8</maven.compiler.target>
</properties>

<dependencies>
<dependency>
<groupId>junit</groupId>
Expand All @@ -30,11 +36,21 @@
<artifactId>log4j-core</artifactId>
<version>2.11.1</version>
</dependency>
<dependency>
<groupId>org.apache.logging.log4j</groupId>
<artifactId>log4j-api</artifactId>
<version>2.11.1</version>
</dependency>
</dependencies>
</dependencies>

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


</project>
15 changes: 12 additions & 3 deletions src/main/java/ch/hearc/ig/odi/logger/LogClass.java
Original file line number Diff line number Diff line change
@@ -1,13 +1,22 @@
package ch.hearc.ig.odi.logger;


import org.apache.logging.log4j.*;

public class LogClass {

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

public static void info(CharSequence message){}
public static void info(CharSequence message){
//issue #4
//System.out.println("Logger information : " + message);
}

public static void warn(CharSequence message){
System.out.println("\u001B[31m" + "Logger warning : " + message);
}

public static void warn(CharSequence message){}
public static void fatal(CharSequence message){
System.out.println("\u001B[33m" + "Logger fatal : " + message);
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,11 @@

import ch.hearc.ig.odi.logger.LogClass;
import org.apache.commons.lang3.StringUtils;
import ch.hearc.ig.odi.logger.LogClass;

import java.util.ArrayList;
import java.util.List;
import java.util.regex.Pattern;
import org.apache.logging.log4j.*;

public class StringCalculator {

Expand Down Expand Up @@ -51,6 +51,7 @@ else if (numberInt > 1000)
}

if (negativeNumbers.size() > 0) {
LogClass.fatal("Nombre négatif interdit");
throw new RuntimeException("Negative not allowed: " + negativeNumbers.toString());
}

Expand Down
19 changes: 19 additions & 0 deletions src/main/resources/log4j2.xml
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,29 @@
<Console name="Console" target="SYSTEM_OUT">
<PatternLayout pattern="%d{HH:mm:ss.SSS} [%t] %-5level %logger{36} - %msg%n"/>
</Console>

<appender name="FILE" class="org.apache.log4j.FileAppender">

<param name="file" value="${log}/log.out"/>
<param name="immediateFlush" value="true"/>
<param name="threshold" value="debug"/>
<param name="append" value="false"/>

<layout class="org.apache.log4j.PatternLayout">
<param name="conversionPattern" value="%m%n"/>
</layout>
</appender>
</Appenders>
<Loggers>
<Root level="trace">
<AppenderRef ref="Console"/>
</Root>

<logger name="log4j.rootLogger" additivity="false">
<level value="DEBUG"/>
<appender-ref ref="FILE"/>
</logger>
</Loggers>


</Configuration>