Our Products:   CompleteFTP  edtFTPnet/Free  edtFTPnet/PRO  edtFTPj/Free  edtFTPj/PRO
0 votes
14.4k views
in Java FTP by
I have the following code implemented, it creates the file, but never writes anything to it. In addition, it does not log to the screen. Please help...

Logger.setLevel(Level.ALL);
Logger.addAppender(new FileAppender("C:\\ttt.txt"));
Logger.addAppender(new StandardOutputAppender());

11 Answers

0 votes
by (161k points)
Try Demo.java in the distribution zip - does that work?

I have the following code implemented, it creates the file, but never writes anything to it. In addition, it does not log to the screen. Please help...

Logger.setLevel(Level.ALL);
Logger.addAppender(new FileAppender("C:\\ttt.txt"));
Logger.addAppender(new StandardOutputAppender());
0 votes
by
If I run the logging without adding an Appender it does log to the screen in my code and in the Demo.java code. Only when I add an Appender, either FileAppender or StandardOutputAppender it does not log to the specified locations. (ie blank file and no ouput to the screen)
0 votes
by (161k points)
Are you using the latest version? 1.4.2?

The junit tests use FileAppender and work correctly.

If I run the logging without adding an Appender it does log to the screen in my code and in the Demo.java code. Only when I add an Appender, either FileAppender or StandardOutputAppender it does not log to the specified locations. (ie blank file and no ouput to the screen)
0 votes
by
That is correct, it does work in the junit tests. I can not figure out why my code does not work...
0 votes
by
Here is a snippet of my code...

try {

Logger.setLevel(Level.ALL);
Logger.addAppender(new FileAppender("C:\\ttt.txt"));
Logger.addAppender(new StandardOutputAppender());

FTPClient ftp = null;

ftp = new FTPClient(rechost);

ftp.login(recuid, recpwd);

ftp.setConnectMode(FTPConnectMode.PASV);
ftp.setType(FTPTransferType.ASCII);
0 votes
by (161k points)
Are any exceptions being thrown? Is it possible you don't have write access to create and write to the log file?

Here is a snippet of my code...

try {

Logger.setLevel(Level.ALL);
Logger.addAppender(new FileAppender("C:\\ttt.txt"));
Logger.addAppender(new StandardOutputAppender());
0 votes
by
No exceptions, no rights issues as I am an Administrator on my machine...
0 votes
by (161k points)
Try running the code thru a debugger (e.g. in Eclipse) and stepping into the logging code.

If this doesn't yield anything, try to isolate the code into a small Java class that demonstrates the problem & we'll take a look.

No exceptions, no rights issues as I am an Administrator on my machine...
0 votes
by
Here is a smaller piece of code...

public static void main(String[] args) {
String rechost="foor.bar";
String recuid="userid";
String recpwd="password";
try {
Logger.setLevel(Level.ALL);
Logger.addAppender(new FileAppender("C:\\ttt.txt"));
Logger.addAppender(new StandardOutputAppender());
System.setProperty("edtftp.log.log4j","true");
FTPClient ftp = null;

ftp = new FTPClient(rechost);
} catch (Exception e) {
System.out.println("Error "+e);
}
}

When I run this I get two warnings, again no output, but two warnings...


log4j:WARN No appenders could be found for logger (com.enterprisedt.net.ftp.FTPControlSocket).

log4j:WARN Please initialize the log4j system properly.
0 votes
by
Should I be able to log to a file and the screen without using log4j? If so, when I remove the line

System.setProperty("edtftp.log.log4j","true");

it still does not log to the screen or file. If I remove the line

Logger.addAppender(new FileAppender("C:\\ttt.txt"));

It does not log to the screen, only when I remove both addAppender lines does it log to the screen...

Categories

...