Discussion:
org.apache.logging.log4j.core.config.plugins.PluginAttribute.required()
Gary Gregory
2014-07-07 15:35:30 UTC
Permalink
Why don't we have a required flag?

Using it and throwing an Exception when this condition is violated would
avoid guard code like:

@PluginFactory
public static RegexFilter createFilter(
@PluginAttribute("regex") final Pattern regex,
@PluginAttribute("useRawMsg") final Boolean useRawMsg,
@PluginAttribute("onMatch") final Result match,
@PluginAttribute("onMismatch") final Result mismatch) {

if (regex == null) {
LOGGER.error("A regular expression must be provided for
RegexFilter");
return null;
}
return new RegexFilter(useRawMsg, regex, match, mismatch);
}

?
--
E-Mail: ***@gmail.com | ***@apache.org
Java Persistence with Hibernate, Second Edition
<http://www.manning.com/bauer3/>
JUnit in Action, Second Edition <http://www.manning.com/tahchiev/>
Spring Batch in Action <http://www.manning.com/templier/>
Blog: http://garygregory.wordpress.com
Home: http://garygregory.com/
Tweet! http://twitter.com/GaryGregory
Ralph Goers
2014-07-07 16:06:10 UTC
Permalink
Seems reasonable to me.

Ralph
Post by Gary Gregory
Why don't we have a required flag?
@PluginFactory
public static RegexFilter createFilter(
@PluginAttribute("regex") final Pattern regex,
@PluginAttribute("useRawMsg") final Boolean useRawMsg,
@PluginAttribute("onMatch") final Result match,
@PluginAttribute("onMismatch") final Result mismatch) {
if (regex == null) {
LOGGER.error("A regular expression must be provided for RegexFilter");
return null;
}
return new RegexFilter(useRawMsg, regex, match, mismatch);
}
?
--
Java Persistence with Hibernate, Second Edition
JUnit in Action, Second Edition
Spring Batch in Action
Blog: http://garygregory.wordpress.com
Home: http://garygregory.com/
Tweet! http://twitter.com/GaryGregory
Matt Sicker
2014-07-07 22:57:19 UTC
Permalink
I support this. Should be added to @PluginAttribute and
@PluginBuilderAttribute or whatever it's called.
Post by Ralph Goers
Seems reasonable to me.
Ralph
Why don't we have a required flag?
Using it and throwing an Exception when this condition is violated would
@PluginFactory
public static RegexFilter createFilter(
@PluginAttribute("regex") final Pattern regex,
@PluginAttribute("useRawMsg") final Boolean useRawMsg,
@PluginAttribute("onMatch") final Result match,
@PluginAttribute("onMismatch") final Result mismatch) {
if (regex == null) {
LOGGER.error("A regular expression must be provided for RegexFilter");
return null;
}
return new RegexFilter(useRawMsg, regex, match, mismatch);
}
?
--
Java Persistence with Hibernate, Second Edition
<http://www.manning.com/bauer3/>
JUnit in Action, Second Edition <http://www.manning.com/tahchiev/>
Spring Batch in Action <http://www.manning.com/templier/>
Blog: http://garygregory.wordpress.com
Home: http://garygregory.com/
Tweet! http://twitter.com/GaryGregory
--
Matt Sicker <***@gmail.com>
Gary Gregory
2014-07-09 01:56:29 UTC
Permalink
Hm... if the error logging takes place in the plugin framework, then it
should be removed from the create() methods, but then apps that do
programmatic configuration will not benefit from the error logging. We
would then need to either keep the current guard clauses (with no logging)
or remove the guard clauses and let the chips fall where they may with NPEs.

Thoughts?

Gary
Post by Gary Gregory
Why don't we have a required flag?
Using it and throwing an Exception when this condition is violated would
@PluginFactory
public static RegexFilter createFilter(
@PluginAttribute("regex") final Pattern regex,
@PluginAttribute("useRawMsg") final Boolean useRawMsg,
@PluginAttribute("onMatch") final Result match,
@PluginAttribute("onMismatch") final Result mismatch) {
if (regex == null) {
LOGGER.error("A regular expression must be provided for
RegexFilter");
return null;
}
return new RegexFilter(useRawMsg, regex, match, mismatch);
}
?
--
Java Persistence with Hibernate, Second Edition
<http://www.manning.com/bauer3/>
JUnit in Action, Second Edition <http://www.manning.com/tahchiev/>
Spring Batch in Action <http://www.manning.com/templier/>
Blog: http://garygregory.wordpress.com
Home: http://garygregory.com/
Tweet! http://twitter.com/GaryGregory
--
E-Mail: ***@gmail.com | ***@apache.org
Java Persistence with Hibernate, Second Edition
<http://www.manning.com/bauer3/>
JUnit in Action, Second Edition <http://www.manning.com/tahchiev/>
Spring Batch in Action <http://www.manning.com/templier/>
Blog: http://garygregory.wordpress.com
Home: http://garygregory.com/
Tweet! http://twitter.com/GaryGregory
Matt Sicker
2014-07-09 02:03:26 UTC
Permalink
Crap, that does actually make things more complicated! It's almost getting
to the point where bytecode manipulation is starting to sound like a decent
idea at times.
Post by Gary Gregory
Hm... if the error logging takes place in the plugin framework, then it
should be removed from the create() methods, but then apps that do
programmatic configuration will not benefit from the error logging. We
would then need to either keep the current guard clauses (with no logging)
or remove the guard clauses and let the chips fall where they may with NPEs.
Thoughts?
Gary
Post by Gary Gregory
Why don't we have a required flag?
Using it and throwing an Exception when this condition is violated would
@PluginFactory
public static RegexFilter createFilter(
@PluginAttribute("regex") final Pattern regex,
@PluginAttribute("useRawMsg") final Boolean useRawMsg,
@PluginAttribute("onMatch") final Result match,
@PluginAttribute("onMismatch") final Result mismatch) {
if (regex == null) {
LOGGER.error("A regular expression must be provided for
RegexFilter");
return null;
}
return new RegexFilter(useRawMsg, regex, match, mismatch);
}
?
--
Java Persistence with Hibernate, Second Edition
<http://www.manning.com/bauer3/>
JUnit in Action, Second Edition <http://www.manning.com/tahchiev/>
Spring Batch in Action <http://www.manning.com/templier/>
Blog: http://garygregory.wordpress.com
Home: http://garygregory.com/
Tweet! http://twitter.com/GaryGregory
--
Java Persistence with Hibernate, Second Edition
<http://www.manning.com/bauer3/>
JUnit in Action, Second Edition <http://www.manning.com/tahchiev/>
Spring Batch in Action <http://www.manning.com/templier/>
Blog: http://garygregory.wordpress.com
Home: http://garygregory.com/
Tweet! http://twitter.com/GaryGregory
--
Matt Sicker <***@gmail.com>
Ralph Goers
2014-07-09 02:46:45 UTC
Permalink
That is why programs that do programmatic configuration should use an API and not call the components directly

Sent from my iPad
Hm... if the error logging takes place in the plugin framework, then it should be removed from the create() methods, but then apps that do programmatic configuration will not benefit from the error logging. We would then need to either keep the current guard clauses (with no logging) or remove the guard clauses and let the chips fall where they may with NPEs.
Thoughts?
Gary
Post by Gary Gregory
Why don't we have a required flag?
@PluginFactory
public static RegexFilter createFilter(
@PluginAttribute("regex") final Pattern regex,
@PluginAttribute("useRawMsg") final Boolean useRawMsg,
@PluginAttribute("onMatch") final Result match,
@PluginAttribute("onMismatch") final Result mismatch) {
if (regex == null) {
LOGGER.error("A regular expression must be provided for RegexFilter");
return null;
}
return new RegexFilter(useRawMsg, regex, match, mismatch);
}
?
--
Java Persistence with Hibernate, Second Edition
JUnit in Action, Second Edition
Spring Batch in Action
Blog: http://garygregory.wordpress.com
Home: http://garygregory.com/
Tweet! http://twitter.com/GaryGregory
--
Java Persistence with Hibernate, Second Edition
JUnit in Action, Second Edition
Spring Batch in Action
Blog: http://garygregory.wordpress.com
Home: http://garygregory.com/
Tweet! http://twitter.com/GaryGregory
Gary Gregory
2014-07-09 04:53:08 UTC
Permalink
Actually, if the framework detects a "required" violation and logs a
message, it should not call the create() method, so there would no double
logging.

It would then be up to the plugin author to decide what level of validation
he or she wants:

- Use the required annotation attribute and let the framework validate (and
log)
- Don't use the required annotation attribute and validate in the plugin
(and log)
- Use the required annotation attribute, let the framework validate (and
log), AND provide validation (and logging) in the plugin for programmatic
configs.

So it does still make sense.

The big question is should we use the required annotation attribute and
remove all the validation and logging. This would be a nice clean up. The
cases where people to programmatic configs would be the 20 of the 80/20 and
since those users are more advanced, they should be able to better deal
with calling create methods with non-garbage input, and if they do they
should handle, NPEs and such.

Thoughts?

Gary
Post by Gary Gregory
Hm... if the error logging takes place in the plugin framework, then it
should be removed from the create() methods, but then apps that do
programmatic configuration will not benefit from the error logging. We
would then need to either keep the current guard clauses (with no logging)
or remove the guard clauses and let the chips fall where they may with NPEs.
Thoughts?
Gary
Post by Gary Gregory
Why don't we have a required flag?
Using it and throwing an Exception when this condition is violated would
@PluginFactory
public static RegexFilter createFilter(
@PluginAttribute("regex") final Pattern regex,
@PluginAttribute("useRawMsg") final Boolean useRawMsg,
@PluginAttribute("onMatch") final Result match,
@PluginAttribute("onMismatch") final Result mismatch) {
if (regex == null) {
LOGGER.error("A regular expression must be provided for
RegexFilter");
return null;
}
return new RegexFilter(useRawMsg, regex, match, mismatch);
}
?
--
Java Persistence with Hibernate, Second Edition
<http://www.manning.com/bauer3/>
JUnit in Action, Second Edition <http://www.manning.com/tahchiev/>
Spring Batch in Action <http://www.manning.com/templier/>
Blog: http://garygregory.wordpress.com
Home: http://garygregory.com/
Tweet! http://twitter.com/GaryGregory
--
Java Persistence with Hibernate, Second Edition
<http://www.manning.com/bauer3/>
JUnit in Action, Second Edition <http://www.manning.com/tahchiev/>
Spring Batch in Action <http://www.manning.com/templier/>
Blog: http://garygregory.wordpress.com
Home: http://garygregory.com/
Tweet! http://twitter.com/GaryGregory
--
E-Mail: ***@gmail.com | ***@apache.org
Java Persistence with Hibernate, Second Edition
<http://www.manning.com/bauer3/>
JUnit in Action, Second Edition <http://www.manning.com/tahchiev/>
Spring Batch in Action <http://www.manning.com/templier/>
Blog: http://garygregory.wordpress.com
Home: http://garygregory.com/
Tweet! http://twitter.com/GaryGregory
Ralph Goers
2014-07-09 06:03:20 UTC
Permalink
IMO the proper, and recommended, way to do programmatic configuration is to implement a Configuration, the end result of which is a tree of Nodes. Doing that leverages everything we have to offer and is probably simpler to implement in the end. We should create a sample that shows how to do this.

While creating Loggers, Appenders, etc manually is possible it is always going to be brittle as we are not going to guarantee that components won't change and thus the factory methods may have parameters added. This would be less of a problem with the builders Matt loves, but it is a complete non-issue when the plugin system does the work, which is why leveraging it should be our recommended approach.

So I wouldn't worry about the validation if the plugin system is bypassed. If they want to manually create the components then they should also have to perform all the validation the plugin system provides,

Ralph
Actually, if the framework detects a "required" violation and logs a message, it should not call the create() method, so there would no double logging.
- Use the required annotation attribute and let the framework validate (and log)
- Don't use the required annotation attribute and validate in the plugin (and log)
- Use the required annotation attribute, let the framework validate (and log), AND provide validation (and logging) in the plugin for programmatic configs.
So it does still make sense.
The big question is should we use the required annotation attribute and remove all the validation and logging. This would be a nice clean up. The cases where people to programmatic configs would be the 20 of the 80/20 and since those users are more advanced, they should be able to better deal with calling create methods with non-garbage input, and if they do they should handle, NPEs and such.
Thoughts?
Gary
Hm... if the error logging takes place in the plugin framework, then it should be removed from the create() methods, but then apps that do programmatic configuration will not benefit from the error logging. We would then need to either keep the current guard clauses (with no logging) or remove the guard clauses and let the chips fall where they may with NPEs.
Thoughts?
Gary
Post by Gary Gregory
Why don't we have a required flag?
@PluginFactory
public static RegexFilter createFilter(
@PluginAttribute("regex") final Pattern regex,
@PluginAttribute("useRawMsg") final Boolean useRawMsg,
@PluginAttribute("onMatch") final Result match,
@PluginAttribute("onMismatch") final Result mismatch) {
if (regex == null) {
LOGGER.error("A regular expression must be provided for RegexFilter");
return null;
}
return new RegexFilter(useRawMsg, regex, match, mismatch);
}
?
--
Java Persistence with Hibernate, Second Edition
JUnit in Action, Second Edition
Spring Batch in Action
Blog: http://garygregory.wordpress.com
Home: http://garygregory.com/
Tweet! http://twitter.com/GaryGregory
--
Java Persistence with Hibernate, Second Edition
JUnit in Action, Second Edition
Spring Batch in Action
Blog: http://garygregory.wordpress.com
Home: http://garygregory.com/
Tweet! http://twitter.com/GaryGregory
--
Java Persistence with Hibernate, Second Edition
JUnit in Action, Second Edition
Spring Batch in Action
Blog: http://garygregory.wordpress.com
Home: http://garygregory.com/
Tweet! http://twitter.com/GaryGregory
Matt Sicker
2014-07-09 18:03:30 UTC
Permalink
A Groovy DSL using closures would make a neat interface to creating the
Node hierarchy you're speaking of. Is that what you meant when you
mentioned this in the past?
Post by Ralph Goers
IMO the proper, and recommended, way to do programmatic configuration is
to implement a Configuration, the end result of which is a tree of Nodes.
Doing that leverages everything we have to offer and is probably simpler
to implement in the end. We should create a sample that shows how to do
this.
While creating Loggers, Appenders, etc manually is possible it is always
going to be brittle as we are not going to guarantee that components won't
change and thus the factory methods may have parameters added. This would
be less of a problem with the builders Matt loves, but it is a complete
non-issue when the plugin system does the work, which is why leveraging it
should be our recommended approach.
So I wouldn't worry about the validation if the plugin system is bypassed.
If they want to manually create the components then they should also have
to perform all the validation the plugin system provides,
Ralph
Actually, if the framework detects a "required" violation and logs a
message, it should not call the create() method, so there would no double
logging.
It would then be up to the plugin author to decide what level of
- Use the required annotation attribute and let the framework validate (and log)
- Don't use the required annotation attribute and validate in the plugin (and log)
- Use the required annotation attribute, let the framework validate (and
log), AND provide validation (and logging) in the plugin for programmatic
configs.
So it does still make sense.
The big question is should we use the required annotation attribute and
remove all the validation and logging. This would be a nice clean up. The
cases where people to programmatic configs would be the 20 of the 80/20 and
since those users are more advanced, they should be able to better deal
with calling create methods with non-garbage input, and if they do they
should handle, NPEs and such.
Thoughts?
Gary
Post by Gary Gregory
Hm... if the error logging takes place in the plugin framework, then it
should be removed from the create() methods, but then apps that do
programmatic configuration will not benefit from the error logging. We
would then need to either keep the current guard clauses (with no logging)
or remove the guard clauses and let the chips fall where they may with NPEs.
Thoughts?
Gary
Post by Gary Gregory
Why don't we have a required flag?
Using it and throwing an Exception when this condition is violated would
@PluginFactory
public static RegexFilter createFilter(
@PluginAttribute("regex") final Pattern regex,
@PluginAttribute("useRawMsg") final Boolean useRawMsg,
@PluginAttribute("onMatch") final Result match,
@PluginAttribute("onMismatch") final Result mismatch) {
if (regex == null) {
LOGGER.error("A regular expression must be provided for RegexFilter");
return null;
}
return new RegexFilter(useRawMsg, regex, match, mismatch);
}
?
--
Java Persistence with Hibernate, Second Edition
<http://www.manning.com/bauer3/>
JUnit in Action, Second Edition <http://www.manning.com/tahchiev/>
Spring Batch in Action <http://www.manning.com/templier/>
Blog: http://garygregory.wordpress.com
Home: http://garygregory.com/
Tweet! http://twitter.com/GaryGregory
--
Java Persistence with Hibernate, Second Edition
<http://www.manning.com/bauer3/>
JUnit in Action, Second Edition <http://www.manning.com/tahchiev/>
Spring Batch in Action <http://www.manning.com/templier/>
Blog: http://garygregory.wordpress.com
Home: http://garygregory.com/
Tweet! http://twitter.com/GaryGregory
--
Java Persistence with Hibernate, Second Edition
<http://www.manning.com/bauer3/>
JUnit in Action, Second Edition <http://www.manning.com/tahchiev/>
Spring Batch in Action <http://www.manning.com/templier/>
Blog: http://garygregory.wordpress.com
Home: http://garygregory.com/
Tweet! http://twitter.com/GaryGregory
--
Matt Sicker <***@gmail.com>
Ralph Goers
2014-07-09 19:34:49 UTC
Permalink
Not necessarily Groovy specifically, but in general, yes. However, even then it might be nicer to have a layer above that that creates the Nodes and adds them to the hierarchy. I’m not really sure what that would look like. I’d have to try to build something before I would know what would be “friendly”.

Ralph
A Groovy DSL using closures would make a neat interface to creating the Node hierarchy you're speaking of. Is that what you meant when you mentioned this in the past?
IMO the proper, and recommended, way to do programmatic configuration is to implement a Configuration, the end result of which is a tree of Nodes. Doing that leverages everything we have to offer and is probably simpler to implement in the end. We should create a sample that shows how to do this.
While creating Loggers, Appenders, etc manually is possible it is always going to be brittle as we are not going to guarantee that components won't change and thus the factory methods may have parameters added. This would be less of a problem with the builders Matt loves, but it is a complete non-issue when the plugin system does the work, which is why leveraging it should be our recommended approach.
So I wouldn't worry about the validation if the plugin system is bypassed. If they want to manually create the components then they should also have to perform all the validation the plugin system provides,
Ralph
Actually, if the framework detects a "required" violation and logs a message, it should not call the create() method, so there would no double logging.
- Use the required annotation attribute and let the framework validate (and log)
- Don't use the required annotation attribute and validate in the plugin (and log)
- Use the required annotation attribute, let the framework validate (and log), AND provide validation (and logging) in the plugin for programmatic configs.
So it does still make sense.
The big question is should we use the required annotation attribute and remove all the validation and logging. This would be a nice clean up. The cases where people to programmatic configs would be the 20 of the 80/20 and since those users are more advanced, they should be able to better deal with calling create methods with non-garbage input, and if they do they should handle, NPEs and such.
Thoughts?
Gary
Hm... if the error logging takes place in the plugin framework, then it should be removed from the create() methods, but then apps that do programmatic configuration will not benefit from the error logging. We would then need to either keep the current guard clauses (with no logging) or remove the guard clauses and let the chips fall where they may with NPEs.
Thoughts?
Gary
Why don't we have a required flag?
@PluginFactory
public static RegexFilter createFilter(
@PluginAttribute("regex") final Pattern regex,
@PluginAttribute("useRawMsg") final Boolean useRawMsg,
@PluginAttribute("onMatch") final Result match,
@PluginAttribute("onMismatch") final Result mismatch) {
if (regex == null) {
LOGGER.error("A regular expression must be provided for RegexFilter");
return null;
}
return new RegexFilter(useRawMsg, regex, match, mismatch);
}
?
--
Java Persistence with Hibernate, Second Edition
JUnit in Action, Second Edition
Spring Batch in Action
Blog: http://garygregory.wordpress.com
Home: http://garygregory.com/
Tweet! http://twitter.com/GaryGregory
--
Java Persistence with Hibernate, Second Edition
JUnit in Action, Second Edition
Spring Batch in Action
Blog: http://garygregory.wordpress.com
Home: http://garygregory.com/
Tweet! http://twitter.com/GaryGregory
--
Java Persistence with Hibernate, Second Edition
JUnit in Action, Second Edition
Spring Batch in Action
Blog: http://garygregory.wordpress.com
Home: http://garygregory.com/
Tweet! http://twitter.com/GaryGregory
--
Matt Sicker
2014-09-13 21:00:04 UTC
Permalink
Going back to this programmatic configuration topic, I agree with Ralph's
idea of using Configuration/Node. Thus, a programmatic API would likely
work via that idea so as not to cause problems with this sort of annotation.
Post by Ralph Goers
Not necessarily Groovy specifically, but in general, yes. However, even
then it might be nicer to have a layer above that that creates the Nodes
and adds them to the hierarchy. I’m not really sure what that would look
like. I’d have to try to build something before I would know what would be
“friendly”.
Ralph
A Groovy DSL using closures would make a neat interface to creating the
Node hierarchy you're speaking of. Is that what you meant when you
mentioned this in the past?
Post by Ralph Goers
IMO the proper, and recommended, way to do programmatic configuration is
to implement a Configuration, the end result of which is a tree of Nodes.
Doing that leverages everything we have to offer and is probably simpler
to implement in the end. We should create a sample that shows how to do
this.
While creating Loggers, Appenders, etc manually is possible it is always
going to be brittle as we are not going to guarantee that components won't
change and thus the factory methods may have parameters added. This would
be less of a problem with the builders Matt loves, but it is a complete
non-issue when the plugin system does the work, which is why leveraging it
should be our recommended approach.
So I wouldn't worry about the validation if the plugin system is
bypassed. If they want to manually create the components then they should
also have to perform all the validation the plugin system provides,
Ralph
Actually, if the framework detects a "required" violation and logs a
message, it should not call the create() method, so there would no double
logging.
It would then be up to the plugin author to decide what level of
- Use the required annotation attribute and let the framework validate (and log)
- Don't use the required annotation attribute and validate in the plugin (and log)
- Use the required annotation attribute, let the framework validate (and
log), AND provide validation (and logging) in the plugin for programmatic
configs.
So it does still make sense.
The big question is should we use the required annotation attribute and
remove all the validation and logging. This would be a nice clean up. The
cases where people to programmatic configs would be the 20 of the 80/20 and
since those users are more advanced, they should be able to better deal
with calling create methods with non-garbage input, and if they do they
should handle, NPEs and such.
Thoughts?
Gary
Post by Gary Gregory
Hm... if the error logging takes place in the plugin framework, then it
should be removed from the create() methods, but then apps that do
programmatic configuration will not benefit from the error logging. We
would then need to either keep the current guard clauses (with no logging)
or remove the guard clauses and let the chips fall where they may with NPEs.
Thoughts?
Gary
Post by Gary Gregory
Why don't we have a required flag?
Using it and throwing an Exception when this condition is violated
@PluginFactory
public static RegexFilter createFilter(
@PluginAttribute("regex") final Pattern regex,
@PluginAttribute("useRawMsg") final Boolean useRawMsg,
@PluginAttribute("onMatch") final Result match,
@PluginAttribute("onMismatch") final Result mismatch) {
if (regex == null) {
LOGGER.error("A regular expression must be provided for RegexFilter");
return null;
}
return new RegexFilter(useRawMsg, regex, match, mismatch);
}
?
--
Java Persistence with Hibernate, Second Edition
<http://www.manning.com/bauer3/>
JUnit in Action, Second Edition <http://www.manning.com/tahchiev/>
Spring Batch in Action <http://www.manning.com/templier/>
Blog: http://garygregory.wordpress.com
Home: http://garygregory.com/
Tweet! http://twitter.com/GaryGregory
--
Java Persistence with Hibernate, Second Edition
<http://www.manning.com/bauer3/>
JUnit in Action, Second Edition <http://www.manning.com/tahchiev/>
Spring Batch in Action <http://www.manning.com/templier/>
Blog: http://garygregory.wordpress.com
Home: http://garygregory.com/
Tweet! http://twitter.com/GaryGregory
--
Java Persistence with Hibernate, Second Edition
<http://www.manning.com/bauer3/>
JUnit in Action, Second Edition <http://www.manning.com/tahchiev/>
Spring Batch in Action <http://www.manning.com/templier/>
Blog: http://garygregory.wordpress.com
Home: http://garygregory.com/
Tweet! http://twitter.com/GaryGregory
--
--
Matt Sicker <***@gmail.com>
Loading...