-
-
Notifications
You must be signed in to change notification settings - Fork 1.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
ongoing work on ConversionRule support
Signed-off-by: Ceki Gulcu <ceki@qos.ch>
- Loading branch information
Showing
7 changed files
with
211 additions
and
24 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
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
42 changes: 42 additions & 0 deletions
42
logback-core/src/main/java/ch/qos/logback/core/model/ConversionRuleModel.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 @@ | ||
/* | ||
* Logback: the reliable, generic, fast and flexible logging framework. | ||
* Copyright (C) 1999-2024, QOS.ch. All rights reserved. | ||
* | ||
* This program and the accompanying materials are dual-licensed under | ||
* either the terms of the Eclipse Public License v1.0 as published by | ||
* the Eclipse Foundation | ||
* | ||
* or (per the licensee's choosing) | ||
* | ||
* under the terms of the GNU Lesser General Public License version 2.1 | ||
* as published by the Free Software Foundation. | ||
*/ | ||
|
||
package ch.qos.logback.core.model; | ||
|
||
public class ConversionRuleModel extends ComponentModel { | ||
|
||
String conversionWord; | ||
|
||
@Override | ||
protected ConversionRuleModel makeNewInstance() { | ||
return new ConversionRuleModel(); | ||
} | ||
|
||
public String getConversionWord() { | ||
return conversionWord; | ||
} | ||
|
||
public void setConversionWord(String conversionWord) { | ||
this.conversionWord = conversionWord; | ||
} | ||
|
||
public String getConverterClass() { | ||
return className; | ||
} | ||
|
||
public void setConverterClass(String converterClass) { | ||
setClassName(converterClass); | ||
} | ||
|
||
} |
76 changes: 76 additions & 0 deletions
76
...ck-core/src/main/java/ch/qos/logback/core/model/processor/ConversionRuleModelHandler.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,76 @@ | ||
/* | ||
* Logback: the reliable, generic, fast and flexible logging framework. | ||
* Copyright (C) 1999-2024, QOS.ch. All rights reserved. | ||
* | ||
* This program and the accompanying materials are dual-licensed under | ||
* either the terms of the Eclipse Public License v1.0 as published by | ||
* the Eclipse Foundation | ||
* | ||
* or (per the licensee's choosing) | ||
* | ||
* under the terms of the GNU Lesser General Public License version 2.1 | ||
* as published by the Free Software Foundation. | ||
*/ | ||
|
||
package ch.qos.logback.core.model.processor; | ||
|
||
import ch.qos.logback.core.Context; | ||
import ch.qos.logback.core.CoreConstants; | ||
import ch.qos.logback.core.model.ConversionRuleModel; | ||
import ch.qos.logback.core.model.Model; | ||
import ch.qos.logback.core.util.OptionHelper; | ||
|
||
import java.util.HashMap; | ||
import java.util.Map; | ||
|
||
import static ch.qos.logback.core.joran.JoranConstants.CONVERSION_WORD_ATTRIBUTE; | ||
|
||
public class ConversionRuleModelHandler extends ModelHandlerBase { | ||
|
||
private boolean inError; | ||
|
||
public ConversionRuleModelHandler(Context context) { | ||
super(context); | ||
} | ||
|
||
static public ConversionRuleModelHandler makeInstance(Context context, ModelInterpretationContext mic) { | ||
return new ConversionRuleModelHandler(context); | ||
} | ||
|
||
@Override | ||
public void handle(ModelInterpretationContext mic, Model model) throws ModelHandlerException { | ||
|
||
ConversionRuleModel conversionRuleModel = (ConversionRuleModel) model; | ||
String converterClass = conversionRuleModel.getClassName(); | ||
|
||
if (OptionHelper.isNullOrEmptyOrAllSpaces(converterClass)) { | ||
addWarn("Missing className. This should have been caught earlier."); | ||
inError = true; | ||
return; | ||
} else { | ||
converterClass = mic.getImport(converterClass); | ||
} | ||
|
||
String conversionWord = conversionRuleModel.getConversionWord(); | ||
|
||
|
||
try { | ||
Map<String, String> ruleRegistry = (Map<String, String>) context | ||
.getObject(CoreConstants.PATTERN_RULE_REGISTRY); | ||
if (ruleRegistry == null) { | ||
ruleRegistry = new HashMap<String, String>(); | ||
context.putObject(CoreConstants.PATTERN_RULE_REGISTRY, ruleRegistry); | ||
} | ||
// put the new rule into the rule registry | ||
addInfo("registering conversion word " + conversionWord + " with class [" + converterClass + "]"); | ||
ruleRegistry.put(conversionWord, converterClass); | ||
} catch (Exception oops) { | ||
inError = true; | ||
String errorMsg = "Could not add conversion rule to PatternLayout."; | ||
addError(errorMsg); | ||
} | ||
|
||
|
||
|
||
} | ||
} |