Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
463 views
in Technique[技术] by (71.8m points)

playframework 2.0 - How do I configure Logback to print out the class name

I'm using Play 2.1. I'm using the default logger play.api.Logger. I'm confused about how it works.

In my scala code, a line in class "com.myapp.tickets" in the method "getPayment()" like this

Logger.info("getTickets")

generates a log message like this.

14:58:58.005 INFO  application play.api.LoggerLike$class info  getTickets

My application-logger.xml pattern is

%d{HH:mm:ss.SSS} %-5level %logger %class %method  %msg%n

The issue I have is that %logger tells me "application", %class tells me "play.api.LoggerLike$class and %method tells me "info". I know all of that. I of course want to avoid adding more cruft into the message itself (like the class name or method).

If I print out the call stack (%caller) then level 2 has what I want, but that does not seem a viable way to generate a log.

How do I configure it to output the application specific class and method, not the class and method of the logger itself?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

%class{0} will only output the class name, so instead of:

com.something.MyClass

You'll get:

MyClass

This is how my pattern for logback normally looks:

%d{HH:mm:ss} [%thread] %-5p %class{0} - %m%n

You can also add the method and the line if you are interested by doing:

%d{HH:mm:ss} [%thread] %-5p %class{0}.%method:%L - %m%n

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...