-
Notifications
You must be signed in to change notification settings - Fork 40
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactor: Streamlined commands and added logging
- Loading branch information
Showing
53 changed files
with
1,421 additions
and
1,348 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
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
2 changes: 1 addition & 1 deletion
2
...s/riot/cli/common/RuntimeIOException.java → ...m/redis/riot/core/RuntimeIOException.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
11 changes: 11 additions & 0 deletions
11
core/riot-core/src/main/java/com/redis/riot/core/UnknownFileTypeException.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,11 @@ | ||
package com.redis.riot.core; | ||
|
||
public class UnknownFileTypeException extends RuntimeException { | ||
|
||
private static final long serialVersionUID = 1L; | ||
|
||
public UnknownFileTypeException(String message) { | ||
super(message); | ||
} | ||
|
||
} |
18 changes: 18 additions & 0 deletions
18
core/riot-core/src/main/java/com/redis/riot/core/logging/RiotLevel.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,18 @@ | ||
package com.redis.riot.core.logging; | ||
|
||
import java.util.logging.Level; | ||
|
||
public class RiotLevel extends Level { | ||
|
||
/** | ||
* Custom level between INFO and WARN | ||
*/ | ||
public static final Level LIFECYCLE = new RiotLevel("LIFECYCLE", 850); | ||
|
||
private static final long serialVersionUID = 1L; | ||
|
||
public RiotLevel(String name, int value) { | ||
super(name, value); | ||
} | ||
|
||
} |
22 changes: 22 additions & 0 deletions
22
core/riot-core/src/main/java/com/redis/riot/core/logging/SingleLineFormatter.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,22 @@ | ||
package com.redis.riot.core.logging; | ||
|
||
import java.util.logging.Formatter; | ||
import java.util.logging.LogRecord; | ||
|
||
import org.springframework.core.NestedExceptionUtils; | ||
|
||
public class SingleLineFormatter extends Formatter { | ||
|
||
@Override | ||
public String format(LogRecord logRecord) { | ||
String message = formatMessage(logRecord); | ||
if (logRecord.getThrown() != null) { | ||
Throwable rootCause = NestedExceptionUtils.getRootCause(logRecord.getThrown()); | ||
if (rootCause != null && rootCause.getMessage() != null) { | ||
return String.format("%s: %s%n", message, rootCause.getMessage()); | ||
} | ||
} | ||
return String.format("%s%n", message); | ||
} | ||
|
||
} |
42 changes: 42 additions & 0 deletions
42
core/riot-core/src/main/java/com/redis/riot/core/logging/StackTraceSingleLineFormatter.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,42 @@ | ||
package com.redis.riot.core.logging; | ||
|
||
import java.io.PrintWriter; | ||
import java.io.StringWriter; | ||
import java.time.Instant; | ||
import java.time.ZoneId; | ||
import java.time.ZonedDateTime; | ||
import java.time.format.DateTimeFormatter; | ||
import java.time.format.DateTimeFormatterBuilder; | ||
import java.time.temporal.ChronoField; | ||
import java.util.TimeZone; | ||
import java.util.logging.Formatter; | ||
import java.util.logging.LogRecord; | ||
|
||
public class StackTraceSingleLineFormatter extends Formatter { | ||
|
||
private final DateTimeFormatter d = new DateTimeFormatterBuilder().appendValue(ChronoField.HOUR_OF_DAY, 2) | ||
.appendLiteral(':').appendValue(ChronoField.MINUTE_OF_HOUR, 2).optionalStart().appendLiteral(':') | ||
.appendValue(ChronoField.SECOND_OF_MINUTE, 2).optionalStart() | ||
.appendFraction(ChronoField.NANO_OF_SECOND, 3, 3, true).toFormatter(); | ||
|
||
private final ZoneId offset = TimeZone.getDefault().toZoneId(); | ||
|
||
@Override | ||
public String format(LogRecord logRecord) { | ||
String message = formatMessage(logRecord); | ||
ZonedDateTime time = Instant.ofEpochMilli(logRecord.getMillis()).atZone(offset); | ||
if (logRecord.getThrown() == null) { | ||
return String.format("%s %s %s\t: %s%n", time.format(d), logRecord.getLevel().getLocalizedName(), | ||
logRecord.getLoggerName(), message); | ||
} | ||
return String.format("%s %s %s\t: %s%n%s%n", time.format(d), logRecord.getLevel().getLocalizedName(), | ||
logRecord.getLoggerName(), message, stackTrace(logRecord)); | ||
} | ||
|
||
private String stackTrace(LogRecord logRecord) { | ||
StringWriter sw = new StringWriter(4096); | ||
PrintWriter pw = new PrintWriter(sw); | ||
logRecord.getThrown().printStackTrace(pw); | ||
return sw.toString(); | ||
} | ||
} |
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
Oops, something went wrong.