如何配置Logback以打印出类名 [英] How do I configure Logback to print out the class name

查看:1718
本文介绍了如何配置Logback以打印出类名的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用Play 2.1.我正在使用默认的记录器play.api.Logger.我对它的工作方式感到困惑.

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

在我的scala代码中,方法"getPayment()"中的"com.myapp.tickets"类中的一行是这样的

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

Logger.info("getTickets")

生成这样的日志消息.

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

我的application-logger.xml模式是

My application-logger.xml pattern is

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

我遇到的问题是%logger告诉我应用程序",%class告诉我"play.api.LoggerLike $ class和%method告诉我"info".我都知道.我当然想避免在消息本身中添加更多内容(如类名或方法).

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).

如果我打印出调用堆栈(%caller),则级别2符合我的要求,但这似乎不是生成日志的可行方法.

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?

推荐答案

登录模式:

%d{HH:mm:ss.SSS} [%thread] %-5level %class{36}.%M %L - %msg%n

结果:

14:53:47.816 [http-bio-8080-exec-3] DEBUG  c.f.s.w.s.i.example.ExServiceImpl.getStatus 993 - blocked-->0

  • [http-bio-8080-exec-3]是线程名称

    • [http-bio-8080-exec-3] is the thread name

      c.f.s.w.s.i.example是程序包名称

      ExServiceImpl是类名

      getStatus是方法名称

      993是行号

      这篇关于如何配置Logback以打印出类名的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆