简体   繁体   English

Java 日志记录和 Unix Nohup 问题

[英]Java Logging & Unix Nohup problem

I have created a small program which logs text data to a file on some action.我创建了一个小程序,它在某些操作上将文本数据记录到文件中。 I am accessing the remote system where the program is deployed by Putty.我正在访问由 Putty 部署程序的远程系统。 I have run the program using nohup so that it keeps running even if i shut down my shell.我已经使用 nohup 运行了该程序,因此即使我关闭了 shell,它也会继续运行。 Till the time i am logged into the shell it continues to log the data.在我登录 shell 之前,它会继续记录数据。 However, as soon as i exit my shell it stops writing to the log file.但是,一旦我退出 shell,它就会停止写入日志文件。 My program still continues to run just that it doesn't write to the log file.我的程序仍然继续运行,只是它没有写入日志文件。 I am using Java 1.6 + slf4j+log4j for logging.我正在使用 Java 1.6 + slf4j+log4j 进行日志记录。 The OS is Ubuntu.操作系统是 Ubuntu。

Would appreciate some help.将不胜感激一些帮助。

EDIT: my log4j.properties编辑:我的 log4j.properties

log4j.rootLogger=DEBUG

log4j.appender.AdminFileAppender=org.apache.log4j.DailyRollingFileAppender
log4j.appender.AdminFileAppender.File=pdmLogs.log
log4j.appender.AdminFileAppender.layout=org.apache.log4j.PatternLayout
log4j.appender.AdminFileAppender.layout.ConversionPattern=%d{dd MMM yyyy HH:mm:ss,SSS} -- %p %t %c - %m%n

log4j.appender.ReportFileAppender=org.apache.log4j.ConsoleAppender
log4j.appender.ReportFileAppender.layout=org.apache.log4j.PatternLayout
log4j.appender.ReportFileAppender.layout.ConversionPattern=%d{dd MMM yyyy HH:mm:ss,SSS} -- %p %t %c - %m%n

log4j.logger.com.xxx.xxx.yyy=ReportFileAppender,AdminFileAppender
log4j.logger.com.xxx.xxx.zzz=ReportFileAppender,AdminFileAppender

The command which I am running is:我正在运行的命令是:

nohup java -cp jarfile.jar com.xxx.xxx.yyy.Main &

Try changing your configuration to:尝试将您的配置更改为:

log4j.rootLogger=DEBUG, AdminFileAppender
...

How do you run the program?你如何运行程序? After running the program, do you see it among the list of process running by doing ps -ef | grep <process-id>运行程序后,你是否在执行ps -ef | grep <process-id>运行的进程列表中看到它? ps -ef | grep <process-id> Just to make sure, your program doesn't block at any time waiting for input? ps -ef | grep <process-id>只是为了确保您的程序在任何时候都不会阻塞等待输入? Also, check on the exit value of your process.另外,检查进程的退出值。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM