[ 
https://issues.apache.org/jira/browse/LOG4J2-461?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=13939771#comment-13939771
 ] 

Ronko commented on LOG4J2-461:
------------------------------

Hi guys, ok, have studied this immensely and the log4j2 source code, and 
believe I have found the issue with log4j2.  LOG4J2-460 is directly related but 
I do not believe they are same issue. One causes the other.

We are trying to use AWS SWF FLow Framework. SWF flow runs annotation 
processor, which uses Freemarker, which is coded to log4j 1.x API. With the 
log4j1.2 api from log4j2, that should theoretically be fine, but read on. 

TWO PROBLEMS
1) Log 4j2 CORE (only, apis are fine) will not load under some circumstances 
(such as from maven plugin reactor).

2) There are class cast code bugs in log4j2 code that are trying to cast wrong 
incompatible types. Details follow.

First, on 1)...

First issue: log4j2 core (ONLY) cannot be found or loaded under some 
circumstances. Log4j2 api and log4j1.2 api load fine under all circumstances I 
have found. I have gone through direct coding against core, forcing it via 
classpath, maven dependency, plugin dependency, (including system dependency), 
i have even written my own instance of 
org.apache.logging.log4j.spi.LoggerContextFactory, passed it in via system 
properly via properties-maven-plugin:set-system-properties:

                        <plugin>
                                <groupId>org.codehaus.mojo</groupId>
                                <artifactId>properties-maven-plugin</artifactId>
                                <version>1.0-alpha-2</version>
                                <executions>
                                        <execution>
                                                <phase>initialize</phase>
                                                <goals>
                                                        
<goal>set-system-properties</goal>
                                                </goals>
                                                <configuration>
                                                        <properties>
                                                                <property>
                                                                        
<name>log4j2.loggerContextFactory</name>
                                                                        
<value>com.myco.common.commons.log.HackLogContextFactory</value>
                                                                </property>
                                                        </properties>
                                                </configuration>
                                        </execution>
                                </executions>
                        </plugin>

Then I run maven-compiler-plugin (or maven processor plugin, both fail 
identically) WITH annotation processing.  maven-compiler-plugin:compile then 
runs with proc jvm arg enabled. The APT annotation processor code in the AWS 
SKJ jar is found, and runs. It uses freemarker for templating. 
Log4j2-1.2 api IS found, tries to load. It cannot find core, both are right 
beside each other in dependencies. No power I have found can cause it to find 
it. 

There must be a class loader conflict or class loading issue. So the following 
outputs:

>ERROR StatusLogger Unable to locate a logging implementation, using 
>SimpleLogger

NOW is bug #2! SimpleLogger, LoggerContext, and SimpleLoggerContext, possibly 
others are coded across packages to cast the wrong types, it seems. When 
log4j2-1.2 API tries to load logging, it itself throws a class cast at 
org.apache.log4j.Logger.getLogger(Logger.java:39):

Caused by: java.lang.ExceptionInInitializerError
        at freemarker.ext.beans.BeansWrapper.<clinit>(BeansWrapper.java:147)
        at freemarker.template.ObjectWrapper.<clinit>(ObjectWrapper.java:81)
        at freemarker.core.Configurable.<init>(Configurable.java:161)
        at freemarker.template.Configuration.<init>(Configuration.java:195)
        at freemarker.template.Configuration.<clinit>(Configuration.java:172)
        at 
com.amazonaws.eclipse.simpleworkflow.asynchrony.freemarker.ActivitiesCodeGenerator.getConfiguration(ActivitiesCodeGenerator.java:49)
        at 
com.amazonaws.eclipse.simpleworkflow.asynchrony.freemarker.ActivitiesCodeGenerator.generate(ActivitiesCodeGenerator.java:97)
        at 
com.amazonaws.eclipse.simpleworkflow.asynchrony.freemarker.ActivitiesCodeGenerator.generateActivitiesClientInterface(ActivitiesCodeGenerator.java:85)
        at 
com.amazonaws.eclipse.simpleworkflow.asynchrony.freemarker.ActivitiesCodeGenerator.generateCode(ActivitiesCodeGenerator.java:79)
        at 
com.amazonaws.eclipse.simpleworkflow.asynchrony.annotationprocessor.AsynchronyDeciderAnnotationProcessor.processActivities(AsynchronyDeciderAnnotationProcessor.java:120)
        at 
com.amazonaws.eclipse.simpleworkflow.asynchrony.annotationprocessor.AsynchronyDeciderAnnotationProcessor.process(AsynchronyDeciderAnnotationProcessor.java:64)
        at 
com.sun.tools.javac.processing.JavacProcessingEnvironment.callProcessor(JavacProcessingEnvironment.java:793)
        at 
com.sun.tools.javac.processing.JavacProcessingEnvironment.discoverAndRunProcs(JavacProcessingEnvironment.java:722)
        at 
com.sun.tools.javac.processing.JavacProcessingEnvironment.access$1700(JavacProcessingEnvironment.java:97)
        at 
com.sun.tools.javac.processing.JavacProcessingEnvironment$Round.run(JavacProcessingEnvironment.java:1029)
        at 
com.sun.tools.javac.processing.JavacProcessingEnvironment.doProcessing(JavacProcessingEnvironment.java:1163)
        at 
com.sun.tools.javac.main.JavaCompiler.processAnnotations(JavaCompiler.java:1108)
        at com.sun.tools.javac.main.JavaCompiler.compile(JavaCompiler.java:824)
        at com.sun.tools.javac.main.Main.compile(Main.java:439)
        ... 26 more
Caused by: java.lang.ClassCastException: 
org.apache.logging.log4j.simple.SimpleLoggerContext cannot be cast to 
org.apache.logging.log4j.core.LoggerContext
        at org.apache.log4j.Logger.getLogger(Logger.java:39)
        at 
freemarker.log._Log4JLoggerFactory.getLogger(_Log4JLoggerFactory.java:67)
        at freemarker.log.Logger.getLogger(Logger.java:284)
        at 
freemarker.template.utility.SecurityUtilities.<clinit>(SecurityUtilities.java:66)

Here is why:  SimpleLoggerContext (being run because CORE could not be found), 
extends:
org.apache.logging.log4j.spi.LoggerContext
But LOOK!
The class that Logger.java:39 tries to cast it to is of type:
org.apache.logging.log4j.core.LoggerContext

!!!!DIFFERENT!!!
Note the "spi" versus "core" in the package. 

This causes the stack dump above. 

THis same problem can be found elsewhere. When implemented my own 
HackLogContextFactory and passed it in via system prop, I got this:

ERROR StatusLogger org.apache.logging.log4j.core.impl.Log4jContextFactory does 
not implement org.apache.logging.log4j.spi.LoggerContextFactory

Again, types being cast to the wrong types. 


>  ERROR StatusLogger Unable to locate a logging implementation, using 
> SimpleLogger
> ---------------------------------------------------------------------------------
>
>                 Key: LOG4J2-461
>                 URL: https://issues.apache.org/jira/browse/LOG4J2-461
>             Project: Log4j 2
>          Issue Type: Bug
>          Components: API
>    Affects Versions: 2.0-beta9
>         Environment: Android
>            Reporter: Gaurav Kapoor
>            Priority: Blocker
>
> ERROR StatusLogger Unable to locate a logging implementation, using 
> SimpleLogger
> Code:
> Logger LOG = LogManager.getLogger(MainActivity.class);
>                       LOG.error("Test Log4j2");
> {code}
> <?xml version="1.0" encoding="UTF-8"?> 
> <Configuration> 
>   <Appenders> 
>     <Console name="STDOUT" target="SYSTEM_OUT"> 
>       <PatternLayout pattern="%d %-5p [%t] %C{2} (%F:%L) - %m%n"/> 
>     </Console> 
>   </Appenders> 
>   <Loggers> 
>     <Logger name="hello" level="info"/> 
>     <Root level="trace"> 
>       <AppenderRef ref="STDOUT"/> 
>     </Root> 
>   </Loggers> 
> </Configuration>
> {code}



--
This message was sent by Atlassian JIRA
(v6.2#6252)

---------------------------------------------------------------------
To unsubscribe, e-mail: log4j-dev-unsubscr...@logging.apache.org
For additional commands, e-mail: log4j-dev-h...@logging.apache.org

Reply via email to