Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » Equinox » newbie: how should bundle code log in equinox?
newbie: how should bundle code log in equinox? [message #84975] Sat, 24 March 2007 11:35 Go to next message
David Donohue is currently offline David DonohueFriend
Messages: 104
Registered: July 2009
Senior Member
I have successfully deployed an equinox app, standalone, with a simple bundle.

The trouble is I cannot see any log output from my bundle.

Question: what is the best way to log? My libraries already include commons-logging and log4j, plus of course java.util.logging. I am aware of bundle org.eclipse.equinox.log

Which logging option is best/preferred for plugins in Equinox?

Part (new)B: How do I do it? Where exactly do I put any .properties files?

MANY THANKS!
David
Re: newbie: how should bundle code log in equinox? [message #84990 is a reply to message #84975] Sat, 24 March 2007 20:35 Go to previous messageGo to next message
Eclipse UserFriend
Originally posted by: alex_blewitt.yahoo.com

If you've already got commons-logging installed, you can use that. However, getting the .properties file is tricky; the easiest way is to put it into a fragment that attaches to the log4j plugin, though you can also export the package of a directory containing the name (or just the name of the properties file itself).

Did you look in .metadata/.log? It wouldn't be printed out to the console in any case.

Alex.
Re: newbie: how should bundle code log in equinox? [message #85005 is a reply to message #84990] Sun, 25 March 2007 01:11 Go to previous messageGo to next message
David Donohue is currently offline David DonohueFriend
Messages: 104
Registered: July 2009
Senior Member
Alex,
Kind of you to always respond to my queries.

I don't quite understand your reply. So my classpath already includes commons logging & log4j. Are you saying I should make a new bundle with only a commons logging config file? I am also hazy on what exactly should appear in such a config file to make my bundle code log somewhere in my standalone OSGi app. I do not see a
metadata
directory.

Thanks again!
David
Re: newbie: how should bundle code log in equinox? [message #85020 is a reply to message #85005] Sun, 25 March 2007 17:40 Go to previous messageGo to next message
Eclipse UserFriend
Originally posted by: alex_blewitt.yahoo.com

The location of .metadata is inside wherever the workspace is -- for example, user.home. So it might be something like c:\Documents and Settings\userid\Application Data\workspace\.metadata\.log or something like that.

Windows will hide .metadata from showing in some views, but you can go into it via a command prompt if you want (and/or enable the showing of hidden files in Windows explorer).

Anyway, back to the log4j question ...

Do you have 3 separate bundles or 1 bundle with 3 jars in it?

Alex.
Re: newbie: how should bundle code log in equinox? [message #85035 is a reply to message #85020] Sun, 25 March 2007 18:55 Go to previous messageGo to next message
David Donohue is currently offline David DonohueFriend
Messages: 104
Registered: July 2009
Senior Member
Alex,
Ah, I found .metadata/.log inside my workspace. Nothing of mine is being logged there.

I have 1 bundle with 3 jars in it.

I tried just writing to a file from within my bundle's Activator.start() code but that fails to create the file or write anything.

public void start(BundleContext context) throws Exception {
FileWriter writer = new FileWriter("c:\\workspace\\TestLog.log");
writer.write("Testing write file");
writer.close();
}

In the osgi console, I verified that this bundle is "Activated" so I assume it means this start() method has been called. So I wonder why is it not writing the file?
David
Re: newbie: how should bundle code log in equinox? [message #85067 is a reply to message #85035] Mon, 26 March 2007 11:05 Go to previous messageGo to next message
Eclipse UserFriend
Originally posted by: alex_blewitt.yahoo.com

OK, if you have 1 bundle with 3 jars in it, you can just put the log4j.properties file in the root of the project and it will pick it up. You will need to make sure you edit build.properties to ensure that the bin.includes also lists this file (otherwise it won't be there when you export it).

If your bundle is ACTIVE, and there's a Bundle-Activator: com.foo.Activator, and that's your Activator's method, then yes, this code should have been run. In fact, if it didn't work (say, it couldn't create the file) and an exception occured, your bundle wouldn't be ACTIVE -- it would go back to RESOLVED.

Can you verify that the Bundle-Activator is indeed pointing to this class? If you mis-spell the entry (e.g. Bondle-Activator) then you'd get exactly this behaviour since it wouldn't find the entry and thus use a default of no activator.

Alex.
Re: newbie: how should bundle code log in equinox? [message #85082 is a reply to message #85067] Mon, 26 March 2007 13:54 Go to previous messageGo to next message
David Donohue is currently offline David DonohueFriend
Messages: 104
Registered: July 2009
Senior Member
Alex,
Once again you have lead me to the solution!
It turns out that after building, my MANIFEST.MF file was wrong. It had only 3 lines and was generated by the ant <jar...> command. You see, in order to assemble my standalone OSGi app, I am packaging it using ant. Probably not the preferred way, but I did not see a better way to package and deploy a standalone OSGi app from Eclipse.

So I had this in my build.xml file
<jar destfile="${destination.jar.file}">

and this ignored my bundle's META-INF/MANIFEST.MF file, and instead created its own MANIFEST.MF file.

I changed this ant directive to
<jar destfile="${destination.jar.file}" filesetmanifest="merge">

and now I get the proper MANIFEST.MF in my bundle's final jar file. My bundle is running, it is writing my test file, and I can see console output from my libraries (Jetty, etc). Looks like I might finally have a working development environment. Whew

MANY Thanks, Alex!
David
Re: newbie: how should bundle code log in equinox? [message #85097 is a reply to message #85082] Mon, 26 March 2007 14:16 Go to previous messageGo to next message
Eclipse UserFriend
Originally posted by: alex_blewitt.yahoo.com

Cool. Though, if you're posting via EclipseZone, if you surround your XML with (xml) and (/xml) -- but using square brackets instead of round -- then it doesn't get eaten up by the comment processing system.

http://www.eclipsezone.com/eclipse/forums/m92138365.html#921 38365

Anyway, using Ant to package OSGi is fine, provided that you remember to get the Manifest data in there :-)

Alex.
Re: newbie: how should bundle code log in equinox? [message #85127 is a reply to message #85097] Mon, 26 March 2007 16:21 Go to previous messageGo to next message
David Donohue is currently offline David DonohueFriend
Messages: 104
Registered: July 2009
Senior Member
Posting again. Here was my original ant direcive

&lt;jar destfile="${plugin.jar.file}" &gt;

I changed it to this

&lt;jar destfile="${plugin.jar.file}" filesetmanifest="merge"&gt;

and it now ads my MANIFEST.MF file into the final packaged jar's MANIFEST.MF file
Re: newbie: how should bundle code log in equinox? [message #85142 is a reply to message #85127] Mon, 26 March 2007 16:41 Go to previous message
Eclipse UserFriend
Originally posted by: alex_blewitt.yahoo.com

Yeah, that would do it :-)

Alex.
Previous Topic:3.3M6 - Equinox HTTP service
Next Topic:ServletBridge and Servlet Filters
Goto Forum:
  


Current Time: Fri Sep 27 23:14:43 GMT 2024

Powered by FUDForum. Page generated in 0.06635 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software

Back to the top