Skip to content

Commit

Permalink
Merge pull request #77 from hkupty/logger-storage/cleanup
Browse files Browse the repository at this point in the history
Remove old storage mechanism
  • Loading branch information
hkupty authored Jan 14, 2024
2 parents a564c70 + f1cfedb commit 03a7ca9
Show file tree
Hide file tree
Showing 5 changed files with 30 additions and 358 deletions.
163 changes: 0 additions & 163 deletions penna-core/src/main/java/penna/core/logger/TreeCache.java

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -157,8 +157,9 @@ void validJsonMessage(@ForAll("fields") LogField[] fields) throws IOException {
SinkManager.Instance.replace(() -> new CoreSink(fos));

Config config = Config.getDefault().replaceFields(fields);
TreeCache cache = new TreeCache(config);
PennaLogger logger = cache.getLoggerAt("c", "est", "moi");
LoggerStorage cache = new LoggerStorage();
cache.replaceConfig(config);
PennaLogger logger = cache.getOrCreate("c.est.moi");


Marker marker = MarkerFactory.getMarker("something");
Expand Down Expand Up @@ -186,8 +187,9 @@ void validGenericMessage(
SinkManager.Instance.replace(() -> new CoreSink(fos));

Config config = Config.getDefault().replaceFields(fields);
TreeCache cache = new TreeCache(config);
PennaLogger logger = cache.getLoggerAt("c", "est", "moi");
LoggerStorage cache = new LoggerStorage();
cache.replaceConfig(config);
PennaLogger logger = cache.getOrCreate("c.est.moi");

event.config = LogConfig.fromConfig(Config.withFields(fields));
event.logger = logger.nameAsChars;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,29 +9,22 @@ class LoggerStorageTests {

@Provide
Arbitrary<List<String>> loggerNames() {
return
Arbitraries
.strings()
.alpha()
.ofMinLength(2)
.ofMaxLength(5)
.flatMap(prefix ->
Arbitraries
.strings()
.alpha()
.ofMinLength(3)
.ofMaxLength(10)
.list()
.ofMinSize(2)
.ofMaxSize(4)
.map(components -> {
var builder = new StringBuilder(prefix);
components.forEach(item -> builder.append(".").append(item));

return builder.toString();
}))
.list();
var builder = new StringBuilder();
var string = Arbitraries
.strings()
.alpha()
.ofMinLength(3)
.ofMaxLength(32)
.list()
.ofMinSize(2)
.ofMaxSize(6)
.map(components -> {
builder.delete(0, builder.length());
components.forEach(item -> builder.append(".").append(item));
return builder.toString();
});

return string.list();
}

@Property
Expand Down
20 changes: 9 additions & 11 deletions penna-core/src/test/java/penna/core/logger/LoggerTests.java
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
import org.slf4j.Marker;
import org.slf4j.MarkerFactory;
import org.slf4j.event.Level;
import penna.api.config.Config;
import penna.core.logger.guard.*;
import penna.core.sink.CoreSink;
import penna.core.sink.Sink;
Expand Down Expand Up @@ -48,9 +47,9 @@ record LogMessage(

@Test
void log_levels_are_respected() {
var cache = new TreeCache(Config.getDefault());
PennaLogger pennaLogger = cache.getLoggerAt("test");
String[] ref = new String[]{"test"};
var cache = new LoggerStorage();
PennaLogger pennaLogger = cache.getOrCreate("test");
String ref = "test";


// Trace
Expand All @@ -76,13 +75,13 @@ void log_levels_are_respected() {

@Test
void can_write_log_messages() {
var cache = new TreeCache(Config.getDefault());
var cache = new LoggerStorage();
AtomicInteger counter = new AtomicInteger(0);
Sink checker = new TestSink(mle -> counter.getAndIncrement());

SinkManager.Instance.replace(() -> checker);

PennaLogger pennaLogger = cache.getLoggerAt("test");
PennaLogger pennaLogger = cache.getOrCreate("test");


Assertions.assertEquals(InfoLevelGuard.singleton(), pennaLogger.levelGuard);
Expand All @@ -106,7 +105,7 @@ void can_write_log_messages() {

@Test
void markers_are_kept() {
var cache = new TreeCache(Config.getDefault());
var cache = new LoggerStorage();

AtomicReference<Marker> usedMarker = new AtomicReference<>(null);
Sink checker = new TestSink(mle -> {
Expand All @@ -117,7 +116,7 @@ void markers_are_kept() {

SinkManager.Instance.replace(() -> checker);

PennaLogger pennaLogger = cache.getLoggerAt("test");
PennaLogger pennaLogger = cache.getOrCreate("test");
Assertions.assertEquals(InfoLevelGuard.singleton(), pennaLogger.levelGuard);

Marker ref = MarkerFactory.getMarker("ref");
Expand All @@ -134,9 +133,8 @@ void markers_are_kept() {

@Test
void everything_added_to_the_log_is_present_in_the_message() throws IOException {
Config config = Config.getDefault();
TreeCache cache = new TreeCache(config);
PennaLogger logger = cache.getLoggerAt("c", "est", "moi");
var cache = new LoggerStorage();
PennaLogger logger = cache.getOrCreate("c.est.moi");

File testFile = File.createTempFile("valid-message", ".json");
FileOutputStream fos = new FileOutputStream(testFile);
Expand Down
Loading

0 comments on commit 03a7ca9

Please sign in to comment.