You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@felix.apache.org by li...@io7m.com on 2016/08/04 19:29:24 UTC
Logging uncaught exceptions?
Hello.
I have a simple declarative service such as:
--8<--
@Component(immediate = true)
public final class Speaker implements SpeakerType
{
public Speaker()
{
System.out.println("Speaker (declarative): constructor");
}
@Activate
private void onActivate()
{
System.out.println("Speaker (declarative): onActivate");
}
@Override
public void speak(final String text)
{
System.out.println("Speaker (declarative): speak: " + text);
}
}
-->8--
If I throw an exception in either the constructor or the onActivate()
method, I get no indication that this has happened. A quick search
through the core spec for the word "exceptions" leads me to 9.3.6,
which I think may be relevant even though I'm going through the
declarative services service:
If the BundleActivator.start or stop method throws an Exception, then
the handling of this Exception is different depending who invoked
the start or stop method.
If the bundle is started/stopped due to a change in the active start
level or the bundle's start level, then the Exception must be wrapped
in a BundleException and broadcast as a FrameworkEvent.ERROR event.
Otherwise, a new BundleException must be created containing the
exception and this BundleException is then thrown to the caller.
So I assume that I need to register some sort of listener to receive
errors. However, even assuming that I do this: What if the exception is
of a type that the listener does not import?
Is there a bundle in the distribution that handles this? I have the Log
service installed, but that doesn't appear to do anything (unless it
requires extra configuration - I've not given it any). I just
want errors logged to the console during development so that I don't
sit here trying to debug silent failures.
M
Re: Logging uncaught exceptions?
Posted by li...@io7m.com.
On 2016-08-04T20:36:10 +0100
Neil Bartlett <nj...@gmail.com> wrote:
> If you DON'T install a log service, the errors are actually printed to the console.
>
> If you DO have a log service then just use the command “log <level>” to list the most recent log entries at that level or above. For example “log warn” will give all the warnings and errors but not info or debug. This has a small advantage over printing to the console because you can show the entries at any time rather than scrolling back to when they happened.
Ah, OK, thanks.
M
Re: Logging uncaught exceptions?
Posted by Neil Bartlett <nj...@gmail.com>.
If you DON'T install a log service, the errors are actually printed to the console.
If you DO have a log service then just use the command “log <level>” to list the most recent log entries at that level or above. For example “log warn” will give all the warnings and errors but not info or debug. This has a small advantage over printing to the console because you can show the entries at any time rather than scrolling back to when they happened.
Regards,
Neil
> On 4 Aug 2016, at 20:29, list+org.apache.felix@io7m.com wrote:
>
> Hello.
>
> I have a simple declarative service such as:
>
> --8<--
> @Component(immediate = true)
> public final class Speaker implements SpeakerType
> {
> public Speaker()
> {
> System.out.println("Speaker (declarative): constructor");
> }
>
> @Activate
> private void onActivate()
> {
> System.out.println("Speaker (declarative): onActivate");
> }
>
> @Override
> public void speak(final String text)
> {
> System.out.println("Speaker (declarative): speak: " + text);
> }
> }
> -->8--
>
> If I throw an exception in either the constructor or the onActivate()
> method, I get no indication that this has happened. A quick search
> through the core spec for the word "exceptions" leads me to 9.3.6,
> which I think may be relevant even though I'm going through the
> declarative services service:
>
> If the BundleActivator.start or stop method throws an Exception, then
> the handling of this Exception is different depending who invoked
> the start or stop method.
>
> If the bundle is started/stopped due to a change in the active start
> level or the bundle's start level, then the Exception must be wrapped
> in a BundleException and broadcast as a FrameworkEvent.ERROR event.
> Otherwise, a new BundleException must be created containing the
> exception and this BundleException is then thrown to the caller.
>
> So I assume that I need to register some sort of listener to receive
> errors. However, even assuming that I do this: What if the exception is
> of a type that the listener does not import?
>
> Is there a bundle in the distribution that handles this? I have the Log
> service installed, but that doesn't appear to do anything (unless it
> requires extra configuration - I've not given it any). I just
> want errors logged to the console during development so that I don't
> sit here trying to debug silent failures.
>
> M
---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@felix.apache.org
For additional commands, e-mail: users-help@felix.apache.org
Re: Logging uncaught exceptions?
Posted by Neil Bartlett <nj...@gmail.com>.
> On 4 Aug 2016, at 20:47, list+org.apache.felix@io7m.com wrote:
>
> On 2016-08-04T12:37:02 -0700
> David Jencks <da...@yahoo.com.INVALID> wrote:
>
>> BundleActivator behavior and DS component behavior are completely unrelated.
>
> Hm, OK. I erroneously assumed that DS components would be built upon
> the activator behaviour. Clearly not!
Components have activate/deactivate methods but they are not BundleActivators because components are not bundles.
However, components are shipped *inside* bundles, and the containing bundle must be active in order for any of the components to be active. This can lead to an apparent connection, where the components get activated as a result of the bundle being activated.
Sorry that I missed this in your original mail, and well spotted David.
>
>> I strongly suspect that you haven’t installed anything to record the logging or display it to you? IIRC pax-logging is a popular way to hook osgi logging up to slf4j and make it easy to configure where it goes.
>
> You suspect correctly!
>
> START LEVEL 1
> ID|State |Level|Name
> 0|Active | 0|System Bundle (5.4.0)|5.4.0
> 1|Active | 1|Apache Felix Bundle Repository (2.0.6)|2.0.6
> 2|Active | 1|Apache Felix Configuration Admin Service (1.8.10)|1.8.10
> 3|Active | 1|Apache Felix Gogo Command (0.16.0)|0.16.0
> 4|Active | 1|Apache Felix Gogo Runtime (0.16.2)|0.16.2
> 5|Active | 1|Apache Felix Gogo Shell (0.10.0)|0.10.0
> 6|Active | 1|Apache Felix Log Service (1.0.1)|1.0.1
> 7|Active | 1|Apache Felix Metatype Service (1.1.2)|1.1.2
> 8|Active | 1|Apache Felix Declarative Services (2.0.4)|2.0.4
> 12|Active | 1|application (0.1.0)|0.1.0
>
> I'm currently only experimenting, so unless I've seen documentation
> suggesting something, I don't have it installed.
>
> I'll take a look at pax-logging. I use slf4j everywhere else, so
> it seems like the right thing to do.
>
> M
---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@felix.apache.org
For additional commands, e-mail: users-help@felix.apache.org
Re: Logging uncaught exceptions?
Posted by li...@io7m.com.
On 2016-08-04T12:37:02 -0700
David Jencks <da...@yahoo.com.INVALID> wrote:
> BundleActivator behavior and DS component behavior are completely unrelated.
Hm, OK. I erroneously assumed that DS components would be built upon
the activator behaviour. Clearly not!
> I strongly suspect that you haven’t installed anything to record the logging or display it to you? IIRC pax-logging is a popular way to hook osgi logging up to slf4j and make it easy to configure where it goes.
You suspect correctly!
START LEVEL 1
ID|State |Level|Name
0|Active | 0|System Bundle (5.4.0)|5.4.0
1|Active | 1|Apache Felix Bundle Repository (2.0.6)|2.0.6
2|Active | 1|Apache Felix Configuration Admin Service (1.8.10)|1.8.10
3|Active | 1|Apache Felix Gogo Command (0.16.0)|0.16.0
4|Active | 1|Apache Felix Gogo Runtime (0.16.2)|0.16.2
5|Active | 1|Apache Felix Gogo Shell (0.10.0)|0.10.0
6|Active | 1|Apache Felix Log Service (1.0.1)|1.0.1
7|Active | 1|Apache Felix Metatype Service (1.1.2)|1.1.2
8|Active | 1|Apache Felix Declarative Services (2.0.4)|2.0.4
12|Active | 1|application (0.1.0)|0.1.0
I'm currently only experimenting, so unless I've seen documentation
suggesting something, I don't have it installed.
I'll take a look at pax-logging. I use slf4j everywhere else, so
it seems like the right thing to do.
M
Re: Logging uncaught exceptions?
Posted by David Jencks <da...@yahoo.com.INVALID>.
BundleActivator behavior and DS component behavior are completely unrelated.
I strongly suspect that you haven’t installed anything to record the logging or display it to you? IIRC pax-logging is a popular way to hook osgi logging up to slf4j and make it easy to configure where it goes.
thanks
david jencks
> On Aug 4, 2016, at 12:29 PM, list+org.apache.felix@io7m.com wrote:
>
> Hello.
>
> I have a simple declarative service such as:
>
> --8<--
> @Component(immediate = true)
> public final class Speaker implements SpeakerType
> {
> public Speaker()
> {
> System.out.println("Speaker (declarative): constructor");
> }
>
> @Activate
> private void onActivate()
> {
> System.out.println("Speaker (declarative): onActivate");
> }
>
> @Override
> public void speak(final String text)
> {
> System.out.println("Speaker (declarative): speak: " + text);
> }
> }
> -->8--
>
> If I throw an exception in either the constructor or the onActivate()
> method, I get no indication that this has happened. A quick search
> through the core spec for the word "exceptions" leads me to 9.3.6,
> which I think may be relevant even though I'm going through the
> declarative services service:
>
> If the BundleActivator.start or stop method throws an Exception, then
> the handling of this Exception is different depending who invoked
> the start or stop method.
>
> If the bundle is started/stopped due to a change in the active start
> level or the bundle's start level, then the Exception must be wrapped
> in a BundleException and broadcast as a FrameworkEvent.ERROR event.
> Otherwise, a new BundleException must be created containing the
> exception and this BundleException is then thrown to the caller.
>
> So I assume that I need to register some sort of listener to receive
> errors. However, even assuming that I do this: What if the exception is
> of a type that the listener does not import?
>
> Is there a bundle in the distribution that handles this? I have the Log
> service installed, but that doesn't appear to do anything (unless it
> requires extra configuration - I've not given it any). I just
> want errors logged to the console during development so that I don't
> sit here trying to debug silent failures.
>
> M
---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@felix.apache.org
For additional commands, e-mail: users-help@felix.apache.org