karaf OSGI 环境中 log 如何使用自己的 appender/ filter

Using your own appenders

If you plan to use your own appenders, you need to create an OSGi bundle and attach it as a fragment to the bundle with a symbolic name of 
org.ops4j.pax.logging.pax-logging-service. This way, the underlying logging system will be able to see and use your appenders.

So for example you write a log4j appender:
class MyAppender extends AppenderSkeleton {
...
}

Then you need to package the appender in a jar with a Manifest like this:

Manifest:
Bundle-SymbolicName: org.mydomain.myappender 
Fragment-Host: org.ops4j.pax.logging.pax-logging-service
...

注 :system 目录是类似于maven repository结构的文件夹

Copy the new appender fragment into the ${karaf.home}/system directory. Karaf uses a virtual maven repository to access resources in the system
directory, so the jar path should use the standard maven groupId/artifactId/version/ convention, where the groupId is a directory structure.

Edit ${karaf.home}/etc/startup.properties and add the new fragment bundle to the list before the pax-logging-service bundle.

Restart karaf with a clean run to reload the system bundles, and now you can use the appender in your log4j config file like shown in the config
examples above.

你可能感兴趣的:(log,filter,karaf,appender)