logging-log4j-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Nipuni Piyabasi Perera <nipuni880...@gmail.com>
Subject Re: Custom appender not identified in OSGi environment
Date Thu, 04 Feb 2016 03:54:22 GMT
Hi,

Thank you very much for the reply.

Initially I got error [1] when I am trying to test the appender in non-OSGi
environment. This was due to not passing the correct number of parameters
to the factory method. I have updated my log4j2.xml and then could solve
the issue[1] in non-OSGi env. I have applied the same configuration to OSGi
environment as well.

Now I am seeing error[2],which seems to be a class loading issue as you
have mentioned. I did added the plugin processor in my pom.xml but still
seeing the same issue. While comparing the OSGi bundle and the non-OSGi jar
I could see that the Log4j2Plugins.dat file is missing in the OSGi bundle. I
have added the package name to configuration element as well. (as per the
pom.xml [3] I am using log4j2 2.5)

[1] Unable to invoke factory method in class ...
[2] ERROR Error processing element HTTPSocket: CLASS_NOT_FOUND
[3] Adding the plugin section of my pom.xml

<plugins>
    <plugin>
        <groupId>org.apache.felix</groupId>
        <artifactId>maven-scr-plugin</artifactId>
        <version>1.9.0</version>
        <executions>
            <execution>
                <id>generate-scr-scrdescriptor</id>
                <goals>
                    <goal>scr</goal>
                </goals>
            </execution>
        </executions>
    </plugin>
    <plugin>
        <groupId>org.apache.maven.plugins</groupId>
        <artifactId>maven-compiler-plugin</artifactId>
        <version>3.1</version>
        <executions>
            <execution>
                <id>log4j-plugin-processor</id>
                <goals>
                    <goal>compile</goal>
                </goals>
                <phase>process-classes</phase>
                <configuration>
                    <proc>only</proc>
                    <annotationProcessors>

<annotationProcessor>org.apache.logging.log4j.core.config.plugins.processor.PluginProcessor</annotationProcessor>
                    </annotationProcessors>
                </configuration>
            </execution>
        </executions>
    </plugin>
    <plugin>
        <groupId>org.apache.felix</groupId>
        <artifactId>maven-bundle-plugin</artifactId>
        <extensions>true</extensions>
        <configuration>
            <instructions>
                <Bundle-Vendor>Nipuni</Bundle-Vendor>

<Bundle-SymbolicName>org.my.custom.http.socket.appender</Bundle-SymbolicName>
                <Bundle-Name>org.my.custom.http.socket.appender</Bundle-Name>
                <Bundle-Version>1.0.0</Bundle-Version>
                <Import-Package>
                    org.apache.log4j.*;version="[2.5.0,3.0.0)"
                </Import-Package>
                <Export-Package>
                    org.my.custom.http.socket.appender.*;version="1.0.0"
                </Export-Package>
                <DynamicImport-Package>*</DynamicImport-Package>
            </instructions>
        </configuration>
    </plugin>

</plugins>


Thanks,
Nipuni

On Thu, Feb 4, 2016 at 4:31 AM, Remko Popma <remko.popma@gmail.com> wrote:

> Thanks for confirming that.
>
> You may avoid the classloader issues by combining the log4j jars and your
> custom appender in a single jar.
>
> The only tricky part here is that you'd need to combine the serialized
> plugin listing files (see
> http://logging.apache.org/log4j/2.x/manual/plugins.html) from the various
> log4j jars into a single serialized plugin listing file in your superjar.
>
> See the source code for PluginProcessor for more details.
> https://logging.apache.org/log4j/2.x/log4j-core/xref/org/apache/logging/log4j/core/config/plugins/processor/PluginProcessor.html
>
> Sent from my iPhone
>
> > On 2016/02/03, at 23:54, Nipuni Piyabasi Perera <nipuni880917@gmail.com>
> wrote:
> >
> > Hi all,
> >
> > As I have mentioned in my first mail, the issue is only in the OSGi
> > environment it seems. I had mistakenly added the appender as a OSGi
> bundle
> > in the non-OSGi environment. Could resolve the issue after changing the
> > package to a jar.
> >
> > Thanks,
> > Nipuni
> >
> > On Wed, Feb 3, 2016 at 7:41 PM, Nipuni Piyabasi Perera <
> > nipuni880917@gmail.com> wrote:
> >
> >> Thanks for the prompt reply.
> >>
> >> I have first tried my custom appender in OSGi environment which gave the
> >> errors above. But I am getting the same issue in non-OSGi environment
> too.
> >> It seems an issue with custom appender.
> >> AFAIK It is plugin annotation that make the appender visible to log4j2.
> I
> >> can't find any issue in my log4j2.xml and plugin configuration of the
> >> class. Is there any other places that I need to care about?
> >>
> >> Thanks,
> >> Nipuni
> >>
> >> On Wed, Feb 3, 2016 at 7:28 PM, Ralph Goers <ralph.goers@dslextreme.com
> >
> >> wrote:
> >>
> >>> OSGi does interesting things with ClassLoaders. Log4j has to be able to
> >>> access your plugin when it is configuring. If it isn’t in an accessible
> >>> ClassLoader it won’t see it.  There have been a few people who are
> using
> >>> Log4j in an OSGi environment that have helped out with patches from
> time to
> >>> time. Perhaps one of them can help out?
> >>>
> >>> Ralph
> >>>
> >>>>> On Feb 3, 2016, at 6:07 AM, Nipuni Piyabasi Perera <
> >>>> nipuni880917@gmail.com> wrote:
> >>>>
> >>>> Hi,
> >>>>
> >>>> I have written a custom appender extending the log4j2
> AbstractAppender.
> >>> But
> >>>> I am getting a runtime error[1]. I have added the plugin annotation[2]
> >>> as
> >>>> per the manual and the custom appender class contains factory method
> >>>> createAppender() as well. I also have added the package name to
> >>>> configuration element.
> >>>> What am I missing here? Appreciate any input on this.
> >>>>
> >>>> I have my log4j2.xml file as below:
> >>>>
> >>>> <Configuration packages="org.my.custom.http.socket.appender">
> >>>>   <Appenders>
> >>>>       ...
> >>>>       <Socket name="socket" host="localhost" port="4714">
> >>>>     <!--PatternLayout pattern="[%d] %5p {%c} - %m%ex%n"/-->
> >>>>   </Socket>
> >>>>       <HTTPSocket name="HTTP_APPENDER" host="localhost" port="8888">
> >>>>  <-------------------------------------
> >>>> New Appender
> >>>>   </HTTPSocket>
> >>>>   </Appenders>
> >>>>   <Loggers>
> >>>>       <Root level="info" includeLocation="true">
> >>>>           ...
> >>>>           <AppenderRef ref="HTTP_APPENDER"/>
> >>>>       </Root>
> >>>>       <Logger name="my.custom.deployer" level="info"
> additivity="true">
> >>>>               <AppenderRef ref="socket"/>
> >>>>   </Logger>
> >>>>   </Loggers>
> >>>> </Configuration>
> >>>>
> >>>>
> >>>> [1] ERROR Appenders contains an invalid element or attribute
> >>> "HTTPSocket"
> >>>> [2] @Plugin(name = "HTTPSocket", category = "Core", elementType =
> >>> "appender",
> >>>> printObject = true)
> >>>>
> >>>> Thanks,
> >>>> Nipuni
> >>>>
> >>>> --
> >>>> Nipuni Perera
> >>>> Software Engineer; WSO2 Inc.; http://wso2.com
> >>>> Email: nipuni@wso2.com
> >>>> Git hub profile: https://github.com/nipuni
> >>>> Blog : http://nipunipererablog.blogspot.com/
> >>>> Mobile: +94 (71) 5626680
> >>>
> >>>
> >>>
> >>> ---------------------------------------------------------------------
> >>> To unsubscribe, e-mail: log4j-user-unsubscribe@logging.apache.org
> >>> For additional commands, e-mail: log4j-user-help@logging.apache.org
> >>
> >>
> >> --
> >> Nipuni Perera
> >> Software Engineer; WSO2 Inc.; http://wso2.com
> >> Email: nipuni@wso2.com
> >> Git hub profile: https://github.com/nipuni
> >> Blog : http://nipunipererablog.blogspot.com/
> >> Mobile: +94 (71) 5626680
> >
> >
> >
> > --
> > Nipuni Perera
> > Software Engineer; WSO2 Inc.; http://wso2.com
> > Email: nipuni@wso2.com
> > Git hub profile: https://github.com/nipuni
> > Blog : http://nipunipererablog.blogspot.com/
> > Mobile: +94 (71) 5626680
>



-- 
Nipuni Perera
Software Engineer; WSO2 Inc.; http://wso2.com
Email: nipuni@wso2.com
Git hub profile: https://github.com/nipuni
Blog : http://nipunipererablog.blogspot.com/
Mobile: +94 (71) 5626680

Mime
  • Unnamed multipart/alternative (inline, None, 0 bytes)
View raw message