Return-Path: X-Original-To: apmail-logging-log4j-user-archive@www.apache.org Delivered-To: apmail-logging-log4j-user-archive@www.apache.org Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by minotaur.apache.org (Postfix) with SMTP id CB2711842A for ; Fri, 5 Feb 2016 16:44:42 +0000 (UTC) Received: (qmail 35501 invoked by uid 500); 5 Feb 2016 16:44:42 -0000 Delivered-To: apmail-logging-log4j-user-archive@logging.apache.org Received: (qmail 35457 invoked by uid 500); 5 Feb 2016 16:44:42 -0000 Mailing-List: contact log4j-user-help@logging.apache.org; run by ezmlm Precedence: bulk List-Unsubscribe: List-Help: List-Post: List-Id: "Log4J Users List" Reply-To: "Log4J Users List" Delivered-To: mailing list log4j-user@logging.apache.org Received: (qmail 35446 invoked by uid 99); 5 Feb 2016 16:44:42 -0000 Received: from Unknown (HELO spamd1-us-west.apache.org) (209.188.14.142) by apache.org (qpsmtpd/0.29) with ESMTP; Fri, 05 Feb 2016 16:44:42 +0000 Received: from localhost (localhost [127.0.0.1]) by spamd1-us-west.apache.org (ASF Mail Server at spamd1-us-west.apache.org) with ESMTP id B3A4BC2596 for ; Fri, 5 Feb 2016 16:44:41 +0000 (UTC) X-Virus-Scanned: Debian amavisd-new at spamd1-us-west.apache.org X-Spam-Flag: NO X-Spam-Score: 2.429 X-Spam-Level: ** X-Spam-Status: No, score=2.429 tagged_above=-999 required=6.31 tests=[DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, FREEMAIL_ENVFROM_END_DIGIT=0.25, HTML_MESSAGE=2, KAM_LIVE=1, RCVD_IN_DNSWL_LOW=-0.7, RCVD_IN_MSPIKE_H3=-0.01, RCVD_IN_MSPIKE_WL=-0.01, SPF_PASS=-0.001] autolearn=disabled Authentication-Results: spamd1-us-west.apache.org (amavisd-new); dkim=pass (2048-bit key) header.d=gmail.com Received: from mx1-us-east.apache.org ([10.40.0.8]) by localhost (spamd1-us-west.apache.org [10.40.0.7]) (amavisd-new, port 10024) with ESMTP id shwGh9f6HArD for ; Fri, 5 Feb 2016 16:44:39 +0000 (UTC) Received: from mail-wm0-f48.google.com (mail-wm0-f48.google.com [74.125.82.48]) by mx1-us-east.apache.org (ASF Mail Server at mx1-us-east.apache.org) with ESMTPS id 560FA42BC3 for ; Fri, 5 Feb 2016 16:44:38 +0000 (UTC) Received: by mail-wm0-f48.google.com with SMTP id g62so55824251wme.0 for ; Fri, 05 Feb 2016 08:44:38 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:in-reply-to:references:date:message-id:subject:from:to :content-type; bh=g0AvMnP6JOwv7q8WQGTNcJ9EDny+xfY17E7P+XZDD1A=; b=ORHnHF0yC9tt91MS8t5P08PWFZHpDaVJcGPaY/96WOXM6Zi3UK/AKuSJdBACQqgjnx or5WNxMUttySDxIlsdY391o/X/YL2MK3X0uwF0HaNIwYjzH/kYah3IPjiN+KZUd6eKOP TUz1lw9VrTin+5DvR3PQxzys9H9/cGKrzKBO/73YtemssZKF03NJfZoZfcSNstdjroFz KxH+DEa8K99QefWnKWgu8SMFJA1hKqPiAOi6IVTNtaQvQNQrF+0791cWw0Yrl4ndzfzT s7E/wi3Yutp3dkA1OH7GxVx0ZQr7DAu3aKgnmgPaDD45Z5uk8wfzGcNSC0wSttV6Q6QJ oeaQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:mime-version:in-reply-to:references:date :message-id:subject:from:to:content-type; bh=g0AvMnP6JOwv7q8WQGTNcJ9EDny+xfY17E7P+XZDD1A=; b=b6O4G4kiWJ/a0iqP7VqqVbUKFOw1XFIRED4n+tuom9ib7pU5AgTWocgguwvX491wvh AobrEAX/73dicJIMx5/ZjL/owQuxp2dvPiPiMSs/EqnGMBcRkP2pKvVnQR1eJ6E7Pj9H uBZ2Wg2xujY0IGmG/qyNqA2DmcyVofIXyLNmO+r5g8KadRGHr8ZQuyiKb588QYcdQKOg ktx/2H0JKKzw1fEmZGEO50A3XW2xv/VTpTxE+3VJxlwBfIl5CLoxXaR9d5JvqcRAewS8 7ZHaJ8RM01HCmJ9i7yAu7cE+eBXqog5rqGLzWSjTmam8+/moSdsi6S0RkDYJxD69JUod LrNQ== X-Gm-Message-State: AG10YORkHPw8uZzKBDrbLjg4IYkd4mcd+w/MjKDB7dSOas/MYtTw3iTcJ0NSnk92OfsOry1v7IMLW1JBUODPhA== MIME-Version: 1.0 X-Received: by 10.194.203.168 with SMTP id kr8mr15239671wjc.168.1454690677234; Fri, 05 Feb 2016 08:44:37 -0800 (PST) Received: by 10.28.141.198 with HTTP; Fri, 5 Feb 2016 08:44:37 -0800 (PST) In-Reply-To: References: <64EBEA1A-7651-45BD-B8BA-1C3DFE763637@dslextreme.com> <6CFCCABA-999E-4AC4-8150-D240464E9A64@gmail.com> <2B1A0E7A-320C-464D-86E1-68595CE38A6D@dslextreme.com> <4E078A82-B9E6-4290-AC91-A1B0F3B30466@dslextreme.com> Date: Fri, 5 Feb 2016 22:14:37 +0530 Message-ID: Subject: Re: Custom appender not identified in OSGi environment From: Nipuni Piyabasi Perera To: Log4J Users List Content-Type: multipart/alternative; boundary=047d7bae42ec132623052b089137 --047d7bae42ec132623052b089137 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: quoted-printable Hi all, This was a class loading issue in my OSGi environment. We were using pax-logging 1.8.4 (which exports log4j2 2.0.2) and the class loader cannot load the package (package read from the log4j2.xml configuration) as the new bundle is not visible to the pax-logging bundle. Could resolve it after adding it as a fragment to pax-logging-log4j2 1.8.4 [1]. (This way new appender bundle becomes a fragment of pax-logging-log4j2 and visible to the class loader.) Sorry for the noise. Thanks all for the replies. [1] org.ops4j.pax.logging.pax-logging-log4j2 Thanks, Nipuni On Fri, Feb 5, 2016 at 9:24 PM, Matt Sicker wrote: > This sounds like it's probably a bug. Could you file an issue in jira? > > On 4 February 2016 at 12:42, Ralph Goers > wrote: > > > I don=E2=80=99t think so. I suspect that > > org.apache.logging.log4j.core.osgi.Activator.java is not finding your > > plugin but I am not sure why. > > > > Ralph > > > > > On Feb 4, 2016, at 11:38 AM, Nipuni Piyabasi Perera < > > nipuni880917@gmail.com> wrote: > > > > > > Thanks for the input. > > > > > > Yes the issue may be different than what I have mentioned. I suspecte= d > > that > > > the issue is related to Log4j2Plugins.dat file as the appender is > working > > > fine in non-OSGi environment, and the only different I could find was > > > that Log4j2Plugins.dat > > > file comparing the two jars. May be I am missing some plugin that I > need > > > to add in pom.xml. > > > > > > Thanks, > > > Nipuni > > > > > > On Fri, Feb 5, 2016 at 12:00 AM, Ralph Goers < > ralph.goers@dslextreme.com > > > > > > wrote: > > > > > >> Actually, I just looked at the code and there is a class that should > be > > >> looking at your bundle to locate any plugins you may have. I am > actually > > >> not very familiar with that code so I wonder if one of the other > > committers > > >> could provide insight on what might be causing it not to work. > > >> > > >> Ralph > > >> > > >>> On Feb 4, 2016, at 11:06 AM, Ralph Goers > > > >> wrote: > > >>> > > >>> I don=E2=80=99t believe that issue is related to your problem. > > >>> > > >>> When Log4j loads plugins it can only find plugins on whatever class > > path > > >> it has available to it. If it is in a different OSGi bundle than yo= ur > > >> plugin it may not see it. In short, Log4j has to be able to find > > >> > META-INF/org/apache/logging/log4j/core/config/plugins/Log4j2Plugins.dat > > for > > >> Log4j and the same file for your plugin. Log4j=E2=80=99s file is emb= edded in > the > > >> log4j-core jar. Yours will be in whatever jar you are producing. The= re > > is a > > >> process for =E2=80=9Cshading=E2=80=9D your code with Log4j=E2=80=99s= that will cause them to > be > > >> combined, but I am afraid I don=E2=80=99t know exactly where that is > > documented. If > > >> you want your stuff in a separate bundle from Log4j=E2=80=99s then y= ou need to > > >> figure out how to get the stuff in your bundle on Log4j=E2=80=99s cl= asspath. > > >>> > > >>> Ralph > > >>> > > >>>> On Feb 4, 2016, at 10:39 AM, Nipuni Piyabasi Perera < > > >> nipuni880917@gmail.com> wrote: > > >>>> > > >>>> Hi all, > > >>>> > > >>>> Above mentioned issue is reported and fixed in[1]. I have tried to > use > > >>>> log4j2- 2.0.1 (as this is the fix version of the jira) in my OSGi > > >>>> environment. But I still see the same CLASS_NOT_FOUND error while = it > > >> works > > >>>> fine in non-OSGi environment. > > >>>> > > >>>> [1] https://issues.apache.org/jira/browse/LOG4J2-741 > > >>>> > > >>>> Thanks, > > >>>> Nipuni > > >>>> > > >>>> On Thu, Feb 4, 2016 at 9:24 AM, Nipuni Piyabasi Perera < > > >>>> nipuni880917@gmail.com> wrote: > > >>>> > > >>>>> Hi, > > >>>>> > > >>>>> Thank you very much for the reply. > > >>>>> > > >>>>> Initially I got error [1] when I am trying to test the appender i= n > > >>>>> non-OSGi environment. This was due to not passing the correct > number > > of > > >>>>> parameters to the factory method. I have updated my log4j2.xml an= d > > 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 bu= t > > >> 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 OSG= i > > >> 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 > > >>>>> > > >>>>> > > >>>>> > > >>>>> org.apache.felix > > >>>>> maven-scr-plugin > > >>>>> 1.9.0 > > >>>>> > > >>>>> > > >>>>> generate-scr-scrdescriptor > > >>>>> > > >>>>> scr > > >>>>> > > >>>>> > > >>>>> > > >>>>> > > >>>>> > > >>>>> org.apache.maven.plugins > > >>>>> maven-compiler-plugin > > >>>>> 3.1 > > >>>>> > > >>>>> > > >>>>> log4j-plugin-processor > > >>>>> > > >>>>> compile > > >>>>> > > >>>>> process-classes > > >>>>> > > >>>>> only > > >>>>> > > >>>>> > > >> > > > org.apache.logging.log4j.core.config.plugins.process= or.PluginProcessor > > >>>>> > > >>>>> > > >>>>> > > >>>>> > > >>>>> > > >>>>> > > >>>>> org.apache.felix > > >>>>> maven-bundle-plugin > > >>>>> true > > >>>>> > > >>>>> > > >>>>> Nipuni > > >>>>> > > >> > > > org.my.custom.http.socket.appender > > >>>>> > > >> org.my.custom.http.socket.appender > > >>>>> 1.0.0 > > >>>>> > > >>>>> org.apache.log4j.*;version=3D"[2.5.0,3.0.0)" > > >>>>> > > >>>>> > > >>>>> > org.my.custom.http.socket.appender.*;version=3D"1.0.0" > > >>>>> > > >>>>> * > > >>>>> > > >>>>> > > >>>>> > > >>>>> > > >>>>> > > >>>>> > > >>>>> > > >>>>> Thanks, > > >>>>> Nipuni > > >>>>> > > >>>>> On Thu, Feb 4, 2016 at 4:31 AM, Remko Popma > > > >> 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 th= e > > >>>>>> 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/l= og4j/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 whic= h > > 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 t= o > > >>>>>> 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=E2=80=99= t in an > > >>>>>> accessible > > >>>>>>>>> ClassLoader it won=E2=80=99t see it. There have been a few p= eople who > > are > > >>>>>> using > > >>>>>>>>> Log4j in an OSGi environment that have helped out with patche= s > > 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 factor= y > > >> 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: > > >>>>>>>>>> > > >>>>>>>>>> > > >>>>>>>>>> > > >>>>>>>>>> ... > > >>>>>>>>>> > > >>>>>>>>>> > > >>>>>>>>>> > > >>>>>>>>>> > port=3D"8888"> > > >>>>>>>>>> <------------------------------------- > > >>>>>>>>>> New Appender > > >>>>>>>>>> > > >>>>>>>>>> > > >>>>>>>>>> > > >>>>>>>>>> > > >>>>>>>>>> ... > > >>>>>>>>>> > > >>>>>>>>>> > > >>>>>>>>>> > >>>>>> additivity=3D"true"> > > >>>>>>>>>> > > >>>>>>>>>> > > >>>>>>>>>> > > >>>>>>>>>> > > >>>>>>>>>> > > >>>>>>>>>> > > >>>>>>>>>> [1] ERROR Appenders contains an invalid element or attribute > > >>>>>>>>> "HTTPSocket" > > >>>>>>>>>> [2] @Plugin(name =3D "HTTPSocket", category =3D "Core", > elementType > > =3D > > >>>>>>>>> "appender", > > >>>>>>>>>> printObject =3D 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 > > >>>>> > > >>>> > > >>>> > > >>>> > > >>>> -- > > >>>> 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 > > > > > > > > --------------------------------------------------------------------- > > To unsubscribe, e-mail: log4j-user-unsubscribe@logging.apache.org > > For additional commands, e-mail: log4j-user-help@logging.apache.org > > > > > > > -- > Matt Sicker > --=20 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 --047d7bae42ec132623052b089137--