I am having problems getting logging to print out in some of my constructors. With others, logging is working just as I would expect.
I have attempted to eliminate every possible source of confusion by going with defaults, and by explicitly setting the log levels within the class itself. I've tried instantiating the logger as both a static and instance variable.
But, even setting the logging level to "Level.ALL" doesn't seem to be working in some of the classes.
For instance loggers, I have been setting the logging level within an instance-initializer / anonymous block. For the static instance, I am using the static block to set the logging level.
Any ideas why the log messages aren't printing out in the classes below?
Note: Code has been edited to show the fix, based on comment by @jmehrens
public abstract class ReadFileInformation extends SimpleFileVisitor<Path> {
static public ConsoleHandler globalConsoleHandler = new ConsoleHandler(); // fix, based on comment by @jmehrens
static private final Logger logger = Logger.getLogger(ReadFileInformation.class.getName());
static { // fix: See comment by @jmehrens
globalConsoleHandler.setLevel(Level.ALL);
logger.addHandler(globalConsoleHandler);
}
{
logger.setLevel(Level.ALL);
logger.log(Level.FINEST, String.format("This does NOT print.\n"));
System.out.println("In ReadFileInformation Static Block. This prints out!");
}
}
public class ReadMetadateFileInformation extends ReadFileInformation {
static private final Logger logger = Logger.getLogger(ReadMetadateFileInformation.class.getName());
static {
logger.setLevel(Level.ALL);
logger.log(Level.FINEST, String.format("This does NOT print.\n"));
System.out.println("In ReadMetadateFileInformation Static Block. This prints out!");
}
{
logger.log(Level.FINEST, String.format("This does NOT print.\n"));
System.out.println("In ReadMetadateFileInformation Anonymous Block. This prints out!");
}
public ReadMetadateFileInformation() {
super();
logger.log(Level.FINE, String.format("This does NOT print.\n"));
}
}
System.out.print
ing has nothing to do withLogger
. I am also guessing that this has nothing to do with subclassing either - basically (the code as posting) does notLog
I suggest that you make a very very easy class with just amain
as get that printing. – Scary Wombat