Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » Eclipse 4 » Logger outside Application Model(how to get logger outside the application model)
Logger outside Application Model [message #1199494] Wed, 20 November 2013 21:49 Go to next message
Martin Bayer is currently offline Martin Bayer
Messages: 26
Registered: December 2012
Junior Member
Hi all,
I just have some best practice question. I needed to get loggin possibility while I'm starting my application. So I did it as follows:
		Bundle bundle = FrameworkUtil.getBundle(this.getClass());
		try {
			bundle.start();// Get context of this bundle
			BundleContext bundleCntxt = bundle.getBundleContext();

			IEclipseContext context = EclipseContextFactory
					.getServiceContext(bundleCntxt);
			this.logger = ContextInjectionFactory.make(WorkbenchLogger.class,
					context);
		} catch (BundleException e) {
			//....
		}


Is it OK to start the bundle manually? Or is there any workaround for it?
Thanks you very much,

Martin
Re: Logger outside Application Model [message #1200522 is a reply to message #1199494] Thu, 21 November 2013 09:29 Go to previous messageGo to next message
Sopot Cela is currently offline Sopot Cela
Messages: 597
Registered: December 2010
Senior Member

Calling it in the @PostContextCreate is the earliest stage in which you can get a 'clean' call. Do you need it earlier than that?
Re: Logger outside Application Model [message #1202296 is a reply to message #1200522] Fri, 22 November 2013 04:48 Go to previous messageGo to next message
Martin Bayer is currently offline Martin Bayer
Messages: 26
Registered: December 2012
Junior Member
I need to initialize the logger when I'm initializing new part of the RCP application (in method annotated by @PostConstruct). I use some static methods in it to read some external resources and I need to have some possibility to log these static methods behavior.
Or is it a common to use the logger as an parameter of the static method? I think it wouldn't be much nice...at least for me:)

Thank you,
Martin
Re: Logger outside Application Model [message #1219057 is a reply to message #1202296] Sat, 30 November 2013 13:49 Go to previous message
Martin Bayer is currently offline Martin Bayer
Messages: 26
Registered: December 2012
Junior Member
I only submit my solution which seems to be working (although it's not probably clearest way - bundle.start() is still in there):
Bundle bundle = FrameworkUtil.getBundle(this.getClass());
bundle.start();
// Get context of this bundle
BundleContext bundleCntxt = bundle.getBundleContext();

IEclipseContext context = EclipseContextFactory.getServiceContext(bundleCntxt);
this.logger = ContextInjectionFactory.make(WorkbenchLogger.class,context);

[Updated on: Sat, 30 November 2013 13:50]

Report message to a moderator

Previous Topic:Controlling fragment contributions
Next Topic:IDE functionality in Eclipse 4 RCP
Goto Forum:
  


Current Time: Tue Sep 23 22:32:32 GMT 2014

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

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