OSGi Wie konfiguriert man Pax Logging?

musiKk

Top Contributor
Hallo,

ich würde gerne log4j in meinen Bundles nutzen und so wie ich das mitbekommen habe, ist Pax Logging dafür der Weg der Wahl. Nun habe ich nach Stunden immer noch nicht herausgefunden, wie man dort die Ausgaben konfiguriert. Das Format ist im Moment unbrauchbar:
Code:
[Thread-2] DEBUG org.apache.felix.ipojo - ServiceEvent REGISTERED
Ich hätte ja gerne allerwenigstens Timestamps sowie die Möglichkeit, vernünftig die Log Levels einzustellen - so wie man es eben von einem Logging-Framework gewohnt ist.

Entsprechend der Installationsanleitung habe ich die benötigten Header ins Manifest geschrieben.

Wie konfiguriert man Pax Logging? Die Dokumentation bringt mir nichts, das funktioniert irgendwie nicht. Ich habe es jedenfalls testweise erstmal so probiert ([c]@Validate[/c] kommt von iPojo):
Java:
@Validate
protected void setupLogging() {
	try {
		Configuration conf = configAdmin.getConfiguration("org.ops4j.pax.logging", null);
		
		@SuppressWarnings("unchecked")
		Dictionary<String, String> props = conf.getProperties();
		System.err.println("current props: " + props);
		
		if(props == null) {
			props = new Hashtable<String, String>();
		}
		
		props.put("log4j.rootLogger", "INFO, A1");
		props.put("log4j.appender.A1", "org.apache.log4j.ConsoleAppender");
		props.put("log4j.appender.A1.layout", "org.apache.log4j.PatternLayout");
		props.put("log4j.appender.A1.layout.ConversionPattern", "%d [%t] %-5p %c - %m%n");
		
		conf.update(props);
	} catch (IOException e) {
		e.printStackTrace();
	}
}
Das wird ignoriert und ich vermute, dass es folgende Meldungen verursacht:
Code:
current props: {log4j.appender.a1.layout=org.apache.log4j.PatternLayout, service.pid=org.ops4j.pax.logging, log4j.rootlogger=INFO, A1, log4j.appender.a1=org.apache.log4j.ConsoleAppender, log4j.appender.a1.layout.conversionpattern=%d [%t] %-5p %c - %m%n}
[CM Configuration Updater (Update: pid=org.ops4j.pax.logging)] ERROR org.apache.felix.configadmin - Cannot use configuration org.ops4j.pax.logging for [org.osgi.service.log.LogService, org.knopflerfish.service.log.LogService, org.ops4j.pax.logging.PaxLoggingService, org.osgi.service.cm.ManagedService, id=32, bundle=46]: Configuration bound to bundle file:/pfad/zu/meinem/bundle.jar

Kleinschreibung der Keys (Properties in OSGi sind ja case-insensitive) bringt keinen Unterschied.

Hat irgendjemand eine Idee, wie man das richtig macht?
 
G

Gelöschtes Mitglied 5909

Gast
Ich habe pax logging noch nicht verwendet, aber es sieht so aus, als würde pax die config an das eigene bundle binden, bevor dein aufruf erfolgt.

Configuration (OSGi Service Platform Release 4 Version 4.2)

Configuration objects can be bound to a specified bundle location. In this case, if a matching Managed Service or Managed Service Factory is registered by a bundle with a different location, then the Configuration Admin service must not do the normal callback, and it should log an error. In the case where a Configuration object is not bound, its location field is null, the Configuration Admin service will bind it to the location of the bundle that registers the first Managed Service or Managed Service Factory that has a corresponding PID property. When a Configuration object is bound to a bundle location in this manner, the Configuration Admin service must detect if the bundle corresponding to the location is uninstalled. If this occurs, the Configuration object is unbound, that is its location field is set back to null.

Ich würde mir mal alle Configurations mit listConfiguration() holen und mal schaun ob die location gesetzt ist.
 

musiKk

Top Contributor
Ich würde mir mal alle Configurations mit listConfiguration() holen und mal schaun ob die location gesetzt ist.

Die Location ist auf mein Bundle gesetzt, in dem ich die Konfiguration vorgenommen habe. Ich weiß jedoch jetzt nicht, was dort eigentlich hin sollte. So tief stecke ich in der Materie wohl doch noch nicht drin...

Ok, zumindest ursprünglich. Ich habe die Konfiguration im Felix noch einmal gelöscht und über den [c]ConfigurationAdmin[/c] neu angelegt. Nun funktioniert es. Beim ersten mal habe ich die [c]Configuration[/c] noch über [c]configAdmin.getConfiguration("org.ops4j.pax.logging")[/c] angelegt. Laut einem Eintrag in der ops4j-Mailingliste muss bei der Location aber zwingend null angegeben werden.

Wie soll man denn auf sowas kommen... :/

Na gut, jetzt funktioniert das ganze zwar, muss aber ganz schön sperrig im Quellcode konfiguriert werden. Aber besser als nichts.

Danke raiL, das war zwar nur eine kleine Anmerkung, hat mich aber in die (hoffentlich) richtige Richtung gebracht.
 
Ähnliche Java Themen

Ähnliche Java Themen

Neue Themen


Oben