Skip to content

Commit

Permalink
Switch to log4j2 (#1686)
Browse files Browse the repository at this point in the history
Co-authored-by: Olaf Seng <[email protected]>
Co-authored-by: Stefan Feilmeier <[email protected]>
  • Loading branch information
3 people authored Dec 21, 2021
1 parent 69da03e commit edb1589
Show file tree
Hide file tree
Showing 5 changed files with 35 additions and 25 deletions.
6 changes: 3 additions & 3 deletions cnf/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -245,12 +245,12 @@
<dependency>
<groupId>org.ops4j.pax.logging</groupId>
<artifactId>pax-logging-api</artifactId>
<version>2.0.11</version>
<version>2.0.13</version>
</dependency>
<dependency>
<groupId>org.ops4j.pax.logging</groupId>
<artifactId>pax-logging-log4j1</artifactId>
<version>2.0.11</version>
<artifactId>pax-logging-log4j2</artifactId>
<version>2.0.13</version>
</dependency>
<dependency>
<groupId>org.osgi</groupId>
Expand Down
8 changes: 4 additions & 4 deletions io.openems.backend.application/BackendApp.bndrun
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,11 @@

-runbundles+: \
org.apache.felix.scr;startlevel=10,\
org.ops4j.pax.logging.pax-logging-log4j1;startlevel=12
org.ops4j.pax.logging.pax-logging-log4j2;startlevel=12

-runrequires: \
bnd.identity;id='org.ops4j.pax.logging.pax-logging-api',\
bnd.identity;id='org.ops4j.pax.logging.pax-logging-log4j1',\
bnd.identity;id='org.ops4j.pax.logging.pax-logging-log4j2',\
bnd.identity;id='org.osgi.service.jdbc',\
bnd.identity;id='org.apache.felix.http.jetty',\
bnd.identity;id='org.apache.felix.webconsole',\
Expand Down Expand Up @@ -77,8 +77,8 @@
org.apache.felix.webconsole;version='[4.7.2,4.7.3)',\
org.apache.felix.webconsole.plugins.ds;version='[2.1.0,2.1.1)',\
org.jsr-305;version='[3.0.2,3.0.3)',\
org.ops4j.pax.logging.pax-logging-api;version='[2.0.11,2.0.12)',\
org.ops4j.pax.logging.pax-logging-log4j1;version='[2.0.11,2.0.12)',\
org.ops4j.pax.logging.pax-logging-api;version='[2.0.13,2.0.14)',\
org.ops4j.pax.logging.pax-logging-log4j2;version='[2.0.13,2.0.14)',\
org.osgi.service.jdbc;version='[1.0.1,1.0.2)',\
org.osgi.util.function;version='[1.2.0,1.2.1)',\
org.osgi.util.promise;version='[1.2.0,1.2.1)',\
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,14 +37,19 @@ void activate() {
try {
config = cm.getConfiguration("org.ops4j.pax.logging", null);
Dictionary<String, Object> properties = config.getProperties();
if (properties != null && properties.isEmpty()) {
if (properties == null || properties.isEmpty() || properties.get("log4j2.rootLogger.level") == null) {
Hashtable<String, Object> log4j = new Hashtable<>();
log4j.put("log4j.rootLogger", "INFO, CONSOLE, osgi:*");
log4j.put("log4j.appender.CONSOLE", "org.apache.log4j.ConsoleAppender");
log4j.put("log4j.appender.CONSOLE.layout", "org.apache.log4j.PatternLayout");
log4j.put("log4j.appender.CONSOLE.layout.ConversionPattern",
"%d{ISO8601} [%-8.8t] %-5p [%-30.30c] %m%n");
log4j.put("log4j.logger.org.eclipse.osgi", "WARN");
log4j.put("log4j2.appender.console.type", "Console");
log4j.put("log4j2.appender.console.name", "console");
log4j.put("log4j2.appender.console.layout.type", "PatternLayout");
log4j.put("log4j2.appender.console.layout.pattern", "%d{ISO8601} [%-8.8t] %-5p [%-30.30c] %m%n");

log4j.put("log4j2.appender.paxosgi.type", "PaxOsgi");
log4j.put("log4j2.appender.paxosgi.name", "paxosgi");

log4j.put("log4j2.rootLogger.level", "INFO");
log4j.put("log4j2.rootLogger.appenderRef.console.ref", "console");
log4j.put("log4j2.rootLogger.appenderRef.paxosgi.ref", "paxosgi");
config.update(log4j);
}
} catch (IOException | SecurityException e) {
Expand Down
8 changes: 4 additions & 4 deletions io.openems.edge.application/EdgeApp.bndrun
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,11 @@
-runbundles+: \
org.apache.felix.scr;startlevel=10,\
org.eclipse.equinox.event;startlevel=11,\
org.ops4j.pax.logging.pax-logging-log4j1;startlevel=12
org.ops4j.pax.logging.pax-logging-log4j2;startlevel=12

-runrequires: \
bnd.identity;id='org.ops4j.pax.logging.pax-logging-api',\
bnd.identity;id='org.ops4j.pax.logging.pax-logging-log4j1',\
bnd.identity;id='org.ops4j.pax.logging.pax-logging-log4j2',\
bnd.identity;id='org.apache.felix.http.jetty',\
bnd.identity;id='org.apache.felix.webconsole',\
bnd.identity;id='org.apache.felix.webconsole.plugins.ds',\
Expand Down Expand Up @@ -323,8 +323,8 @@
org.jsr-305;version='[3.0.2,3.0.3)',\
org.openmuc.jmbus;version='[3.3.0,3.3.1)',\
org.openmuc.jrxtx;version='[1.0.1,1.0.2)',\
org.ops4j.pax.logging.pax-logging-api;version='[2.0.11,2.0.12)',\
org.ops4j.pax.logging.pax-logging-log4j1;version='[2.0.11,2.0.12)',\
org.ops4j.pax.logging.pax-logging-api;version='[2.0.13,2.0.14)',\
org.ops4j.pax.logging.pax-logging-log4j2;version='[2.0.13,2.0.14)',\
org.osgi.util.function;version='[1.2.0,1.2.1)',\
org.osgi.util.promise;version='[1.2.0,1.2.1)',\
rrd4j;version='[3.8.0,3.8.1)'
Original file line number Diff line number Diff line change
Expand Up @@ -99,16 +99,21 @@ private boolean createDefaultConfigurations(List<Config> existingConfigs) {
* Create Default Logging configuration
*/
if (existingConfigs.stream().noneMatch(c -> //
"org.ops4j.pax.logging".equals(c.pid))) {
"org.ops4j.pax.logging".equals(c.pid) && c.properties.get("log4j2.rootLogger.level") != null)) {
// Adding Configuration manually, because this is not a OpenEMS Configuration
try {
Hashtable<String, Object> log4j = new Hashtable<>();
log4j.put("log4j.rootLogger", "INFO, CONSOLE, osgi:*");
log4j.put("log4j.appender.CONSOLE", "org.apache.log4j.ConsoleAppender");
log4j.put("log4j.appender.CONSOLE.layout", "org.apache.log4j.PatternLayout");
log4j.put("log4j.appender.CONSOLE.layout.ConversionPattern",
"%d{ISO8601} [%-8.8t] %-5p [%-30.30c] %m%n");
log4j.put("log4j.logger.org.eclipse.osgi", "WARN");
log4j.put("log4j2.appender.console.type", "Console");
log4j.put("log4j2.appender.console.name", "console");
log4j.put("log4j2.appender.console.layout.type", "PatternLayout");
log4j.put("log4j2.appender.console.layout.pattern", "%d{ISO8601} [%-8.8t] %-5p [%-30.30c] %m%n");

log4j.put("log4j2.appender.paxosgi.type", "PaxOsgi");
log4j.put("log4j2.appender.paxosgi.name", "paxosgi");

log4j.put("log4j2.rootLogger.level", "INFO");
log4j.put("log4j2.rootLogger.appenderRef.console.ref", "console");
log4j.put("log4j2.rootLogger.appenderRef.paxosgi.ref", "paxosgi");
Configuration config = this.parent.cm.getConfiguration("org.ops4j.pax.logging", null);
config.update(log4j);
} catch (IOException e) {
Expand Down

0 comments on commit edb1589

Please sign in to comment.