Writing the servicemix.log within custom java

classic Classic list List threaded Threaded
7 messages Options
Reply | Threaded
Open this post in threaded view
|

Writing the servicemix.log within custom java

Castyn
I was wondering how I can go about writing to this log from within custom java code I have that will be called by the route as a bean.  
Reply | Threaded
Open this post in threaded view
|

Re: Writing the servicemix.log within custom java

jbonofre
Hi,

you can define a logger that use the same appender.

Take a look in etc/org.ops4j.pax.logging.cfg to define your own logger
(on your package) and use the out appender.

Regards
JB

On 01/23/2012 04:55 PM, Castyn wrote:
> I was wondering how I can go about writing to this log from within custom
> java code I have that will be called by the route as a bean.
>
> --
> View this message in context: http://camel.465427.n5.nabble.com/Writing-the-servicemix-log-within-custom-java-tp5166486p5166486.html
> Sent from the Camel - Users mailing list archive at Nabble.com.

--
Jean-Baptiste Onofré
[hidden email]
http://blog.nanthrax.net
Talend - http://www.talend.com
Reply | Threaded
Open this post in threaded view
|

Re: Writing the servicemix.log within custom java

Castyn
Is there an example of this somewhere, I am fairly new to the majority of this.

In the file you mentioned I see

# Root logger
log4j.rootLogger = INFO, out, osgi:VmLogAppender
log4j.throwableRenderer=org.apache.log4j.OsgiThrowableRenderer

# CONSOLE appender not used by default
log4j.appender.stdout=org.apache.log4j.ConsoleAppender
log4j.appender.stdout.layout=org.apache.log4j.PatternLayout
log4j.appender.stdout.layout.ConversionPattern=%d{ABSOLUTE} | %-5.5p | %-16.16t | %-32.32c{1} | %X{bundle.id} - %X{bundle.name} - %X{bundle.version} | %m%n

# File appender
log4j.appender.out=org.apache.log4j.RollingFileAppender
log4j.appender.out.layout=org.apache.log4j.PatternLayout
log4j.appender.out.layout.ConversionPattern=%d{ABSOLUTE} | %-5.5p | %-16.16t | %-32.32c{1} | %X{bundle.id} - %X{bundle.name} - %X{bundle.version} | %m%n
log4j.appender.out.file=${karaf.data}/log/servicemix.log
log4j.appender.out.append=true
log4j.appender.out.maxFileSize=100MB
log4j.appender.out.maxBackupIndex=10

# Sift appender
log4j.appender.sift=org.apache.log4j.sift.MDCSiftingAppender
log4j.appender.sift.key=bundle.name
log4j.appender.sift.default=servicemix
log4j.appender.sift.appender=org.apache.log4j.FileAppender
log4j.appender.sift.appender.layout=org.apache.log4j.PatternLayout
log4j.appender.sift.appender.layout.ConversionPattern=%d{ABSOLUTE} | %-5.5p | %-16.16t | %-32.32c{1} | %m%n
log4j.appender.sift.appender.file=${karaf.data}/log/$\\{bundle.name\\}.log
log4j.appender.sift.appender.append=true
log4j.logger.org.apache.camel = INFO


I'm not sure how to create one here as well as in my code to properly have it use one of these appenders.  Sorry for being a newb!
Reply | Threaded
Open this post in threaded view
|

Re: Writing the servicemix.log within custom java

Gert Vanthienen
Administrator
L.S.,

You probably don't have edit this configuration file at all - if you want,
you can use it to e.g. create a separate log file for your own code or
something, but if you just want to write to servicemix.log, everything
should be good to go.

Just use any of the logging frameworks you're familiar with (slf4j, log4j,
commons-logging, ...) from within your own Java code.  In ServiceMix,
logging from all these frameworks is being handled by Pax Logging, so it
will automatically end up in the servicemix.log file.

Regards,

Gert Vanthienen
------------------------
FuseSource
Web: http://fusesource.com
Blog: http://gertvanthienen.blogspot.com/


On Mon, Jan 23, 2012 at 5:57 PM, Castyn <[hidden email]> wrote:

> Is there an example of this somewhere, I am fairly new to the majority of
> this.
>
> In the file you mentioned I see
>
> # Root logger
> log4j.rootLogger = INFO, out, osgi:VmLogAppender
> log4j.throwableRenderer=org.apache.log4j.OsgiThrowableRenderer
>
> # CONSOLE appender not used by default
> log4j.appender.stdout=org.apache.log4j.ConsoleAppender
> log4j.appender.stdout.layout=org.apache.log4j.PatternLayout
> log4j.appender.stdout.layout.ConversionPattern=%d{ABSOLUTE} | %-5.5p |
> %-16.16t | %-32.32c{1} | %X{bundle.id} - %X{bundle.name} -
> %X{bundle.version} | %m%n
>
> # File appender
> log4j.appender.out=org.apache.log4j.RollingFileAppender
> log4j.appender.out.layout=org.apache.log4j.PatternLayout
> log4j.appender.out.layout.ConversionPattern=%d{ABSOLUTE} | %-5.5p |
> %-16.16t
> | %-32.32c{1} | %X{bundle.id} - %X{bundle.name} - %X{bundle.version} |
> %m%n
> log4j.appender.out.file=${karaf.data}/log/servicemix.log
> log4j.appender.out.append=true
> log4j.appender.out.maxFileSize=100MB
> log4j.appender.out.maxBackupIndex=10
>
> # Sift appender
> log4j.appender.sift=org.apache.log4j.sift.MDCSiftingAppender
> log4j.appender.sift.key=bundle.name
> log4j.appender.sift.default=servicemix
> log4j.appender.sift.appender=org.apache.log4j.FileAppender
> log4j.appender.sift.appender.layout=org.apache.log4j.PatternLayout
> log4j.appender.sift.appender.layout.ConversionPattern=%d{ABSOLUTE} | %-5.5p
> | %-16.16t | %-32.32c{1} | %m%n
> log4j.appender.sift.appender.file=${karaf.data}/log/$\\{bundle.name\\}.log
> log4j.appender.sift.appender.append=true
> log4j.logger.org.apache.camel = INFO
>
>
> I'm not sure how to create one here as well as in my code to properly have
> it use one of these appenders.  Sorry for being a newb!
>
> --
> View this message in context:
> http://camel.465427.n5.nabble.com/Writing-the-servicemix-log-within-custom-java-tp5166486p5166698.html
> Sent from the Camel - Users mailing list archive at Nabble.com.
>
Regards,

Gert Vanthienen
------------------------
Open Source SOA: http://fusesource.com
Blog: http://gertvanthienen.blogspot.com/
Reply | Threaded
Open this post in threaded view
|

Re: Writing the servicemix.log within custom java

jbonofre
Hi Gert,

maybe I misunderstood the requirement. If the user want to create its
own log file, he has to modify the org.ops4j.pax.logging.cfg file (to
add its logger/appender).

Else, if it's just to log into servicemix.log, as the rootLogger does it
already, as you said, just logging (using slf4j, commons-logging, etc)
is enough ;)

Regards
JB

On 01/24/2012 09:38 AM, Gert Vanthienen wrote:

> L.S.,
>
> You probably don't have edit this configuration file at all - if you want,
> you can use it to e.g. create a separate log file for your own code or
> something, but if you just want to write to servicemix.log, everything
> should be good to go.
>
> Just use any of the logging frameworks you're familiar with (slf4j, log4j,
> commons-logging, ...) from within your own Java code.  In ServiceMix,
> logging from all these frameworks is being handled by Pax Logging, so it
> will automatically end up in the servicemix.log file.
>
> Regards,
>
> Gert Vanthienen
> ------------------------
> FuseSource
> Web: http://fusesource.com
> Blog: http://gertvanthienen.blogspot.com/
>
>
> On Mon, Jan 23, 2012 at 5:57 PM, Castyn<[hidden email]>  wrote:
>
>> Is there an example of this somewhere, I am fairly new to the majority of
>> this.
>>
>> In the file you mentioned I see
>>
>> # Root logger
>> log4j.rootLogger = INFO, out, osgi:VmLogAppender
>> log4j.throwableRenderer=org.apache.log4j.OsgiThrowableRenderer
>>
>> # CONSOLE appender not used by default
>> log4j.appender.stdout=org.apache.log4j.ConsoleAppender
>> log4j.appender.stdout.layout=org.apache.log4j.PatternLayout
>> log4j.appender.stdout.layout.ConversionPattern=%d{ABSOLUTE} | %-5.5p |
>> %-16.16t | %-32.32c{1} | %X{bundle.id} - %X{bundle.name} -
>> %X{bundle.version} | %m%n
>>
>> # File appender
>> log4j.appender.out=org.apache.log4j.RollingFileAppender
>> log4j.appender.out.layout=org.apache.log4j.PatternLayout
>> log4j.appender.out.layout.ConversionPattern=%d{ABSOLUTE} | %-5.5p |
>> %-16.16t
>> | %-32.32c{1} | %X{bundle.id} - %X{bundle.name} - %X{bundle.version} |
>> %m%n
>> log4j.appender.out.file=${karaf.data}/log/servicemix.log
>> log4j.appender.out.append=true
>> log4j.appender.out.maxFileSize=100MB
>> log4j.appender.out.maxBackupIndex=10
>>
>> # Sift appender
>> log4j.appender.sift=org.apache.log4j.sift.MDCSiftingAppender
>> log4j.appender.sift.key=bundle.name
>> log4j.appender.sift.default=servicemix
>> log4j.appender.sift.appender=org.apache.log4j.FileAppender
>> log4j.appender.sift.appender.layout=org.apache.log4j.PatternLayout
>> log4j.appender.sift.appender.layout.ConversionPattern=%d{ABSOLUTE} | %-5.5p
>> | %-16.16t | %-32.32c{1} | %m%n
>> log4j.appender.sift.appender.file=${karaf.data}/log/$\\{bundle.name\\}.log
>> log4j.appender.sift.appender.append=true
>> log4j.logger.org.apache.camel = INFO
>>
>>
>> I'm not sure how to create one here as well as in my code to properly have
>> it use one of these appenders.  Sorry for being a newb!
>>
>> --
>> View this message in context:
>> http://camel.465427.n5.nabble.com/Writing-the-servicemix-log-within-custom-java-tp5166486p5166698.html
>> Sent from the Camel - Users mailing list archive at Nabble.com.
>>
>

--
Jean-Baptiste Onofré
[hidden email]
http://blog.nanthrax.net
Talend - http://www.talend.com
Reply | Threaded
Open this post in threaded view
|

RE: Writing the servicemix.log within custom java

atiato

Check the attached , how I'm sending log to Router.txt (daily logging).

Everything should be logged into that file and will be renamed daily.

-----Original Message-----
From: Jean-Baptiste Onofré [mailto:[hidden email]]
Sent: Tuesday, January 24, 2012 10:45 AM
To: [hidden email]
Subject: Re: Writing the servicemix.log within custom java

Hi Gert,

maybe I misunderstood the requirement. If the user want to create its
own log file, he has to modify the org.ops4j.pax.logging.cfg file (to
add its logger/appender).

Else, if it's just to log into servicemix.log, as the rootLogger does it
already, as you said, just logging (using slf4j, commons-logging, etc)
is enough ;)

Regards
JB

On 01/24/2012 09:38 AM, Gert Vanthienen wrote:

> L.S.,
>
> You probably don't have edit this configuration file at all - if you want,
> you can use it to e.g. create a separate log file for your own code or
> something, but if you just want to write to servicemix.log, everything
> should be good to go.
>
> Just use any of the logging frameworks you're familiar with (slf4j, log4j,
> commons-logging, ...) from within your own Java code.  In ServiceMix,
> logging from all these frameworks is being handled by Pax Logging, so it
> will automatically end up in the servicemix.log file.
>
> Regards,
>
> Gert Vanthienen
> ------------------------
> FuseSource
> Web: http://fusesource.com
> Blog: http://gertvanthienen.blogspot.com/
>
>
> On Mon, Jan 23, 2012 at 5:57 PM, Castyn<[hidden email]>  wrote:
>
>> Is there an example of this somewhere, I am fairly new to the majority of
>> this.
>>
>> In the file you mentioned I see
>>
>> # Root logger
>> log4j.rootLogger = INFO, out, osgi:VmLogAppender
>> log4j.throwableRenderer=org.apache.log4j.OsgiThrowableRenderer
>>
>> # CONSOLE appender not used by default
>> log4j.appender.stdout=org.apache.log4j.ConsoleAppender
>> log4j.appender.stdout.layout=org.apache.log4j.PatternLayout
>> log4j.appender.stdout.layout.ConversionPattern=%d{ABSOLUTE} | %-5.5p |
>> %-16.16t | %-32.32c{1} | %X{bundle.id} - %X{bundle.name} -
>> %X{bundle.version} | %m%n
>>
>> # File appender
>> log4j.appender.out=org.apache.log4j.RollingFileAppender
>> log4j.appender.out.layout=org.apache.log4j.PatternLayout
>> log4j.appender.out.layout.ConversionPattern=%d{ABSOLUTE} | %-5.5p |
>> %-16.16t
>> | %-32.32c{1} | %X{bundle.id} - %X{bundle.name} - %X{bundle.version} |
>> %m%n
>> log4j.appender.out.file=${karaf.data}/log/servicemix.log
>> log4j.appender.out.append=true
>> log4j.appender.out.maxFileSize=100MB
>> log4j.appender.out.maxBackupIndex=10
>>
>> # Sift appender
>> log4j.appender.sift=org.apache.log4j.sift.MDCSiftingAppender
>> log4j.appender.sift.key=bundle.name
>> log4j.appender.sift.default=servicemix
>> log4j.appender.sift.appender=org.apache.log4j.FileAppender
>> log4j.appender.sift.appender.layout=org.apache.log4j.PatternLayout
>> log4j.appender.sift.appender.layout.ConversionPattern=%d{ABSOLUTE} | %-5.5p
>> | %-16.16t | %-32.32c{1} | %m%n
>> log4j.appender.sift.appender.file=${karaf.data}/log/$\\{bundle.name\\}.log
>> log4j.appender.sift.appender.append=true
>> log4j.logger.org.apache.camel = INFO
>>
>>
>> I'm not sure how to create one here as well as in my code to properly have
>> it use one of these appenders.  Sorry for being a newb!
>>
>> --
>> View this message in context:
>> http://camel.465427.n5.nabble.com/Writing-the-servicemix-log-within-custom-java-tp5166486p5166698.html
>> Sent from the Camel - Users mailing list archive at Nabble.com.
>>
>
--
Jean-Baptiste Onofré
[hidden email]
http://blog.nanthrax.net
Talend - http://www.talend.com
Reply | Threaded
Open this post in threaded view
|

Re: Writing the servicemix.log within custom java

Raul Kripalani-2
In reply to this post by jbonofre
Take into account that the log level of your logging statements will affect
whether they are displayed on servicemix.log or not. The default
configuration sets the log level for the ROOT logger to INFO, meaning that
only statements with severity equal or above INFO will actually appear on
the log file (INFO, WARN, ERROR).

You can configure the logging level of the ROOT logger in the config file
that Jean-Baptiste mentioned, so you can decrease it to DEBUG or TRACE if
you want to see more verbosity.

I recommend that you use the SLF4j API from within your code, even though
PAX Logging will capture the output from various other frameworks as Gert
mentioned. To add the SLF4J dependency:

    <dependency>

      <groupId>org.slf4j</groupId>

      <artifactId>slf4j-api</artifactId>

      <version>...</version>

    </dependency>
Check what version of SLF4J your SMX container is using and copy it to the
version element for a quick start.

Regards,
Raúl.

On 24 January 2012 08:44, Jean-Baptiste Onofré <[hidden email]> wrote:

> Hi Gert,
>
> maybe I misunderstood the requirement. If the user want to create its own
> log file, he has to modify the org.ops4j.pax.logging.cfg file (to add its
> logger/appender).
>
> Else, if it's just to log into servicemix.log, as the rootLogger does it
> already, as you said, just logging (using slf4j, commons-logging, etc) is
> enough ;)
>
> Regards
> JB
>
>
> On 01/24/2012 09:38 AM, Gert Vanthienen wrote:
>
>> L.S.,
>>
>> You probably don't have edit this configuration file at all - if you want,
>> you can use it to e.g. create a separate log file for your own code or
>> something, but if you just want to write to servicemix.log, everything
>> should be good to go.
>>
>> Just use any of the logging frameworks you're familiar with (slf4j, log4j,
>> commons-logging, ...) from within your own Java code.  In ServiceMix,
>> logging from all these frameworks is being handled by Pax Logging, so it
>> will automatically end up in the servicemix.log file.
>>
>> Regards,
>>
>> Gert Vanthienen
>> ------------------------
>> FuseSource
>> Web: http://fusesource.com
>> Blog: http://gertvanthienen.**blogspot.com/<http://gertvanthienen.blogspot.com/>
>>
>>
>> On Mon, Jan 23, 2012 at 5:57 PM, Castyn<[hidden email]>  wrote:
>>
>>  Is there an example of this somewhere, I am fairly new to the majority of
>>> this.
>>>
>>> In the file you mentioned I see
>>>
>>> # Root logger
>>> log4j.rootLogger = INFO, out, osgi:VmLogAppender
>>> log4j.throwableRenderer=org.**apache.log4j.**OsgiThrowableRenderer
>>>
>>> # CONSOLE appender not used by default
>>> log4j.appender.stdout=org.**apache.log4j.ConsoleAppender
>>> log4j.appender.stdout.layout=**org.apache.log4j.PatternLayout
>>> log4j.appender.stdout.layout.**ConversionPattern=%d{ABSOLUTE} | %-5.5p |
>>> %-16.16t | %-32.32c{1} | %X{bundle.id} - %X{bundle.name} -
>>> %X{bundle.version} | %m%n
>>>
>>> # File appender
>>> log4j.appender.out=org.apache.**log4j.RollingFileAppender
>>> log4j.appender.out.layout=org.**apache.log4j.PatternLayout
>>> log4j.appender.out.layout.**ConversionPattern=%d{ABSOLUTE} | %-5.5p |
>>> %-16.16t
>>> | %-32.32c{1} | %X{bundle.id} - %X{bundle.name} - %X{bundle.version} |
>>> %m%n
>>> log4j.appender.out.file=${**karaf.data}/log/servicemix.log
>>> log4j.appender.out.append=true
>>> log4j.appender.out.**maxFileSize=100MB
>>> log4j.appender.out.**maxBackupIndex=10
>>>
>>> # Sift appender
>>> log4j.appender.sift=org.**apache.log4j.sift.**MDCSiftingAppender
>>> log4j.appender.sift.key=bundle**.name <http://bundle.name>
>>> log4j.appender.sift.default=**servicemix
>>> log4j.appender.sift.appender=**org.apache.log4j.FileAppender
>>> log4j.appender.sift.appender.**layout=org.apache.log4j.**PatternLayout
>>> log4j.appender.sift.appender.**layout.ConversionPattern=%d{**ABSOLUTE}
>>> | %-5.5p
>>> | %-16.16t | %-32.32c{1} | %m%n
>>> log4j.appender.sift.appender.**file=${karaf.data}/log/$\\{bun**dle.name<http://bundle.name>
>>> \\}.log
>>> log4j.appender.sift.appender.**append=true
>>> log4j.logger.org.apache.camel = INFO
>>>
>>>
>>> I'm not sure how to create one here as well as in my code to properly
>>> have
>>> it use one of these appenders.  Sorry for being a newb!
>>>
>>> --
>>> View this message in context:
>>> http://camel.465427.n5.nabble.**com/Writing-the-servicemix-**
>>> log-within-custom-java-**tp5166486p5166698.html<http://camel.465427.n5.nabble.com/Writing-the-servicemix-log-within-custom-java-tp5166486p5166698.html>
>>> Sent from the Camel - Users mailing list archive at Nabble.com.
>>>
>>>
>>
> --
> Jean-Baptiste Onofré
> [hidden email]
> http://blog.nanthrax.net
> Talend - http://www.talend.com
>