You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@karaf.apache.org by Paul Fraser <pa...@qnenet.com> on 2019/05/01 10:56:46 UTC

New OSGi R7 Logging in Karaf

Hi,

B J Hargrave has developed an Slf4j/OSGi bundle which routes all slf4j log events to the new R7 osgi 
log service.

https://www.youtube.com/watch?v=DJF0aETiNec&feature=youtu.be about 24 mins in.

19min 30s into video he shows how the new log service is used ()

  ===========================

   @Reference(service=LoggerFactory.class)

     private Logger logger;

and then as usual in code

     logger.info("Hello new bundle");

=============================

  I would like to be able to use this new logging asusage in code requires only this @Reference 
entry and no need for the slf4j code usually required in every bundle.

Being very new to Karaf, any guidance available as to how to set up the logging config to achieve 
this end would be most appreciated.

I am running Karaf 4.3-SNAPSHOT.

Paul Fraser






Re: New OSGi R7 Logging in Karaf

Posted by Jean-Baptiste Onofré <jb...@nanthrax.net>.
Hi Paul,

We are working on updating Pax Logging to leverage the R7 features.

Karaf master (4.3.0-SNAPSHOT) is in process of fully upgrading to R7,
but it's not yet complete.

Anyway, in existing Karaf releases, you can already use a LoggerFactory
service provided by Pax Logging.

Regards
JB

On 01/05/2019 12:56, Paul Fraser wrote:
> Hi,
> 
> B J Hargrave has developed an Slf4j/OSGi bundle which routes all slf4j
> log events to the new R7 osgi log service.
> 
> https://www.youtube.com/watch?v=DJF0aETiNec&feature=youtu.be about 24
> mins in.
> 
> 19min 30s into video he shows how the new log service is used ()
> 
>  ===========================
> 
>   @Reference(service=LoggerFactory.class)
> 
>     private Logger logger;
> 
> and then as usual in code
> 
>     logger.info("Hello new bundle");
> 
> =============================
> 
>  I would like to be able to use this new logging asusage in code
> requires only this @Reference entry and no need for the slf4j code
> usually required in every bundle.
> 
> Being very new to Karaf, any guidance available as to how to set up the
> logging config to achieve this end would be most appreciated.
> 
> I am running Karaf 4.3-SNAPSHOT.
> 
> Paul Fraser
> 
> 
> 
> 
> 

-- 
Jean-Baptiste Onofré
jbonofre@apache.org
http://blog.nanthrax.net
Talend - http://www.talend.com

Re: New OSGi R7 Logging in Karaf

Posted by Jean-Baptiste Onofré <jb...@nanthrax.net>.
Hi

I agree with Joao, for me it's pretty simple to use SLF4J Logger, and
it's just an optional import.

However, to be fully R7 compliant, I'm updating Pax Logging.

Regards
JB

On 01/05/2019 17:04, João Assunção wrote:
> @Paul, what is the issue with using SLF4J?  
> SLF4J code in every bundle? Usually, the only SLF4J code I have is:
> 
>     private static final Logger LOGGER =
>     LoggerFactory.getLogger(Acme.class); 
> 
> The LoggerFactory provided by Karaf (Pax Logging) will take care of the
> rest.
> 
> For the Log service to be injected, as shown in your example, all the
> classes requiring a logger will need to be DS components. You probably
> don't want/need that.
> During unit test, you will also need to "inject"/set the logger.
> My suggestion is to stick with SLF4J. Your code will be independent of
> the logging library/framework running under the hood, and probably most
> of the libraries you are using are also using SLF4J.
> 
> Best regards,
> João Assunção
> 
> Email: joao.assuncao@exploitsys.com <ma...@exploitsys.com>
> Mobile: +351 916968984
> Phone: +351 211933149
> Web: www.exploitsys.com <http://www.exploitsys.com>
> 
> 
> 
> 
> On Wed, May 1, 2019 at 1:27 PM Jean-Baptiste Onofré <jb@nanthrax.net
> <ma...@nanthrax.net>> wrote:
> 
>     By the way, I will blog and send an update on the mailing list about R7
>     in Karaf, I will add a section about the logging.
> 
>     Regards
>     JB
> 
>     On 01/05/2019 12:56, Paul Fraser wrote:
>     > Hi,
>     >
>     > B J Hargrave has developed an Slf4j/OSGi bundle which routes all slf4j
>     > log events to the new R7 osgi log service.
>     >
>     > https://www.youtube.com/watch?v=DJF0aETiNec&feature=youtu.be about 24
>     > mins in.
>     >
>     > 19min 30s into video he shows how the new log service is used ()
>     >
>     >  ===========================
>     >
>     >   @Reference(service=LoggerFactory.class)
>     >
>     >     private Logger logger;
>     >
>     > and then as usual in code
>     >
>     >     logger.info <http://logger.info>("Hello new bundle");
>     >
>     > =============================
>     >
>     >  I would like to be able to use this new logging asusage in code
>     > requires only this @Reference entry and no need for the slf4j code
>     > usually required in every bundle.
>     >
>     > Being very new to Karaf, any guidance available as to how to set
>     up the
>     > logging config to achieve this end would be most appreciated.
>     >
>     > I am running Karaf 4.3-SNAPSHOT.
>     >
>     > Paul Fraser
>     >
>     >
>     >
>     >
>     >
> 
>     -- 
>     Jean-Baptiste Onofré
>     jbonofre@apache.org <ma...@apache.org>
>     http://blog.nanthrax.net
>     Talend - http://www.talend.com
> 

-- 
Jean-Baptiste Onofré
jbonofre@apache.org
http://blog.nanthrax.net
Talend - http://www.talend.com

Re: New OSGi R7 Logging in Karaf

Posted by João Assunção <jo...@exploitsys.com>.
@Paul, what is the issue with using SLF4J?
SLF4J code in every bundle? Usually, the only SLF4J code I have is:

> private static final Logger LOGGER = LoggerFactory.getLogger(Acme.class);

The LoggerFactory provided by Karaf (Pax Logging) will take care of the
rest.

For the Log service to be injected, as shown in your example, all the
classes requiring a logger will need to be DS components. You probably
don't want/need that.
During unit test, you will also need to "inject"/set the logger.
My suggestion is to stick with SLF4J. Your code will be independent of the
logging library/framework running under the hood, and probably most of the
libraries you are using are also using SLF4J.

Best regards,
João Assunção

Email: joao.assuncao@exploitsys.com
Mobile: +351 916968984
Phone: +351 211933149
Web: www.exploitsys.com




On Wed, May 1, 2019 at 1:27 PM Jean-Baptiste Onofré <jb...@nanthrax.net> wrote:

> By the way, I will blog and send an update on the mailing list about R7
> in Karaf, I will add a section about the logging.
>
> Regards
> JB
>
> On 01/05/2019 12:56, Paul Fraser wrote:
> > Hi,
> >
> > B J Hargrave has developed an Slf4j/OSGi bundle which routes all slf4j
> > log events to the new R7 osgi log service.
> >
> > https://www.youtube.com/watch?v=DJF0aETiNec&feature=youtu.be about 24
> > mins in.
> >
> > 19min 30s into video he shows how the new log service is used ()
> >
> >  ===========================
> >
> >   @Reference(service=LoggerFactory.class)
> >
> >     private Logger logger;
> >
> > and then as usual in code
> >
> >     logger.info("Hello new bundle");
> >
> > =============================
> >
> >  I would like to be able to use this new logging asusage in code
> > requires only this @Reference entry and no need for the slf4j code
> > usually required in every bundle.
> >
> > Being very new to Karaf, any guidance available as to how to set up the
> > logging config to achieve this end would be most appreciated.
> >
> > I am running Karaf 4.3-SNAPSHOT.
> >
> > Paul Fraser
> >
> >
> >
> >
> >
>
> --
> Jean-Baptiste Onofré
> jbonofre@apache.org
> http://blog.nanthrax.net
> Talend - http://www.talend.com
>

Re: New OSGi R7 Logging in Karaf

Posted by Jean-Baptiste Onofré <jb...@nanthrax.net>.
By the way, I will blog and send an update on the mailing list about R7
in Karaf, I will add a section about the logging.

Regards
JB

On 01/05/2019 12:56, Paul Fraser wrote:
> Hi,
> 
> B J Hargrave has developed an Slf4j/OSGi bundle which routes all slf4j
> log events to the new R7 osgi log service.
> 
> https://www.youtube.com/watch?v=DJF0aETiNec&feature=youtu.be about 24
> mins in.
> 
> 19min 30s into video he shows how the new log service is used ()
> 
>  ===========================
> 
>   @Reference(service=LoggerFactory.class)
> 
>     private Logger logger;
> 
> and then as usual in code
> 
>     logger.info("Hello new bundle");
> 
> =============================
> 
>  I would like to be able to use this new logging asusage in code
> requires only this @Reference entry and no need for the slf4j code
> usually required in every bundle.
> 
> Being very new to Karaf, any guidance available as to how to set up the
> logging config to achieve this end would be most appreciated.
> 
> I am running Karaf 4.3-SNAPSHOT.
> 
> Paul Fraser
> 
> 
> 
> 
> 

-- 
Jean-Baptiste Onofré
jbonofre@apache.org
http://blog.nanthrax.net
Talend - http://www.talend.com