Skip to content

Commit

Permalink
Merge branch 'master' into adutra-jansi-enhancements
Browse files Browse the repository at this point in the history
  • Loading branch information
ceki committed Oct 9, 2019
2 parents 58f15b5 + 597b272 commit 347e4e7
Show file tree
Hide file tree
Showing 278 changed files with 5,372 additions and 7,306 deletions.
12 changes: 11 additions & 1 deletion .travis.yml
@@ -1,6 +1,16 @@
dist: trusty

language: java
jdk: oraclejdk9

jdk:
- oraclejdk11

notifications:
email:
- notification@qos.ch

install: /bin/true

script:
- mvn clean
- mvn install
12 changes: 7 additions & 5 deletions README.md
@@ -1,5 +1,5 @@

#About logback
# About logback

Thank you for your interest in logback, the reliable, generic, fast
and flexible logging library for Java.
Expand All @@ -8,13 +8,15 @@ The Logback documentation can be found on the [project
web-site](https://logback.qos.ch/documentation.html) as well as under
the docs/ folder of the logback distribution.

#Building logback
# Building logback

Building logback is documented at:
Version 1.3.x requires Java 9 to compile and build.

More details on building logback is documented at:

https://logback.qos.ch/setup.html#ide

#In case of problems
# In case of problems

In case of problems please do not hesitate to post an e-mail message
on the logback-user@qos.ch mailing list. However, please do not
Expand All @@ -24,7 +26,7 @@ on the logback-user mailing lists who can quickly answer your
questions.


#Pull requests
# Pull requests

If you are interested in improving logback, great! The logback community
looks forward to your contribution. Please follow this process:
Expand Down
4 changes: 4 additions & 0 deletions logback-access/pom.xml
Expand Up @@ -16,6 +16,10 @@
<name>Logback Access Module</name>
<description>logback-access module</description>

<properties>
<module-name>ch.qos.logback.access</module-name>
</properties>

<dependencies>
<dependency>
<groupId>ch.qos.logback</groupId>
Expand Down
Expand Up @@ -178,7 +178,7 @@ protected URL getConfigurationFileURL() {

String jettyHomeProperty = OptionHelper.getSystemProperty("jetty.home");
String defaultConfigFile = DEFAULT_CONFIG_FILE;
if (!OptionHelper.isEmpty(jettyHomeProperty)) {
if (!OptionHelper.isNullOrEmpty(jettyHomeProperty)) {
defaultConfigFile = jettyHomeProperty + File.separatorChar + DEFAULT_CONFIG_FILE;
} else {
addInfo("[jetty.home] system property not set.");
Expand Down
Expand Up @@ -17,22 +17,36 @@
import ch.qos.logback.access.PatternLayoutEncoder;
import ch.qos.logback.access.boolex.JaninoEventEvaluator;
import ch.qos.logback.access.joran.action.ConfigurationAction;
import ch.qos.logback.access.joran.action.EvaluatorAction;
import ch.qos.logback.access.sift.SiftAction;
import ch.qos.logback.access.model.ConfigurationModel;
import ch.qos.logback.access.model.processor.ConfigurationModelHandler;
import ch.qos.logback.access.spi.IAccessEvent;
import ch.qos.logback.core.AppenderBase;
import ch.qos.logback.core.Context;
import ch.qos.logback.core.UnsynchronizedAppenderBase;
import ch.qos.logback.core.filter.EvaluatorFilter;
import ch.qos.logback.core.joran.JoranConfiguratorBase;
import ch.qos.logback.core.joran.action.AppenderRefAction;
import ch.qos.logback.core.joran.action.IncludeAction;
import ch.qos.logback.core.joran.action.NOPAction;
import ch.qos.logback.core.joran.conditional.ElseAction;
import ch.qos.logback.core.joran.conditional.IfAction;
import ch.qos.logback.core.joran.conditional.ThenAction;
import ch.qos.logback.core.joran.action.IncludeModelAction;
import ch.qos.logback.core.joran.spi.DefaultNestedComponentRegistry;
import ch.qos.logback.core.joran.spi.ElementSelector;
import ch.qos.logback.core.joran.spi.InterpretationContext;
import ch.qos.logback.core.joran.spi.RuleStore;
import ch.qos.logback.core.model.AppenderModel;
import ch.qos.logback.core.model.AppenderRefModel;
import ch.qos.logback.core.model.DefineModel;
import ch.qos.logback.core.model.EventEvaluatorModel;
import ch.qos.logback.core.model.ImplicitModel;
import ch.qos.logback.core.model.IncludeModel;
import ch.qos.logback.core.model.Model;
import ch.qos.logback.core.model.ParamModel;
import ch.qos.logback.core.model.PropertyModel;
import ch.qos.logback.core.model.ShutdownHookModel;
import ch.qos.logback.core.model.TimestampModel;
import ch.qos.logback.core.model.processor.AllowAllModelFilter;
import ch.qos.logback.core.model.processor.AppenderModelHandler;
import ch.qos.logback.core.model.processor.AppenderRefModelHandler;
import ch.qos.logback.core.model.processor.ChainedModelFilter;
import ch.qos.logback.core.model.processor.DefaultProcessor;
import ch.qos.logback.core.net.ssl.SSLNestedComponentRegistryRules;

/**
Expand All @@ -47,23 +61,73 @@ public void addInstanceRules(RuleStore rs) {
super.addInstanceRules(rs);

rs.addRule(new ElementSelector("configuration"), new ConfigurationAction());
rs.addRule(new ElementSelector("configuration/appender-ref"), new AppenderRefAction<IAccessEvent>());
rs.addRule(new ElementSelector("configuration/appender-ref"), new AppenderRefAction());

rs.addRule(new ElementSelector("configuration/appender/sift"), new SiftAction());
rs.addRule(new ElementSelector("configuration/appender/sift/*"), new NOPAction());
//rs.addRule(new ElementSelector("configuration/appender/sift/*"), new NOPAction());

rs.addRule(new ElementSelector("configuration/evaluator"), new EvaluatorAction());

// add if-then-else support
rs.addRule(new ElementSelector("*/if"), new IfAction());
rs.addRule(new ElementSelector("*/if/then"), new ThenAction());
rs.addRule(new ElementSelector("*/if/then/*"), new NOPAction());
rs.addRule(new ElementSelector("*/if/else"), new ElseAction());
rs.addRule(new ElementSelector("*/if/else/*"), new NOPAction());
rs.addRule(new ElementSelector("configuration/include"), new IncludeModelAction());
}

rs.addRule(new ElementSelector("configuration/include"), new IncludeAction());
@Override
protected DefaultProcessor buildDefaultProcessor(Context context, InterpretationContext interpretationContext) {
DefaultProcessor defaultProcessor = super.buildDefaultProcessor(context, interpretationContext);
defaultProcessor.addHandler(ConfigurationModel.class, ConfigurationModelHandler.class);
defaultProcessor.addHandler(AppenderModel.class, AppenderModelHandler.class);
defaultProcessor.addHandler(AppenderRefModel.class, AppenderRefModelHandler.class);

injectModelFilters(defaultProcessor);

return defaultProcessor;

}

private void injectModelFilters(DefaultProcessor defaultProcessor) {
@SuppressWarnings("unchecked")
Class<? extends Model>[] variableDefinitionModelClasses = new Class[] {
DefineModel.class,
PropertyModel.class,
TimestampModel.class,
ParamModel.class};

@SuppressWarnings("unchecked")
Class<? extends Model>[] implicitModelClasses = new Class[] {
ImplicitModel.class,
ParamModel.class};

@SuppressWarnings("unchecked")
Class<? extends Model>[] appenderRefModelClasses = new Class[] {
AppenderRefModel.class };

@SuppressWarnings("unchecked")
Class<? extends Model>[] otherFirstPhaseModelClasses = new Class[] {
ConfigurationModel.class,
EventEvaluatorModel.class,
ShutdownHookModel.class,
EventEvaluatorModel.class,
IncludeModel.class,
};



ChainedModelFilter fistPhaseDefintionFilter = new ChainedModelFilter();
for (Class<? extends Model> modelClass : variableDefinitionModelClasses)
fistPhaseDefintionFilter.allow(modelClass);
for (Class<? extends Model> modelClass : otherFirstPhaseModelClasses)
fistPhaseDefintionFilter.allow(modelClass);
for (Class<? extends Model> modelClass : implicitModelClasses)
fistPhaseDefintionFilter.allow(modelClass);
for (Class<? extends Model> modelClass : appenderRefModelClasses)
fistPhaseDefintionFilter.allow(modelClass);

fistPhaseDefintionFilter.denyAll();
defaultProcessor.setPhaseOneFilter(fistPhaseDefintionFilter);


defaultProcessor.setPhaseTwoFilter(new AllowAllModelFilter());

}


@Override
protected void addDefaultNestedComponentRegistryRules(DefaultNestedComponentRegistry registry) {
registry.add(AppenderBase.class, "layout", PatternLayout.class);
Expand Down
Expand Up @@ -14,11 +14,10 @@
package ch.qos.logback.access.joran.action;

import ch.qos.logback.access.boolex.JaninoEventEvaluator;
import ch.qos.logback.core.joran.action.AbstractEventEvaluatorAction;
import ch.qos.logback.core.joran.action.EventEvaluatorAction;

public class EvaluatorAction extends AbstractEventEvaluatorAction {
public class AccessEvaluatorAction extends EventEvaluatorAction {

@Override
protected String defaultClassName() {
return JaninoEventEvaluator.class.getName();
}
Expand Down
Expand Up @@ -15,40 +15,20 @@

import org.xml.sax.Attributes;

import ch.qos.logback.core.joran.action.Action;
import ch.qos.logback.access.model.ConfigurationModel;
import ch.qos.logback.core.joran.action.BaseModelAction;
import ch.qos.logback.core.joran.spi.InterpretationContext;
import ch.qos.logback.core.status.OnConsoleStatusListener;
import ch.qos.logback.core.util.OptionHelper;
import ch.qos.logback.core.util.StatusListenerConfigHelper;
import ch.qos.logback.core.model.Model;

public class ConfigurationAction extends Action {
static final String INTERNAL_DEBUG_ATTR = "debug";
static final String DEBUG_SYSTEM_PROPERTY_KEY = "logback-access.debug";
public class ConfigurationAction extends BaseModelAction {

@Override
public void begin(InterpretationContext ec, String name, Attributes attributes) {
@Override
protected Model buildCurrentModel(InterpretationContext interpretationContext, String name, Attributes attributes) {
ConfigurationModel configurationModel = new ConfigurationModel();
configurationModel.setDebug(attributes.getValue(ConfigurationModel.INTERNAL_DEBUG_ATTR));
return configurationModel;
}

// See LBCLASSIC-225 (the system property is looked up first. Thus, it overrides
// the equivalent property in the config file. This reversal of scope priority is justified
// by the use case: the admin trying to chase rogue config file
String debugAttrib = System.getProperty(DEBUG_SYSTEM_PROPERTY_KEY);
if (debugAttrib == null) {
debugAttrib = attributes.getValue(INTERNAL_DEBUG_ATTR);
}

if (OptionHelper.isEmpty(debugAttrib) || debugAttrib.equals("false") || debugAttrib.equals("null")) {
addInfo(INTERNAL_DEBUG_ATTR + " attribute not set");
} else {
StatusListenerConfigHelper.addOnConsoleListenerInstance(context, new OnConsoleStatusListener());
}

// the context is appender attachable, so it is pushed on top of the stack
ec.pushObject(getContext());
}

@Override
public void end(InterpretationContext ec, String name) {
addInfo("End of configuration.");
ec.popObject();
}
}
@@ -0,0 +1,18 @@
package ch.qos.logback.access.model;

import ch.qos.logback.core.model.Model;

public class ConfigurationModel extends Model {
public static final String INTERNAL_DEBUG_ATTR = "debug";

String debug;

public String getDebug() {
return debug;
}

public void setDebug(String debug) {
this.debug = debug;
}

}
@@ -0,0 +1,42 @@
package ch.qos.logback.access.model.processor;

import ch.qos.logback.access.model.ConfigurationModel;
import ch.qos.logback.core.Context;
import ch.qos.logback.core.joran.spi.InterpretationContext;
import ch.qos.logback.core.model.Model;
import ch.qos.logback.core.model.processor.ModelHandlerBase;
import ch.qos.logback.core.model.processor.ModelHandlerException;
import ch.qos.logback.core.status.OnConsoleStatusListener;
import ch.qos.logback.core.util.OptionHelper;
import ch.qos.logback.core.util.StatusListenerConfigHelper;

public class ConfigurationModelHandler extends ModelHandlerBase {
static final String DEBUG_SYSTEM_PROPERTY_KEY = "logback-access.debug";

public ConfigurationModelHandler(Context context) {
super(context);
}

protected Class<ConfigurationModel> getSupportedModelClass() {
return ConfigurationModel.class;
}

@Override
public void handle(InterpretationContext intercon, Model model) throws ModelHandlerException {
ConfigurationModel configurationModel = (ConfigurationModel) model;
// See LBCLASSIC-225 (the system property is looked up first. Thus, it overrides
// the equivalent property in the config file. This reversal of scope priority
// is justified
// by the use case: the admin trying to chase rogue config file
String debug = System.getProperty(DEBUG_SYSTEM_PROPERTY_KEY);
if (debug == null) {
debug = configurationModel.getDebug();
}
if (OptionHelper.isNullOrEmpty(debug) || debug.equals("false") || debug.equals("null")) {
addInfo(ConfigurationModel.INTERNAL_DEBUG_ATTR + " attribute not set");
} else {
StatusListenerConfigHelper.addOnConsoleListenerInstance(context, new OnConsoleStatusListener());
}

}
}
Expand Up @@ -23,7 +23,7 @@ public class RequestAttributeConverter extends AccessConverter {
@Override
public void start() {
key = getFirstOption();
if (OptionHelper.isEmpty(key)) {
if (OptionHelper.isNullOrEmpty(key)) {
addWarn("Missing key for the request attribute");
} else {
super.start();
Expand Down
Expand Up @@ -23,7 +23,7 @@ public class RequestCookieConverter extends AccessConverter {
@Override
public void start() {
key = getFirstOption();
if (OptionHelper.isEmpty(key)) {
if (OptionHelper.isNullOrEmpty(key)) {
addWarn("Missing key for the requested header");
} else {
super.start();
Expand Down
Expand Up @@ -23,7 +23,7 @@ public class RequestHeaderConverter extends AccessConverter {
@Override
public void start() {
key = getFirstOption();
if (OptionHelper.isEmpty(key)) {
if (OptionHelper.isNullOrEmpty(key)) {
addWarn("Missing key for the requested header. Defaulting to all keys.");
key = null;
}
Expand Down
Expand Up @@ -25,7 +25,7 @@ public class RequestParameterConverter extends AccessConverter {
@Override
public void start() {
key = getFirstOption();
if (OptionHelper.isEmpty(key)) {
if (OptionHelper.isNullOrEmpty(key)) {
addWarn("Missing key for the request parameter");
} else {
super.start();
Expand Down
Expand Up @@ -23,7 +23,7 @@ public class ResponseHeaderConverter extends AccessConverter {
@Override
public void start() {
key = getFirstOption();
if (OptionHelper.isEmpty(key)) {
if (OptionHelper.isNullOrEmpty(key)) {
addWarn("Missing key for the response header");
} else {
super.start();
Expand Down

0 comments on commit 347e4e7

Please sign in to comment.