Hi Antony,

depends what it means:

I- log4j2 as container logging solution:

* add log4j2 jars and
http://repo.maven.apache.org/maven2/org/apache/tomee/log4j2-tomee/7.0.0-M1/log4j2-tomee-7.0.0-M1.jar
in tomee/lib (or in common.loader if you don't want to change default
folders)
* add openejb.log.factory = log4j2 in conf/system.properties
* add log4j2.xml in common.loader (can be lib/ directory directly or any
other folder in the common.loader)
* Note: the log4j2-tomee jar ensures logs are flushed at container shutdown
cause log4j2 uses shutdown hooks which are not reliable (you can loose log
using them). Bug have been reported but without a container integration it
is hard to solve and log4j2 didnt want to integrate with all containers.
See https://issues.apache.org/jira/browse/LOG4J2-658

II- log4j2 as application logging solution

* add log4j2 jars in WEB-INF/lib
* add log4j2.xml in WEB-INF/classes
* Note1: log4j2-web is buggy - mainly works only for servlet only in a
reliable way - so if you need it ensure the feature you use work. I would
recommand to start/stop log4j yourself either in a @Singleton or using CDI
listeners (@Initialized/@Destroyed(ApplicationScoped.class)).
* Note2: ear support is not perfect, see
https://issues.apache.org/jira/browse/LOG4J2-788 - but it is solvable using
a custom selector (see the diff)


All the warning I mentionned can just be warnings and not affect you but I
prefer to be complete there.

Last note: in EE it is always better to not use static loggers which is an
anti pattern cause:

- classes are scanned and can be instantiated to validate runtime
constraints in a temp loader where no code will be invoked so no need to
use static loggers which would initialized the whole logging stack for
nothing - and potentially leak streams
- classes are loaded eagerly by the container at several places but no
instance are created eagerly in most of cases. it means you can get
initialized too early using static loggers and before log4j2 initialization
- on this point we could extend log4j2-tomee a bit to initialize/destroy
log4j2 through container hooks but it would have the drawback to sometimes
initialize it before the ServletContext is available.

Hope it helps!



Romain Manni-Bucau
@rmannibucau <https://twitter.com/rmannibucau> |  Blog
<http://rmannibucau.wordpress.com> | Github <https://github.com/rmannibucau> |
LinkedIn <https://www.linkedin.com/in/rmannibucau> | Tomitriber
<http://www.tomitribe.com>

2016-02-10 15:52 GMT+01:00 antonypaul <[email protected]>:

> Hi,
>
> Is there any documentation and log4j2.properties/xml file for using log4j2
> with Tomee 7 M1.
>
> Regards,
> Antony
>
>
>
> --
> View this message in context:
> http://tomee-openejb.979440.n4.nabble.com/Using-log4j2-with-Tomee-7-tp4677585.html
> Sent from the TomEE Users mailing list archive at Nabble.com.
>

Reply via email to