Passing arrays as parameters via log4j.xml & log4j.properties

classic Classic list List threaded Threaded
2 messages Options
Reply | Threaded
Open this post in threaded view
|

Passing arrays as parameters via log4j.xml & log4j.properties

Debraj Manna
Cross posting from stackoverflow
<https://stackoverflow.com/questions/47688508/passing-arrays-as-parameters-via-log4j-xml-log4j-properties>

Can some one let me know is it possible to pass array or list to a log4j
appender property via log4j.xml or log4j.properties?

Something like below in appender I want to populate via log4j.xml or
log4j.properties

private List<String> validPackages;
public List<String> getValidPackages() {
        return buildVersionFile;}
public void setValidPackages(List<String> validPackages) {
        this.validPackages = validPackages}
Reply | Threaded
Open this post in threaded view
|

Re: Passing arrays as parameters via log4j.xml & log4j.properties

Matt Sicker
I haven't tested this out, but from the plugin documentation <
http://logging.apache.org/log4j/2.x/manual/plugins.html>, if you make a
plugin that implements Collection, then you can automatically convert its
children into that collection. In that use case, though, you'd need another
plugin element for your validPackages list instead of a plain String.

There's no built-in TypeConverter for arrays (other than byte[] and char[]
which have special meaning anyways), so another alternative would be to add
a TypeConverter for Collection<String> or similar, though reifying generics
at that point for more general Collection<T> usage would become an exercise
in frustration IMO.

On 7 December 2017 at 08:07, Debraj Manna <[hidden email]> wrote:

> Cross posting from stackoverflow
> <https://stackoverflow.com/questions/47688508/passing-
> arrays-as-parameters-via-log4j-xml-log4j-properties>
>
> Can some one let me know is it possible to pass array or list to a log4j
> appender property via log4j.xml or log4j.properties?
>
> Something like below in appender I want to populate via log4j.xml or
> log4j.properties
>
> private List<String> validPackages;
> public List<String> getValidPackages() {
>         return buildVersionFile;}
> public void setValidPackages(List<String> validPackages) {
>         this.validPackages = validPackages}
>



--
Matt Sicker <[hidden email]>