Often, it can be very helpful to look at edtFTPj/PRO's extensive logging output if any problems are experienced communicating with FTP servers. edtFTPj/PRO has a powerful logging API modelled on the popular log4j library – in fact full integration with log4j is supported.
All commands sent to the FTP server and subsequent replies are logged, and can be made available on the console or directed to a log file. Much other useful information is also logged.
Statements within edtFTPj/PRO are logged at different levels, ranging from least verbose (FATAL), to most verbose (DEBUG). Intermediate levels are ERROR, WARN, and INFO. An overall level can be set for the library, and all statements up to and including that level will be outputted.
For example, if the overall level is set to INFO then FATAL, ERROR, WARN and INFO log statements will be outputted, but DEBUG statements will not be.
There are also two additional levels - OFF which means no logging will occur, and ALL which means all log statements will be outputted, no matter what level they are. The ALL level is actually an additional level which is used for extremely verbose output - so when the level is set to ALL more log statements may be outputted than at DEBUG.
Logging levels are encapsulated in the Level class. For example, the WARN level is represented by Level.WARN.
By default, the log level is switched to OFF, so that no logging will appear.
The log level can be changed in two ways. Firstly, it can be changed explicitly by calling the setLevel method on the Logger class. For example:
will set the global logging level to DEBUG.
A System property, edtftp.log.level, can also be used to set the logging level. For example, using the -D option to set an application's System property, you could use:
java -Dedtftp.log.level=INFO com.mypackage.myclass
Using edtFTPj/PRO's logging in your own application is very similar to using log4j. A logger is created, and its methods used to write logging information. Rather than use the Level class, the Logger class has convenience methods for logging at each level. An example is shown below:
Logger log = Logger.getLogger(MyClass.class); log.info("Connecting to server " + host);
As noted, all logging by default goes to standard output. A FileAppender must be added if logging is to go to a file (and this will disable logging to standard out). An example is shown below:
Now all logging output will go to the FileAppender's file, and no logging will go to standard output. Multiple FileAppenders can be added. If the StandardOutputAppender is added to the Logger as well, logging will be directed to the file and to standard output.
Log files can get too large, especially if all logging levels are being logged. The RollingFileAppender can be used to limit the size of files, and also the number of files used.
Full integration with log4j is possible. A System property, edtftp.log.log4j, is used to indicate that log4j integration should be attempted. It must be set to "true". Also, the log4j jar file must be available in the CLASSPATH. Once this is done all logging calls are directed via log4j, using reflection, and the standard log4j settings are used.
Because of obfuscation, package names are not used in the logger names for edtFTPj/PRO. Logger names are hard coded to the class name only. Sometimes it is convenient to have a package prefix with log4j integration, as all the edtFTPj/PRO logging settings can then be controlled together. A System property, edtftp.log.prefix, can be used to set a prefix for all logger names used in edtFTPj/PRO. For example, "edtftp.log.prefix=com.enterprisedt." could be used to set a prefix of 'com.enterprisedt.' for all edtFTPj/PRO loggers.
See How to setup extended logging for details on enabling additional levels for logging for hard-to-solve problems.