Skip to content

Commit

Permalink
Use display name for log titles
Browse files Browse the repository at this point in the history
  • Loading branch information
Thomas Goodwin committed Jun 19, 2024
1 parent 30a4bd7 commit 7bdfe6d
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
* @author Goodie
*/
public class MelinoeExtension implements BeforeTestExecutionCallback, AfterTestExecutionCallback, BeforeAllCallback, BeforeEachCallback, AfterEachCallback, AfterAllCallback {
public static String CLASS_DISPLAY_NAME;
public static String DISPLAY_NAME;
public static String CLASS_NAME;
public static String METHOD_NAME;
Expand Down Expand Up @@ -89,6 +90,9 @@ private static void populateInformation(ExtensionContext context) {
METHOD_NAME = context.getTestMethod().map(Method::getName).orElse(null);
CLASS_NAME = context.getTestClass().map(Class::getCanonicalName).orElse(null);
DISPLAY_NAME = context.getDisplayName();
if(METHOD_NAME == null) {
CLASS_DISPLAY_NAME = DISPLAY_NAME;
}

context.getExecutionException().ifPresentOrElse(throwable -> {
THROWABLE = throwable;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,6 @@ public Session newSession() {
return new SessionImpl(fileManager, rootLogger, closableRegister);
}

String prettyName = MelinoeExtension.DISPLAY_NAME + System.lineSeparator() + MelinoeExtension.METHOD_NAME + "()";
String logMessage = switch (MelinoeExtension.EXECUTION_TYPE) {
case BEFORE_ALL -> "Before all";
case BEFORE_EACH -> "Before each";
Expand All @@ -78,8 +77,7 @@ public Session newSession() {
default -> "Other???";
};

String classLoggerKey = MelinoeExtension.CLASS_NAME;
LoggerImpl classLogger = loggersMap.computeIfAbsent(classLoggerKey, s -> rootLogger.createSublogger(MelinoeExtension.CLASS_NAME));
LoggerImpl classLogger = loggersMap.computeIfAbsent(MelinoeExtension.CLASS_NAME, s -> rootLogger.createSublogger(MelinoeExtension.CLASS_DISPLAY_NAME));
MelinoeExtension.storeLogger(classLogger);

if(isBeforeOrAfterAll()) {
Expand All @@ -88,7 +86,7 @@ public Session newSession() {
return new SessionImpl(fileManager, beforeAfterAllLogger, closableRegister);
} else {
String methodLoggerKey = MelinoeExtension.CLASS_NAME + MelinoeExtension.METHOD_NAME;
LoggerImpl methodLogger = loggersMap.computeIfAbsent(methodLoggerKey, s -> classLogger.createSublogger(prettyName));
LoggerImpl methodLogger = loggersMap.computeIfAbsent(methodLoggerKey, s -> classLogger.createSublogger(MelinoeExtension.DISPLAY_NAME));

if(isBeforeOrAfterEach()) {
LoggerImpl sublogger = methodLogger.createSublogger(logMessage);
Expand Down

0 comments on commit 7bdfe6d

Please sign in to comment.