From cb316f2f3f7151c3dc069f8db8d9e36da51bfb50 Mon Sep 17 00:00:00 2001 From: Richard Sand Date: Wed, 15 Mar 2023 13:33:10 -0400 Subject: [PATCH] Allows subclasses to do post-create operations on new Logger instances Signed-off-by: Richard Sand --- .../java/ch/qos/logback/classic/LoggerContext.java | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/logback-classic/src/main/java/ch/qos/logback/classic/LoggerContext.java b/logback-classic/src/main/java/ch/qos/logback/classic/LoggerContext.java index f5e702bbee..949a593ceb 100755 --- a/logback-classic/src/main/java/ch/qos/logback/classic/LoggerContext.java +++ b/logback-classic/src/main/java/ch/qos/logback/classic/LoggerContext.java @@ -154,6 +154,7 @@ public Logger getLogger(final String name) { childLogger = logger.getChildByName(childName); if (childLogger == null) { childLogger = logger.createChildByName(childName); + customizeNewLogger(childLogger); loggerCache.put(childName, childLogger); incSize(); } @@ -165,6 +166,15 @@ public Logger getLogger(final String name) { } } + /** + * This method allows subclasses to perform post-create customizations on newly-created {@link Logger} instances. + * By default, this method does nothing + * + * @param childLogger + */ + protected void customizeNewLogger(final Logger childLogger) { + } + private void incSize() { size++; }