PAX Logging custom Layout

294 views
Skip to first unread message

Lukasz Lech

unread,
Apr 25, 2018, 10:10:15 AM4/25/18
to op...@googlegroups.com

Hello,

 

I’m very confused with Pax Logging configuration. For example, on the wiki https://ops4j1.jira.com/wiki/spaces/ops4j/pages/7274541/Configuring+Pax+Logging the layout is configured this way:

 

log4j.appender.A1.layout=org.apache.log4j.PatternLayout

 

However, In org.ops4j.pax.logging.cfg in Karaf distribution I have:

 

log4j2.appender.console.layout.type = PatternLayout

 

In first syntax, I see how I could replace standart PatternLayout with my own, in that what is actually used in Karaf I don’t know where I should start…

 

I need (most likely) to customize PatternLayout because I’m using Dockerized karaf and Elasticsearch, which together have no support for multiline messages. So if Java logs something multi-line like StackTrace, my Patter need to convert the message to single-line.

 

Is there any entry point I can start doing my research? Honestly, pax logging is the part that is still a black magic to me. That what I see in config file differs from both log4j property-based documentation and that what can be found on wiki, every time I’m changing there something I do it through experimenting…

 

Best regards,

Lukasz Lech

 

Grzegorz Grzybek

unread,
Apr 25, 2018, 10:20:55 AM4/25/18
to op...@googlegroups.com
Hello

"log4j." prefixed properties in org.ops4j.pax.logging PID (etc/org.ops4j.pax.logging.cfg file) should be used for pax-logging-api + pax-logging-service bundles
"log4j2." prefixed properties in org.ops4j.pax.logging PID (etc/org.ops4j.pax.logging.cfg file) should be used for pax-logging-api + pax-logging-log4j2 bundles

So, the patterns to use depend on whether you want log4jv1 or log4jv2.

Log4j2 changed the way properties configurator works.

Log4j2 property syntax is described here: http://logging.apache.org/log4j/2.x/manual/configuration.html#Properties
Log4j1: https://logging.apache.org/log4j/1.2/manual.html

The most "visible" difference is that with log4j1, you specify both appenders and level in single property. With Log4j2, you have different properties for level and different for appender(s).

I hope this clears the confusion a bit.

regards
Grzegorz Grzybek

--
--
------------------
OPS4J - http://www.ops4j.org - op...@googlegroups.com

---
You received this message because you are subscribed to the Google Groups "OPS4J" group.
To unsubscribe from this group and stop receiving emails from it, send an email to ops4j+unsubscribe@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Lukasz Lech

unread,
Apr 25, 2018, 11:35:33 AM4/25/18
to op...@googlegroups.com

Thanks, now I’ve found the solution

 

I’ve searched for JsonLayout configuration in log4j and I’ve adapted the ‘rolling’ appender deifiition to

 

# Rolling file appender

log4j2.appender.rolling.type = RollingRandomAccessFile

log4j2.appender.rolling.name = RollingFile

log4j2.appender.rolling.fileName = ${karaf.data}/log/karaf.log

log4j2.appender.rolling.filePattern = ${karaf.data}/log/karaf.log.%i

log4j2.appender.rolling.append = true

log4j2.appender.rolling.layout.type = JsonLayout

log4j2.appender.rolling.layout.compact = true

log4j2.appender.rolling.layout.eventEol = true

log4j2.appender.rolling.policies.type = Policies

log4j2.appender.rolling.policies.size.type = SizeBasedTriggeringPolicy

log4j2.appender.rolling.policies.size.size = 16MB

 

It required to install 3 additional bundles to fulfill the dependencies:

 

mvn:com.fasterxml.jackson.core/jackson-core/2.9.5

mvn:com.fasterxml.jackson.core/jackson-annotations/2.9.0

mvn:com.fasterxml.jackson.core/jackson-databind/2.9.5

 

Now I have 1 line with json log per logging event. I hope it will help others who’d like to achieve the same.

 

Best regards,

Lukasz Lech

--

To unsubscribe from this group and stop receiving emails from it, send an email to ops4j+un...@googlegroups.com.


For more options, visit https://groups.google.com/d/optout.

 

--

--
------------------
OPS4J - http://www.ops4j.org - op...@googlegroups.com

---
You received this message because you are subscribed to the Google Groups "OPS4J" group.

To unsubscribe from this group and stop receiving emails from it, send an email to ops4j+un...@googlegroups.com.

Reply all
Reply to author
Forward
0 new messages