[英]Get “name” for object, corresponding to package name and object name
Given the object: 给定对象:
package com.foo.bar
object Sample {
val LOG = org.slf4j.LoggerFactory.getLogger(???)
....
}
what statement/function/whatever I put into getLogger statement in order to get "com.foo.bar.Sample" ? 我为了获得“ com.foo.bar.Sample”而将什么语句/函数/无论我放入getLogger语句中?
Basically, it's just a matter of code style, for the moment I configured IntelliJ to generate LOG statements with strings, evaluated from template like "packagename.classname". 基本上,这只是代码风格的问题,目前我已配置IntelliJ来生成带有字符串的LOG语句,这些语句是从“ packagename.classname”之类的模板进行评估的。 But may be there's some better way? 但是也许有更好的方法吗?
Thanks. 谢谢。
在这种情况下,您可以使用getClass().getName()
。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.