由买买提看人间百态

boards

本页内容为未名空间相应帖子的节选和存档,一周内的贴子最多显示50字,超过一周显示500字 访问原贴
Programming版 - when I run junit test, how can I log the java log to a file?
相关主题
有人用过slf4j simple logger么,太他妈的难用了hibernate问题
关于 Java 的 Log 轮子如何实现将网页内容自动存取?
java logger 用哪一个好?Python vs J2EE
Perl/MySQL下fetchrow出错《OSGi 实战》英文文字版[PDF]
eclipse中总出现这样的错误提示怎么办?怎样准确测量函数执行的时间?
log4j 谁熟悉?弱问,上哪儿去找服务器?
光学Java Standard 本身是不是永远不够?Java EE 6 Pocket Guide
[合集] how to call a korn shell script in JAVA program?现在主流web server是什么?
相关话题的讨论汇总
话题: log话题: logger话题: file话题: junit
进入Programming版参与讨论
1 (共1页)
l**********n
发帖数: 8443
1
when I run junit test, how can I log the java log to a file? the log is only
logged to a file when running inside glassfish
c*****a
发帖数: 808
2
slf4j行不行
g*****g
发帖数: 34805
3
You can always use log4j and configure appender to both console and file.

only

【在 l**********n 的大作中提到】
: when I run junit test, how can I log the java log to a file? the log is only
: logged to a file when running inside glassfish

l**********n
发帖数: 8443
4
where should I put the log4j configuration file? in the resources folder of
the java source or test resources folder?

【在 g*****g 的大作中提到】
: You can always use log4j and configure appender to both console and file.
:
: only

g*****g
发帖数: 34805
5
It needs to be in classpath, that's all.

of

【在 l**********n 的大作中提到】
: where should I put the log4j configuration file? in the resources folder of
: the java source or test resources folder?

l**********n
发帖数: 8443
6
java.util.logging.Logger' is already defined in a single-type import
I found I couldn't switch to log4j.
l**********n
发帖数: 8443
7
in the code, I set up like this:
private static void setupLogger(){
m_log.setLevel(Level.ALL);
try {
FileHandler fhandler = new FileHandler("E:\logs\service.log");
SimpleFormatter sformatter = new SimpleFormatter();
fhandler.setFormatter(sformatter);
m_log.addHandler(fhandler);
} catch (IOException ex) {
m_log.log(Level.SEVERE, ex.getMessage(), ex);
} catch (SecurityException ex) {
m_log.log(Level.SEVERE, ex.getMessage(), ex);
}
}
static {
setupLogger();
}
// but then how I know it is production or unit testing? how to enable
logging globally?
l**********n
发帖数: 8443
8
I added the logging.properties to classpath, it is not working.
handlers=java.util.logging.FileHandler, java.util.logging.ConsoleHandler
java.util.logging.ConsoleHandler.level=INFO
java.util.logging.ConsoleHandler.formatter=java.util.logging.SimpleFormatter
java.util.logging.FileHandler.level=INFO
java.util.logging.FileHandler.pattern=logs/jetty.log
# Write 10MB before rotating this file
java.util.logging.FileHandler.limit=10000000
# Number of rotating files to be used
java.util.logging.FileHandler.count=4
java.util.logging.FileHandler.formatter=java.util.logging.SimpleFormatter
.level=INFO
z****e
发帖数: 54598
9
前面说了log4j
我建议上aspectj
如果你会用的话,就可以很容易滴将log代码和真正逻辑代码分离
l**********n
发帖数: 8443
10
我们是个小公司,没有什么framework,已经用了java.util.logging.Logger, 还可以
用log4j吗? 怎么set up aspectj? 怎么分离log和真正的代码?log on method entry
point? what about to log some business logic inside the method?
l**********n
发帖数: 8443
11
I don't understand
Logger.getLogger(getClass().getName())
it seems creating so many logger is unnecessary. why not keep only one
Logger?
coz then it only has one place to add the Handler:
m_log.addHandler(fhandler);
otherwise it has to go to so many different logger and for each one, add the
FileHandler.
I am confused of Java.
l**********n
发帖数: 8443
12
there should be a global logger:
static public void setup() throws IOException {
// Get the global logger to configure it
Logger logger = Logger.getLogger(Logger.GLOBAL_LOGGER_NAME);
logger.setLevel(Level.INFO);
fileTxt = new FileHandler("Logging.txt");
fileHTML = new FileHandler("Logging.html");
// Create txt Formatter
formatterTxt = new SimpleFormatter();
fileTxt.setFormatter(formatterTxt);
logger.addHandler(fileTxt);
// Create HTML Formatter
formatterHTML = new MyHtmlFormatter();
fileHTML.setFormatter(formatterHTML);
logger.addHandler(fileHTML);
}
1 (共1页)
进入Programming版参与讨论
相关主题
现在主流web server是什么?eclipse中总出现这样的错误提示怎么办?
javascript是要统一江湖的log4j 谁熟悉?
淘宝技术这十年光学Java Standard 本身是不是永远不够?
这里人多,请问Java如何读取需要登录的网页的内容 (转载)[合集] how to call a korn shell script in JAVA program?
有人用过slf4j simple logger么,太他妈的难用了hibernate问题
关于 Java 的 Log 轮子如何实现将网页内容自动存取?
java logger 用哪一个好?Python vs J2EE
Perl/MySQL下fetchrow出错《OSGi 实战》英文文字版[PDF]
相关话题的讨论汇总
话题: log话题: logger话题: file话题: junit