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?
You can simply put a my-logback. xml in the root of one of your classpath entries and specify -Dlogback. configurationFile=my-logback. xml .
Logback Architecture A Logger is a context for log messages. This is the class that applications interact with to create log messages. Appenders place log messages in their final destinations. A Logger can have more than one Appender.
In a Logback. xml file, all the configuration options are enclosed within the <configuration> root element. In the root element, you can set the debug=true attribute to inspect Logback's internal status. You can also configure auto scanning of the configuration file by setting the scan=true attribute.
Logback natively implements the SLF4J API.
%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
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With