Add support to propagate ONOS log to Kafka with KafkaAppender in log4j2

- new OSGi Bundle to define extra imports for log4j2
- update OSGiWrapper to support fragment-host tag + bugfix
- add kafka-clients to onos-dependencies package
- add example of how to propagate log to Kafka via KafkaAppender
- bugfix to org.ops4j.pax.logging.cfg

Change-Id: I89992936101a48c6452082bf23c7133c20aa0b48
diff --git a/tools/package/etc/org.ops4j.pax.logging.cfg b/tools/package/etc/org.ops4j.pax.logging.cfg
index 036447d..c771aa9 100644
--- a/tools/package/etc/org.ops4j.pax.logging.cfg
+++ b/tools/package/etc/org.ops4j.pax.logging.cfg
@@ -36,13 +36,12 @@
 #log4j2.rootLogger.type = asyncRoot
 #log4j2.rootLogger.includeLocation = false
 log4j2.rootLogger.appenderRef.RollingFile.ref = RollingFile
-log4j2.rootLogger.appenderRef.AuditFile.ref = AuditFile
 log4j2.rootLogger.appenderRef.PaxOsgi.ref = PaxOsgi
 log4j2.rootLogger.appenderRef.Console.ref = Console
 log4j2.rootLogger.appenderRef.Console.filter.regex.type = RegexFilter
 log4j2.rootLogger.appenderRef.Console.filter.regex.regex = .*Audit.*
 log4j2.rootLogger.appenderRef.Console.filter.regex.onMatch = DENY
-log4j2.rootLogger.appenderRef.Console.filter.regex.onMisMatch = ACCEPT
+log4j2.rootLogger.appenderRef.Console.filter.regex.onMismatch = ACCEPT
 #log4j2.rootLogger.appenderRef.Console.filter.threshold.type = ThresholdFilter
 #log4j2.rootLogger.appenderRef.Console.filter.threshold.level = ${karaf.log.console:-OFF}
 
@@ -86,7 +85,7 @@
 log4j2.appender.rolling.filter.regex.type = RegexFilter
 log4j2.appender.rolling.filter.regex.regex = .*AuditLog.*
 log4j2.appender.rolling.filter.regex.onMatch = DENY
-log4j2.appender.rolling.filter.regex.onMisMatch = ACCEPT
+log4j2.appender.rolling.filter.regex.onMismatch = ACCEPT
 log4j2.appender.rolling.fileName = ${karaf.data}/log/karaf.log
 log4j2.appender.rolling.filePattern = ${karaf.data}/log/karaf.log.%i
 # uncomment to not force a disk flush
@@ -144,3 +143,22 @@
 #log4j2.logger.http-headers.level = DEBUG
 #log4j2.logger.maven.name = org.ops4j.pax.url.mvn
 #log4j2.logger.maven.level = TRACE
+
+# --- Example for a Kafka appender ---
+# Avoid recursive logging for Kafka
+# log4j2.logger.apacheKafka.name = org.apache.kafka
+# log4j2.logger.apacheKafka.level = INFO
+
+# Kafka appender definition
+# log4j2.appender.kafka.type = Kafka
+# log4j2.appender.kafka.name = Kafka
+# log4j2.appender.kafka.property.type = Property
+# log4j2.appender.kafka.property.name = bootstrap.servers
+# log4j2.appender.kafka.property.value = localhost:9092
+# log4j2.appender.kafka.topic = onos.log
+# Async send, no need to wait for Kafka ack for each record
+# log4j2.appender.kafka.syncSend = false
+# log4j2.kafka.pattern = {"@timestamp":"%d{yyyy-MM-dd'T'HH:mm:ss.SSS'Z'}","levelname":"%p","threadName":"%t","category":"%c{1}","bundle.id":"%X{bundle.id}","bundle.name":"%X{bundle.name}","bundle.version":"%X{bundle.version}","message":"%m"}%n
+# log4j2.appender.kafka.layout.type = PatternLayout
+# log4j2.appender.kafka.layout.pattern = ${log4j2.kafka.pattern}
+# log4j2.rootLogger.appenderRef.Kafka.ref = Kafka
\ No newline at end of file
diff --git a/tools/package/etc/startup.properties b/tools/package/etc/startup.properties
new file mode 100644
index 0000000..086936d
--- /dev/null
+++ b/tools/package/etc/startup.properties
@@ -0,0 +1,23 @@
+# Valid for Karaf 4.2.8. If updating Karaf version in ONOS, make sure to
+# copy-paste here the content of apache-karaf-*/etc/startup.properties in, and
+# update the Kafka and log4j2 additions at the end if needed
+
+# Standard startup.properties file
+# Bundles to be started on startup, with startlevel
+mvn\:org.apache.karaf.features/org.apache.karaf.features.extension/4.2.8 = 1
+mvn\:org.apache.karaf.services/org.apache.karaf.services.eventadmin/4.2.8 = 5
+mvn\:org.ops4j.pax.url/pax-url-aether/2.6.2 = 5
+mvn\:org.apache.felix/org.apache.felix.metatype/1.2.2 = 5
+mvn\:org.ops4j.pax.logging/pax-logging-api/1.11.4 = 8
+mvn\:org.fusesource.jansi/jansi/1.18 = 8
+mvn\:org.ops4j.pax.logging/pax-logging-log4j2/1.11.4 = 8
+mvn\:org.apache.felix/org.apache.felix.coordinator/1.0.2 = 9
+mvn\:org.apache.felix/org.apache.felix.configadmin/1.9.16 = 10
+mvn\:org.apache.felix/org.apache.felix.fileinstall/3.6.4 = 11
+mvn\:org.apache.karaf.features/org.apache.karaf.features.core/4.2.8 = 15
+
+# Added part to enable Kafka log4j2 appender
+# N.B.: kafka-clients should have startlevel lower than onos-tools-package-log4j2-extra
+mvn\:org.apache.servicemix.bundles/org.apache.servicemix.bundles.kafka-clients/1.1.1_1 = 6
+# N.B.: onos-tools-package-log4j2-extra should have lower startlevel than pax-logging-*
+mvn\:org.onosproject/onos-log4j2-extra/$ONOS_VERSION = 7