为特定包设置 java Logger
有人可以向我解释一下如何为具体包中的各种类设置 java Logger 吗?
例如: 如果我得到这个并设置它,
Logger logger = Logger.getLogger("com.google.api.client.*");
logger.setLevel(Level.CONFIG);
logger.addHandler(new Handler() {
@Override
public void close() throws SecurityException {
}
@Override
public void flush() {
}
@Override
public void publish(LogRecord record) {
// default ConsoleHandler will take care of >= INFO
if (record.getLevel().intValue() < Level.INFO.intValue()) {
System.out.println(record.getMessage());
}
}
});
存在类似
Logger.getLogger(HttpTransport.class.getName()).isLoggable(Level.CONFIG);
则在 HttpTransport< 的库中 的条件/code> 是
com.google.api.client.*
的一部分
,但问题是,这
Logger.getLogger(HttpTransport.class.getName()).isLoggable(Level.CONFIG);
是 false
...就像如果获得了不同的记录器
还应该如何我为同一个包中的所有类设置它? HttpTransport 等具体类的记录器是否有条件。
could anybody explain to me, how to set up java Logger for various classes from a concrete package ?
for example:
if I get this one and set it up
Logger logger = Logger.getLogger("com.google.api.client.*");
logger.setLevel(Level.CONFIG);
logger.addHandler(new Handler() {
@Override
public void close() throws SecurityException {
}
@Override
public void flush() {
}
@Override
public void publish(LogRecord record) {
// default ConsoleHandler will take care of >= INFO
if (record.getLevel().intValue() < Level.INFO.intValue()) {
System.out.println(record.getMessage());
}
}
});
there are conditions like this
Logger.getLogger(HttpTransport.class.getName()).isLoggable(Level.CONFIG);
in the library where HttpTransport
is part of com.google.api.client.*
But the problem is, that
Logger.getLogger(HttpTransport.class.getName()).isLoggable(Level.CONFIG);
is false
... like if a different logger was obtained
How else should I set it for all classes from the same package? if there are conditions for loggers for concrete classes like HttpTransport.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您不希望在包字符串中包含 .*。
更改
为
You do not want the .* in your package string.
Change
to