Skip to content

Commit

Permalink
Fix: Fixed imprecision
Browse files Browse the repository at this point in the history
  • Loading branch information
Szombatioi committed May 22, 2024
1 parent a735485 commit 86fc781
Show file tree
Hide file tree
Showing 3 changed files with 47 additions and 24 deletions.
14 changes: 7 additions & 7 deletions test/core/src/temalab/logger/ConsoleLogger.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
package temalab.logger;
public class ConsoleLogger extends LoggerBase{
public class ConsoleLogger extends PrintStreamLogger{
static final String ANSI_RESET = "\u001B[0m";
static final String ANSI_RED = "\u001B[31m";
static final String ANSI_YELLOW = "\u001B[33m";
Expand All @@ -12,32 +12,32 @@ public ConsoleLogger(){
//TODO maybe can be placed elsewhere, e.g. Base or Logger interface and then it could be overriden
private void printLines(String label, String message){
for (String line : message.split("\n")) {
getPrintStream().println(String.format("\t%s - %s", label, line));
printStream.println(String.format("\t%s - %s", label, line));
}
getPrintStream().print(ANSI_RESET);
printStream.print(ANSI_RESET);
}

@Override
public void debug(String label, String message){
getPrintStream().println(ANSI_RESET + getInfos("DEBUG"));
printStream.println(ANSI_RESET + getInfos("DEBUG"));
printLines(label, message);
}

@Override
public void info(String label, String message){
getPrintStream().print(ANSI_BLUE + getInfos("INFO"));
printStream.print(ANSI_BLUE + getInfos("INFO"));
printLines(label, message);
}

@Override
public void warning(String label, String message){
getPrintStream().print(ANSI_YELLOW + getInfos("WARNING"));
printStream.print(ANSI_YELLOW + getInfos("WARNING"));
printLines(label, message);
}

@Override
public void error(String label, String message){
getPrintStream().print(ANSI_RED + getInfos("ERROR"));
printStream.print(ANSI_RED + getInfos("ERROR"));
printLines(label, message);
}
}
21 changes: 4 additions & 17 deletions test/core/src/temalab/logger/LoggerBase.java
Original file line number Diff line number Diff line change
@@ -1,20 +1,8 @@
package temalab.logger;
import java.io.PrintStream;
import java.time.LocalDateTime;
import java.time.format.DateTimeFormatter;

public abstract class LoggerBase implements Logger {
private PrintStream printStream = null;
protected PrintStream getPrintStream() {return printStream;}

public void setPrintStream(PrintStream p){
printStream.close(); //TODO Cleaner
printStream = p;
}

public LoggerBase(){
printStream = System.err;
}

protected String getInfos(String level) {
String res = "";
Expand Down Expand Up @@ -43,14 +31,13 @@ public String getCallerMethod(){
return Thread.currentThread().getStackTrace()[5].getMethodName();
}

//TODO any better way to do it?
@Override
public void debug(String label, String message){}
public abstract void debug(String label, String message);
@Override
public void info(String label, String message){}
public abstract void info(String label, String message);
@Override
public void warning(String label, String message){}
public abstract void warning(String label, String message);
@Override
public void error(String label, String message){}
public abstract void error(String label, String message);

}
36 changes: 36 additions & 0 deletions test/core/src/temalab/logger/PrintStreamLogger.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
package temalab.logger;

import java.io.PrintStream;

public class PrintStreamLogger extends LoggerBase {
protected PrintStream printStream = null;

public void setPrintStream(PrintStream p){
printStream.close(); //TODO Cleaner
printStream = p;
}

public PrintStreamLogger(){
printStream = System.err;
}

@Override
public void debug(String label, String message){
printStream.println(getInfos("DEBUG"));
}

@Override
public void info(String label, String message){
printStream.print(getInfos("INFO"));
}

@Override
public void warning(String label, String message){
printStream.print(getInfos("WARNING"));
}

@Override
public void error(String label, String message){
printStream.print(getInfos("ERROR"));
}
}

0 comments on commit 86fc781

Please sign in to comment.