Skip to content

Commit

Permalink
Logging fix (#699)
Browse files Browse the repository at this point in the history
  • Loading branch information
msbarry authored Oct 28, 2023
1 parent 1be2fca commit 9f96002
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,8 @@ public static void clearStage() {

/** Returns the current {@code [stage]} value prepended to log for this thread. */
public static String getStage() {
return MDC.get(STAGE_KEY);
// strip out the "[stage] " wrapper
return MDC.get(STAGE_KEY) instanceof String s ? s.substring(1, s.length() - 2) : null;
}

/** Prepends {@code [parent:child]} to all subsequent logs from this thread. */
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
package com.onthegomap.planetiler.util;

import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertNull;

import org.junit.jupiter.api.Test;

class LogUtilTest {
@Test
void testStageHandling() {
assertNull(LogUtil.getStage());
LogUtil.setStage("test");
assertEquals("test", LogUtil.getStage());
LogUtil.setStage(LogUtil.getStage(), "child");
assertEquals("test:child", LogUtil.getStage());
LogUtil.clearStage();
assertNull(LogUtil.getStage());
}
}

0 comments on commit 9f96002

Please sign in to comment.