how to use the ops4j logging

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

how to use the ops4j logging

a175335
This post was updated on .
I want to make a logging bundle and have read some information about the ops4j.But, I still don't have idea  to extend it for my own components.How should I do? Can somebody give me some advice? I use ServiceMix and  deploy my own bundle .Through 'log4j.xml' file to generat I want the log files
Reply | Threaded
Open this post in threaded view
|

Re: how to use the ops4j logging

Achim Nierbeck
Could you give us some more details, on what you're trying to achieve?
Are you planning on extending log4j with some custom appenders?
Are you planning on using any kind of logging in your application?

regards, Achim


2014-06-16 10:56 GMT+02:00 a175335 <[hidden email]>:

> I want to make a logging bundle and have read some information about the
> ops4j.But, I still don't have idea  to extend it for my own components.How
> should I do? Can somebody give me some advice?
>
>
>
> --
> View this message in context:
> http://servicemix.396122.n5.nabble.com/how-to-use-the-ops4j-logging-tp5720883.html
> Sent from the ServiceMix - Dev mailing list archive at Nabble.com.
>



--

Apache Member
Apache Karaf <http://karaf.apache.org/> Committer & PMC
OPS4J Pax Web <http://wiki.ops4j.org/display/paxweb/Pax+Web/> Committer &
Project Lead
blog <http://notizblog.nierbeck.de/>

Software Architect / Project Manager / Scrum Master
Reply | Threaded
Open this post in threaded view
|

Re: how to use the ops4j logging

a175335
hi Achim :
   
           thanks for your reply.I want to build a common log component. So, I create a OSGI bundle which export a LogService. All the other bundles import the log sevice .In the Osgi bundle ,I want to use the 'log4j.xml'  as the configuration file and  plan on extending log4j with some custom appenders. All of the logs handed by the bundle.
Reply | Threaded
Open this post in threaded view
|

Re: how to use the ops4j logging

Jean-Baptiste Onofré
Hi,

you don't need it: it's already the purpose of pax-logging.

Take a look on Karaf log documentation (used in ServiceMix):

http://karaf.apache.org/manual/latest/users-guide/log.html

Regards
JB

On 06/16/2014 03:37 PM, a175335 wrote:

> hi Achim :
>
>             thanks for your reply.I want to build a common log component. So,
> I create a OSGI bundle which export a LogService. All the other bundles
> import the log sevice .In the Osgi bundle ,I want to use the 'log4j.xml'  as
> the configuration file and  plan on extending log4j with some custom
> appenders. All of the logs handed by the bundle.
>
>
>
> --
> View this message in context: http://servicemix.396122.n5.nabble.com/how-to-use-the-ops4j-logging-tp5720883p5720898.html
> Sent from the ServiceMix - Dev 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: how to use the ops4j logging

a175335
hi:
 is the 'log4j.xml' configuration file supported?
       
 
 

Reply | Threaded
Open this post in threaded view
|

Re: how to use the ops4j logging

Jean-Baptiste Onofré
Not yet, the etc/org.ops4j.pax.logging.cfg uses the log4j properties format.

Regards
JB

On 06/16/2014 03:55 PM, a175335 wrote:

> hi:
>   is the 'log4j.xml' configuration file supported?
>
>
>
>
>
>
>
>
> --
> View this message in context: http://servicemix.396122.n5.nabble.com/how-to-use-the-ops4j-logging-tp5720883p5720900.html
> Sent from the ServiceMix - Dev 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: how to use the ops4j logging

Guillaume Nodet-7
Note that everything supported by the log4j xml is available (afaik) in the
pax-logging properties format, as it has been enhanced from the default
log4j properties file.


2014-06-16 16:29 GMT+02:00 Jean-Baptiste Onofré <[hidden email]>:

> Not yet, the etc/org.ops4j.pax.logging.cfg uses the log4j properties
> format.
>
> Regards
> JB
>
>
> On 06/16/2014 03:55 PM, a175335 wrote:
>
>> hi:
>>   is the 'log4j.xml' configuration file supported?
>>
>>
>>
>>
>>
>>
>>
>>
>> --
>> View this message in context: http://servicemix.396122.n5.
>> nabble.com/how-to-use-the-ops4j-logging-tp5720883p5720900.html
>> Sent from the ServiceMix - Dev 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: how to use the ops4j logging

a175335
hi :

  I make a customer demo below,


package org.ops4j.pax.logging.file;

import java.util.Date;

import org.apache.log4j.RollingFileAppender;
import org.apache.log4j.helpers.CountingQuietWriter;
import org.apache.log4j.spi.LoggingEvent;
import org.ops4j.pax.logging.bo.Log;

public class FileAppender extends RollingFileAppender {

        public FileAppender() {

        }

        private String format(LoggingEvent event) {
                Log log = (Log) event.getMessage();
                log.setThreadName(event.getThreadName());
                log.setLocationInfo(event.getLocationInformation().fullInfo);
                log.setLevel(event.getLevel().toString());
                log.setTime(new Date(event.timeStamp));
                log.setLoggerName(event.getLoggerName());

                return log.toString();
        }

        protected void subAppend(LoggingEvent event) {
                if (!(event.getMessage() instanceof Log)) {
                        return;
                }

                this.qw.write(format(event));

                if (this.immediateFlush) {
                        this.qw.flush();
                }

                if ((fileName != null)
                                && ((CountingQuietWriter) qw).getCount() >= maxFileSize) {
                        this.rollOver();
                }
        }

}
and the content of the file 'MANIFEST.MF' is below:
Manifest-Version: 1.0
Built-By: Administrator
Tool: Bnd-0.0.357
Bundle-Name: Gzydt :: InfoShare :: Infoshare :: Logging
Created-By: Apache Maven Bundle Plugin
Bundle-Vendor: The Apache Software Foundation
Build-Jdk: 1.6.0_43
Bundle-Version: 0.0.1.SNAPSHOT
Bnd-LastModified: 1403420942423
Bundle-ManifestVersion: 2
Bundle-License: http://www.apache.org/licenses/LICENSE-2.0.txt
Bundle-Description: Subsystem - Bundle :: Infoshare - Logging
Bundle-SymbolicName: infoshare.logging
Bundle-DocURL: http://www.apache.org/
Import-Package: org.apache.log4j;version="1.2",org.osgi.framework;vers
 ion="1.5"
I have  already configured both 'org.ops4j.pax.logging.cfg' and 'startup.properties'
the file of  'org.ops4j.pax.logging.cfg' is:
# Root logger
log4j.rootLogger=INFO, file, 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

# customer appender
log4j.appender.file=org.ops4j.pax.logging.file.FileAppender
log4j.appender.file.layout=org.apache.log4j.PatternLayout
log4j.appender.file.layout.ConversionPattern=%d{ABSOLUTE} | %-5.5p | %-16.16t | %-32.32c{1} | %X{bundle.id} - %X{bundle.name} - %X{bundle.version} | %m%n
log4j.appender.file.file=${karaf.data}/log/file.log
log4j.appender.file.append=true
log4j.appender.file.maxFileSize=1MB
log4j.appender.file.maxBackupIndex=10
the file of 'startup.properties' is
org/ops4j/pax/logging/pax-logging-sample-fragment/1.7.3-SNAPSHOT/pax-logging-sample-fragment-1.7.3-SNAPSHOT.jar=5
I test my appender ,but it doesn't work ,the log file which is named 'file.log' has nothing be written

I test code is :
public class Activator implements BundleActivator {

        private static final Logger LOG = Logger.getLogger("log4j.appender.file");

        /*
         * (non-Javadoc)
         *
         * @see
         * org.osgi.framework.BundleActivator#start(org.osgi.framework.BundleContext
         * )
         */
        public void start(BundleContext context) throws Exception {

                LOG.debug("test!!!");
                LOG.info(context.getBundle().getSymbolicName() + "start!!");

        }
is there anything wrong ???

Reply | Threaded
Open this post in threaded view
|

Re: how to use the ops4j logging

Achim Nierbeck
Hi,

you'll need to add your custom appender to pax logging.
This either can be done as I have documented at [1].
Or another way is to register this custom appender as service.
Though I haven't done that solution yet.

Regards, Achim

[1] -
http://notizblog.nierbeck.de/2011/08/adding-custom-log-appender-to-pax-logging/


2014-06-22 9:41 GMT+02:00 a175335 <[hidden email]>:

> hi :
>
>   I make a customer demo below,
>
>
> package org.ops4j.pax.logging.file;
>
> import java.util.Date;
>
> import org.apache.log4j.RollingFileAppender;
> import org.apache.log4j.helpers.CountingQuietWriter;
> import org.apache.log4j.spi.LoggingEvent;
> import org.ops4j.pax.logging.bo.Log;
>
> public class FileAppender extends RollingFileAppender {
>
>         public FileAppender() {
>
>         }
>
>         private String format(LoggingEvent event) {
>                 Log log = (Log) event.getMessage();
>                 log.setThreadName(event.getThreadName());
>
> log.setLocationInfo(event.getLocationInformation().fullInfo);
>                 log.setLevel(event.getLevel().toString());
>                 log.setTime(new Date(event.timeStamp));
>                 log.setLoggerName(event.getLoggerName());
>
>                 return log.toString();
>         }
>
>         protected void subAppend(LoggingEvent event) {
>                 if (!(event.getMessage() instanceof Log)) {
>                         return;
>                 }
>
>                 this.qw.write(format(event));
>
>                 if (this.immediateFlush) {
>                         this.qw.flush();
>                 }
>
>                 if ((fileName != null)
>                                 && ((CountingQuietWriter) qw).getCount()
> >= maxFileSize) {
>                         this.rollOver();
>                 }
>         }
>
> }
> and the content of the file 'MANIFEST.MF' is below:
> Manifest-Version: 1.0
> Built-By: Administrator
> Tool: Bnd-0.0.357
> Bundle-Name: Gzydt :: InfoShare :: Infoshare :: Logging
> Created-By: Apache Maven Bundle Plugin
> Bundle-Vendor: The Apache Software Foundation
> Build-Jdk: 1.6.0_43
> Bundle-Version: 0.0.1.SNAPSHOT
> Bnd-LastModified: 1403420942423
> Bundle-ManifestVersion: 2
> Bundle-License: http://www.apache.org/licenses/LICENSE-2.0.txt
> Bundle-Description: Subsystem - Bundle :: Infoshare - Logging
> Bundle-SymbolicName: infoshare.logging
> Bundle-DocURL: http://www.apache.org/
> Import-Package: org.apache.log4j;version="1.2",org.osgi.framework;vers
>  ion="1.5"
> I have  already configured both 'org.ops4j.pax.logging.cfg' and
> 'startup.properties'
> the file of  'org.ops4j.pax.logging.cfg' is:
> # Root logger
> log4j.rootLogger=INFO, file, 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
>
> # customer appender
> log4j.appender.file=org.ops4j.pax.logging.file.FileAppender
> log4j.appender.file.layout=org.apache.log4j.PatternLayout
> log4j.appender.file.layout.ConversionPattern=%d{ABSOLUTE} | %-5.5p |
> %-16.16t | %-32.32c{1} | %X{bundle.id} - %X{bundle.name} -
> %X{bundle.version} | %m%n
> log4j.appender.file.file=${karaf.data}/log/file.log
> log4j.appender.file.append=true
> log4j.appender.file.maxFileSize=1MB
> log4j.appender.file.maxBackupIndex=10
> the file of 'startup.properties' is
>
> org/ops4j/pax/logging/pax-logging-sample-fragment/1.7.3-SNAPSHOT/pax-logging-sample-fragment-1.7.3-SNAPSHOT.jar=5
> I test my appender ,but it doesn't work ,the log file which is named
> 'file.log' has nothing be written
>
> I test code is :
> public class Activator implements BundleActivator {
>
>         private static final Logger LOG =
> Logger.getLogger("log4j.appender.file");
>
>         /*
>          * (non-Javadoc)
>          *
>          * @see
>          *
> org.osgi.framework.BundleActivator#start(org.osgi.framework.BundleContext
>          * )
>          */
>         public void start(BundleContext context) throws Exception {
>
>                 LOG.debug("test!!!");
>                 LOG.info(context.getBundle().getSymbolicName() +
> "start!!");
>
>         }
> is there anything wrong ???
>
>
>
>
>
> --
> View this message in context:
> http://servicemix.396122.n5.nabble.com/how-to-use-the-ops4j-logging-tp5720883p5721028.html
> Sent from the ServiceMix - Dev mailing list archive at Nabble.com.
>



--

Apache Member
Apache Karaf <http://karaf.apache.org/> Committer & PMC
OPS4J Pax Web <http://wiki.ops4j.org/display/paxweb/Pax+Web/> Committer &
Project Lead
blog <http://notizblog.nierbeck.de/>

Software Architect / Project Manager / Scrum Master
Reply | Threaded
Open this post in threaded view
|

Re: how to use the ops4j logging

a175335
hi

    thanks for your document,my custom appender can work now ,but how can I use it in my won bundles?

the code '  LOG.info(context.getBundle().getSymbolicName() + "start!!"); ' has not work. The log message is

not written  into the file which named file.log.Should I configue the file of 'log4j.porperties ' used my custom appender in my won bundles?
Reply | Threaded
Open this post in threaded view
|

Re: how to use the ops4j logging

Achim Nierbeck
If you define your own appender in the config it should work right away.
maybe your config isn't correct yet.

regards, Achim


2014-06-22 20:02 GMT+02:00 a175335 <[hidden email]>:

> hi
>
>     thanks for your document,my custom appender can work now ,but how can I
> use it in my won bundles?
>
> the code '  LOG.info(context.getBundle().getSymbolicName() + "start!!"); '
> has not work. The log message is
>
> not written  into the file which named file.log.Should I configue the file
> of 'log4j.porperties ' used my custom appender in my won bundles?
>
>
>
> --
> View this message in context:
> http://servicemix.396122.n5.nabble.com/how-to-use-the-ops4j-logging-tp5720883p5721032.html
> Sent from the ServiceMix - Dev mailing list archive at Nabble.com.
>



--

Apache Member
Apache Karaf <http://karaf.apache.org/> Committer & PMC
OPS4J Pax Web <http://wiki.ops4j.org/display/paxweb/Pax+Web/> Committer &
Project Lead
blog <http://notizblog.nierbeck.de/>

Software Architect / Project Manager / Scrum Master