[logback-user] PatternLayout feature request

Ceki Gulcu listid at qos.ch
Thu Jul 12 21:02:47 CEST 2007

Hi Arthur,

Logback already offers a similar feature called automatic abbreviation
for logger names and for class names.

For example, the pattern "%logger{10}" will attempt to abbreviate the
logger name to 10 characters, thus the logger name
"mainPackage.sub.sample.Bar" will be printed as "m.s.s.Bar". The table
below from the Layout chapter [1] of the log4j manual lists other

Pattern  	    Logger name  	              Result
%logger       mainPackage.sub.sample.Bar 	mainPackage.sub.sample.Bar
%logger{10}   mainPackage.sub.sample.Bar 	m.s.s.Bar
%logger{15} 	mainPackage.sub.sample.Bar 	m.s.sample.Bar
%logger{16} 	mainPackage.sub.sample.Bar 	m.sub.sample.Bar
%logger{26} 	mainPackage.sub.sample.Bar 	mainPackage.sub.sample.Bar

Alternatively, logback makes it very easy (even easier than in log4j)
to define your own conversion patterns. See the section called
"Creating a custom conversion specifier" in the Layout chapter of the
logback manual.

I hope this helps,

[1] http://logback.qos.ch/manual/layouts.html

Arthur Blake wrote:
> I'm using Logback on a new project.  I like it a lot so far.  Seems like 
> a leaner, tighter log4j.  Pretty easy to learn quickly because it is so 
> similar to log4j in a lot of ways.
> I'd like to see a feature in the PatternLayout where I can show just the 
> class name of the logger without its package prefix.
> For example, if I have a logger named 
> com.mycompany.myapplication.myarea.Stuff
> I'd like a version of the %logger conversion word that just outputs "Stuff"
> (not "com.mycompany.myapplication.myarea.Stuff" or even "c.m.m.m.Stuff")
> Most of my classes are unique across package names, and I'd like my log 
> output to be more concise in this way.
> I'm not worried about being confused by name collisions because my 
> application is small enough that it's obvious what logger is involved in 
> my log output.
> I've gotten around this so far by naming some of my logs with just the 
> class name without it's package, but I'd rather have a PatternLayout 
> conversion word or specifier to handle this.
> Forgive me if this feature is already in the PatternLayout, but I 
> couldn't find it after looking pretty hard.
> Arthur

Ceki Gülcü
Logback: The reliable, generic, fast and flexible logging framework for Java.

More information about the Logback-user mailing list