Logging and iPOJO

View: New views
4 Messages — Rating Filter:   Alert me  

Logging and iPOJO

by Henrik Niehaus :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

Hi *,

another question concerning iPOJO. I'm wondering how to use the osgi
logging service with iPOJO. Let's assume I want to use the logger like this:

@Component
public class LoggerTest {

    @Requires
    private LogService log;

    @Validate
    public void validate() {
        log.log(LogService.LOG_INFO, "Alles klar. Der Logger is da");
    }

    @Invalidate
    public void invalidate() {
        System.err.println("Verflixt, der logger is weg");
    }
}

Then I would need to convert every class, in which I want to use a
logger, to be a component. That would result in a lot of components.
That doesn't seem to be correct to me. Is there a best practice for
logging and iPOJO?

Cheers
Henrik

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@...
For additional commands, e-mail: users-help@...


Re: Logging and iPOJO

by clement escoffier :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

Hi,

Something recommended is to create a log method to get the logger. I  
also recommend you to set the dependency optional (enabling the  
nullable object support). In that case, if the logger is not there,  
you can still call the log but nothing will happen:


@Component
public class MyApp {


@Requires(optional=true)
private LogService log;

public log(int level, String mes) { // Don't need to be synchronize
        log.(level, mes);
}

...

}

Regards,

Clement


On 10.10.2009, at 16:56, Henrik Niehaus wrote:

> Hi *,
>
> another question concerning iPOJO. I'm wondering how to use the osgi
> logging service with iPOJO. Let's assume I want to use the logger  
> like this:
>
> @Component
> public class LoggerTest {
>
>    @Requires
>    private LogService log;
>
>    @Validate
>    public void validate() {
>        log.log(LogService.LOG_INFO, "Alles klar. Der Logger is da");
>    }
>
>    @Invalidate
>    public void invalidate() {
>        System.err.println("Verflixt, der logger is weg");
>    }
> }
>
> Then I would need to convert every class, in which I want to use a
> logger, to be a component. That would result in a lot of components.
> That doesn't seem to be correct to me. Is there a best practice for
> logging and iPOJO?
>
> Cheers
> Henrik
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@...
> For additional commands, e-mail: users-help@...
>


---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@...
For additional commands, e-mail: users-help@...


Re: Logging and iPOJO

by Henrik Niehaus :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

Hi Clement,

I'm not sure, if I understood you right. Do you mean, I should create a
central method for logging for each bundle? Maybe a static one like
BundleXYLogger.log(...) ?

Clement Escoffier schrieb:

> Hi,
>
> Something recommended is to create a log method to get the logger. I
> also recommend you to set the dependency optional (enabling the nullable
> object support). In that case, if the logger is not there, you can still
> call the log but nothing will happen:
>
>
> @Component
> public class MyApp {
>
>
> @Requires(optional=true)
> private LogService log;
>
> public log(int level, String mes) { // Don't need to be synchronize
>     log.(level, mes);
> }
>
> ...
>
> }
>
> Regards,
>
> Clement
>
>
> On 10.10.2009, at 16:56, Henrik Niehaus wrote:
>
>> Hi *,
>>
>> another question concerning iPOJO. I'm wondering how to use the osgi
>> logging service with iPOJO. Let's assume I want to use the logger like
>> this:
>>
>> @Component
>> public class LoggerTest {
>>
>>    @Requires
>>    private LogService log;
>>
>>    @Validate
>>    public void validate() {
>>        log.log(LogService.LOG_INFO, "Alles klar. Der Logger is da");
>>    }
>>
>>    @Invalidate
>>    public void invalidate() {
>>        System.err.println("Verflixt, der logger is weg");
>>    }
>> }
>>
>> Then I would need to convert every class, in which I want to use a
>> logger, to be a component. That would result in a lot of components.
>> That doesn't seem to be correct to me. Is there a best practice for
>> logging and iPOJO?
>>
>> Cheers
>> Henrik
>>
>> ---------------------------------------------------------------------
>> To unsubscribe, e-mail: users-unsubscribe@...
>> For additional commands, e-mail: users-help@...
>>
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@...
> For additional commands, e-mail: users-help@...
>


--
Mein öffentlicher PGP Schlüssel und Fingerabdruck:
http://hampelratte.org/pgp/

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@...
For additional commands, e-mail: users-help@...


Re: Logging and iPOJO

by clement escoffier :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message


On 10.10.2009, at 21:27, Henrik Niehaus wrote:

> Hi Clement,
>
> I'm not sure, if I understood you right. Do you mean, I should  
> create a
> central method for logging for each bundle? Maybe a static one like
> BundleXYLogger.log(...) ?

OSGi generally discourage using statis.


Something that you can do it to use the 'temporal' dependencies  
injected as proxy. So, the main component have the dependency:
@Requires(proxy=true) // It's not the same @requires
private LogService log;


Then, you give a reference to this object on your sub-components:
myhelper = new MySubComponent(log);

In that case, the log is available from the MySubComponent object. It  
inherits the characteristics from the dependency.

You will find more details on:
http://felix.apache.org/site/how-to-use-ipojo-annotations.html#HowtouseiPOJOAnnotations-TemporalDependencies%2528externalhandler%2529 
  (section Temporal Dependencies (external handler))
and http://felix.apache.org/site/temporal-service-dependency.html


Regards,

Clement

PS: The proxy support will be extended to all service dependencies in  
the 1.6.0.




>
> Clement Escoffier schrieb:
>> Hi,
>>
>> Something recommended is to create a log method to get the logger. I
>> also recommend you to set the dependency optional (enabling the  
>> nullable
>> object support). In that case, if the logger is not there, you can  
>> still
>> call the log but nothing will happen:
>>
>>
>> @Component
>> public class MyApp {
>>
>>
>> @Requires(optional=true)
>> private LogService log;
>>
>> public log(int level, String mes) { // Don't need to be synchronize
>>    log.(level, mes);
>> }
>>
>> ...
>>
>> }
>>
>> Regards,
>>
>> Clement
>>
>>
>> On 10.10.2009, at 16:56, Henrik Niehaus wrote:
>>
>>> Hi *,
>>>
>>> another question concerning iPOJO. I'm wondering how to use the osgi
>>> logging service with iPOJO. Let's assume I want to use the logger  
>>> like
>>> this:
>>>
>>> @Component
>>> public class LoggerTest {
>>>
>>>   @Requires
>>>   private LogService log;
>>>
>>>   @Validate
>>>   public void validate() {
>>>       log.log(LogService.LOG_INFO, "Alles klar. Der Logger is da");
>>>   }
>>>
>>>   @Invalidate
>>>   public void invalidate() {
>>>       System.err.println("Verflixt, der logger is weg");
>>>   }
>>> }
>>>
>>> Then I would need to convert every class, in which I want to use a
>>> logger, to be a component. That would result in a lot of components.
>>> That doesn't seem to be correct to me. Is there a best practice for
>>> logging and iPOJO?
>>>
>>> Cheers
>>> Henrik
>>>
>>> ---------------------------------------------------------------------
>>> To unsubscribe, e-mail: users-unsubscribe@...
>>> For additional commands, e-mail: users-help@...
>>>
>>
>>
>> ---------------------------------------------------------------------
>> To unsubscribe, e-mail: users-unsubscribe@...
>> For additional commands, e-mail: users-help@...
>>
>
>
> --
> Mein öffentlicher PGP Schlüssel und Fingerabdruck:
> http://hampelratte.org/pgp/
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@...
> For additional commands, e-mail: users-help@...
>