-
Notifications
You must be signed in to change notification settings - Fork 12
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Adding logging formaters that simplifies the log output and the formater
for console output adds coloring based on the log levels. It means that the info and debug log messages in the console will no longer be colored red. In order to be able to take advantage of this feature a plugin needs to be installed into eclipse. More info will be provided on the github project page.
- Loading branch information
Showing
9 changed files
with
132 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,6 @@ | ||
package cz.cuni.mff.d3s.deeco.logging; | ||
|
||
|
||
/** | ||
* API for sending log output. | ||
* | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -9,7 +9,7 @@ | |
* | ||
*/ | ||
interface Logger { | ||
|
||
/** | ||
* Mainly for debugging reasons. | ||
* | ||
|
73 changes: 73 additions & 0 deletions
73
jdeeco-core/src/cz/cuni/mff/d3s/deeco/logging/SimpleColorFormatter.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,73 @@ | ||
package cz.cuni.mff.d3s.deeco.logging; | ||
|
||
import java.util.logging.LogRecord; | ||
|
||
public class SimpleColorFormatter extends SimpleFormatter { | ||
|
||
private enum LogColor{ | ||
|
||
/** | ||
* ANSI_RESET | ||
*/ | ||
DEFAULT("\u001B[0m"), | ||
/** | ||
* ANSI_BLACK | ||
*/ | ||
BLACK("\u001B[30m"), | ||
/** | ||
* ANSI_RED | ||
*/ | ||
RED("\u001B[91m"), | ||
/** | ||
* ANSI_GREEN | ||
*/ | ||
GREEN("\u001B[32m"), | ||
/** | ||
* ANSI_YELLOW | ||
*/ | ||
YELLOW("\u001B[33m"), | ||
/** | ||
* ANSI_BLUE | ||
*/ | ||
BLUE("\u001B[34m"), | ||
/** | ||
* ANSI_PURPLE | ||
*/ | ||
PURPLE("\u001B[35m"), | ||
/** | ||
* ANSI_CYAN | ||
*/ | ||
CYAN("\u001B[36m"), | ||
/** | ||
* ANSI_WHITE | ||
*/ | ||
WHITE("\u001B[37m"); | ||
|
||
public final String mark; | ||
|
||
private LogColor(String mark){ | ||
this.mark = mark; | ||
} | ||
} | ||
|
||
public String format(LogRecord record) { | ||
StringBuilder builder = new StringBuilder(); | ||
|
||
if(record.getLevel().equals(CustomLevel.DEBUG)){ | ||
builder.append(LogColor.CYAN.mark); | ||
} else if(record.getLevel().equals(CustomLevel.INFO)){ | ||
builder.append(LogColor.GREEN.mark); | ||
} else if(record.getLevel().equals(CustomLevel.WARNING)){ | ||
builder.append(LogColor.YELLOW.mark); | ||
} else if(record.getLevel().equals(CustomLevel.ERROR)){ | ||
builder.append(LogColor.RED.mark); | ||
} | ||
|
||
super.preFormat(builder, record); | ||
|
||
builder.append(LogColor.DEFAULT.mark).append("\n"); | ||
|
||
return builder.toString(); | ||
} | ||
|
||
} |
37 changes: 37 additions & 0 deletions
37
jdeeco-core/src/cz/cuni/mff/d3s/deeco/logging/SimpleFormatter.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
package cz.cuni.mff.d3s.deeco.logging; | ||
|
||
import java.text.DateFormat; | ||
import java.text.SimpleDateFormat; | ||
import java.util.Date; | ||
import java.util.logging.Formatter; | ||
import java.util.logging.Handler; | ||
import java.util.logging.LogRecord; | ||
|
||
public class SimpleFormatter extends Formatter { | ||
|
||
private static final DateFormat dateFormat = new SimpleDateFormat("hh:mm:ss.SSS"); | ||
|
||
protected void preFormat(StringBuilder builder, LogRecord record) { | ||
builder.append("[") | ||
.append(record.getLevel()) | ||
.append("] [") | ||
.append(dateFormat.format(new Date(record.getMillis()))) | ||
.append("] ") | ||
.append(formatMessage(record)); | ||
} | ||
|
||
public String format(LogRecord record) { | ||
StringBuilder builder = new StringBuilder(); | ||
preFormat(builder, record); | ||
builder.append("\n"); | ||
return builder.toString(); | ||
} | ||
|
||
public String getHead(Handler h) { | ||
return super.getHead(h); | ||
} | ||
|
||
public String getTail(Handler h) { | ||
return super.getTail(h); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
handlers=java.util.logging.FileHandler, java.util.logging.ConsoleHandler | ||
java.util.logging.ConsoleHandler.level=WARNING | ||
java.util.logging.ConsoleHandler.formatter=cz.cuni.mff.d3s.deeco.logging.SimpleColorFormatter | ||
|
||
java.util.logging.FileHandler.level=INFO | ||
java.util.logging.FileHandler.pattern=logs/jdeeco.log | ||
|
||
# Write 10MB before rotating this file | ||
java.util.logging.FileHandler.limit=10000000 | ||
java.util.logging.FileHandler.append=true | ||
|
||
# Number of rotating files to be used | ||
java.util.logging.FileHandler.count=4 | ||
java.util.logging.FileHandler.formatter=cz.cuni.mff.d3s.deeco.logging.SimpleFormatter | ||
|
||
.level=INFO |