You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@directory.apache.org by Emmanuel Lécharny <el...@gmail.com> on 2015/01/11 10:04:26 UTC

[Studio] Logging & Eclipse

Hi !

now that I have - again - a working dev platform for Eclipse - many
thanks Stefan ! - I would like to bring some discussion about logs.

Currently, we are mostly using the getLog().log() method all over the
code. It gets the logger from the plugin. So far, so good, but the pb is
that this approach is only available when you are using it in classes
inheriting from Plugin.

One option, as I can see in the code, would be to grab the plugin logger
like in :

    ConnectionUIPlugin.getDefault().getLog().log( blah... );

but it's a bit heavy, and it does not allow you to discriminate between
errors, warnings or even debug.

In the LdifModificationLogger, we are using JUL to log LDIF parsing
error messages. It's very limited to this class.

All in all, we have very few logs, and the logs we have are mainly
stacktraces or messages we don't know their level of criticity.

So, what about using Log4j? Considering that most of the bundles we are
depending on are using it, why not using it too in Studio ?

Also what would be the impact, and the technical hurdles we would face
if so ?


Wdyt ?



Re: [Studio] Logging & Eclipse

Posted by Emmanuel Lécharny <el...@gmail.com>.
Le 11/01/15 11:58, Stefan Seelmann a écrit :
> Hi Emmanuel,
>
> Pierre-Arnaud and I already tried that. IIRC it is not so easy, if using
> because we are within an OSGi environment. If you use log4j (which is a
> bundle itself) it tries to load the log4j.properties, but it can only
> access resources within its own classloader, so it can't load the
> log4j.properties defined e.g. in a Studio pllugin. There are tricks like
> embedding log4j into the plugin or use "buddy class loading" but all not
> so nice. Pax-logging also exists. Another idea is to create our own
> Logging plugin which provides a logger service.
>
> As we are in Eclipse I'd stick to the log service it provides.
>
> You can create a util class with some convenience methods, see
> PluginUtils in schemaeditor plugin as example.
>
> Eclipse 4 introduced a new programming model, where you can just inject
> a Logger and it also has more convenient logging methods [1]. But that
> migration needs to be done later...
>
> But the most important question: What do you want to achieve? I think
> silently logging into a file within a interactive GUI doesn't make too
> much sense, right?
Right. Except that it would be useful for users who have a problem to
report it into a JIRA with the log attached.

Anyway, maybe the best is to get the plugin you are in, and log using
it, as you can select a level. Atm, it fits my need.



Re: [Studio] Logging & Eclipse

Posted by Stefan Seelmann <ma...@stefan-seelmann.de>.
Hi Emmanuel,

Pierre-Arnaud and I already tried that. IIRC it is not so easy, if using
because we are within an OSGi environment. If you use log4j (which is a
bundle itself) it tries to load the log4j.properties, but it can only
access resources within its own classloader, so it can't load the
log4j.properties defined e.g. in a Studio pllugin. There are tricks like
embedding log4j into the plugin or use "buddy class loading" but all not
so nice. Pax-logging also exists. Another idea is to create our own
Logging plugin which provides a logger service.

As we are in Eclipse I'd stick to the log service it provides.

You can create a util class with some convenience methods, see
PluginUtils in schemaeditor plugin as example.

Eclipse 4 introduced a new programming model, where you can just inject
a Logger and it also has more convenient logging methods [1]. But that
migration needs to be done later...

But the most important question: What do you want to achieve? I think
silently logging into a file within a interactive GUI doesn't make too
much sense, right?

Kind Regards,
Stefan

[1] http://www.vogella.com/tutorials/EclipseLogging/article.html#logging



On 01/11/2015 10:04 AM, Emmanuel Lécharny wrote:
> Hi !
> 
> now that I have - again - a working dev platform for Eclipse - many
> thanks Stefan ! - I would like to bring some discussion about logs.
> 
> Currently, we are mostly using the getLog().log() method all over the
> code. It gets the logger from the plugin. So far, so good, but the pb is
> that this approach is only available when you are using it in classes
> inheriting from Plugin.
> 
> One option, as I can see in the code, would be to grab the plugin logger
> like in :
> 
>     ConnectionUIPlugin.getDefault().getLog().log( blah... );
> 
> but it's a bit heavy, and it does not allow you to discriminate between
> errors, warnings or even debug.
> 
> In the LdifModificationLogger, we are using JUL to log LDIF parsing
> error messages. It's very limited to this class.
> 
> All in all, we have very few logs, and the logs we have are mainly
> stacktraces or messages we don't know their level of criticity.
> 
> So, what about using Log4j? Considering that most of the bundles we are
> depending on are using it, why not using it too in Studio ?
> 
> Also what would be the impact, and the technical hurdles we would face
> if so ?
> 
> 
> Wdyt ?
> 
> 


Re: [Studio] Logging & Eclipse

Posted by Emmanuel Lécharny <el...@gmail.com>.
Le 11/01/15 10:04, Emmanuel Lécharny a écrit :
> Hi !
>
> now that I have - again - a working dev platform for Eclipse - many
> thanks Stefan ! - I would like to bring some discussion about logs.
>
> Currently, we are mostly using the getLog().log() method all over the
> code. It gets the logger from the plugin. So far, so good, but the pb is
> that this approach is only available when you are using it in classes
> inheriting from Plugin.
>
> One option, as I can see in the code, would be to grab the plugin logger
> like in :
>
>     ConnectionUIPlugin.getDefault().getLog().log( blah... );
>
> but it's a bit heavy, and it does not allow you to discriminate between
> errors, warnings or even debug.
>
> In the LdifModificationLogger, we are using JUL to log LDIF parsing
> error messages. It's very limited to this class.
>
> All in all, we have very few logs, and the logs we have are mainly
> stacktraces or messages we don't know their level of criticity.
>
> So, what about using Log4j? Considering that most of the bundles we are
> depending on are using it, why not using it too in Studio ?
>
> Also what would be the impact, and the technical hurdles we would face
> if so ?
>
>
> Wdyt ?
>
>
I was more specifically thinking about using code like :

public class OpenConfigurationAction implements IObjectActionDelegate
{
    /** The logger for this class
    private static final Logger LOG = LoggerFactory.getLogger(
OpenConfigurationAction.class );
...

or :

public class OpenConfigurationAction implements IObjectActionDelegate
{
    /** The logger for this class
    private static final Logger LOG = LoggerFactory.getLogger(
"org.apache.directory.studio.apacheds.configuration.v2" );

instead of doing :

...
                catch ( PartInitException e )
                {
                    ApacheDS2ConfigurationPlugin.getDefault().getLog().log(
                        new Status( Status.ERROR,
"org.apache.directory.studio.apacheds.configuration.v2",
                            e.getMessage() ) );

...


PS : I'm into the OpenConfigurationAction class in the
apacheds.configuration.v2 plugin.