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 <[email protected]>:

> 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 via email to