Glen Iris wrote:1 - should each class create its own instance of the file handler or should one instance of the file handler be created and passed to each class?
Since there will be only one log file (I hope so), it makes more sense to have a universal file handler (maybe a single instance throughout the application).
Glen Iris wrote:2 - if no file location is specified for the log-file.txt in the properties file, should i just create one at the root directory or simply print all my logs to the console?
Creating a file at root level is risky. What if the application is run by a non-root user, or what if application is run on Windows OS? It would be safe to create log file in same directory(as application), or create log dir etc.
However, please note that logging is not a 'must' requirement for OCMJD, and you won't get any extra points by implementing logging. However, you may loose points if logging causes any issue in application.
By the way, I did not implemented any logging (just print statements during development).
Because logging is not a must requirement, there is no need for logging. I used logging for debugging purposes, so I left these statements in my code, but disabled all logging when I submitted (I also mentioned this one in choices.txt). And I kept it simple by just using a ConsoleHandler (just because to avoid all issues with writing rights).
Glen Iris wrote:At the moment my FileHandler is printing out the log files in xml format to my log.txt file. How can I get them to print out to the file in the format that they print to the console?
Did you look at FileHandler API? I don't think so, because it's clearly stated. And I really don't like a developer who's too lazy to search for himself. If you don't know it, doing a bit of investigation yourself (google, java api,...) should always be an innate reflex! Please ShowSomeEffort.
Glen Iris wrote:how can I get them to not print to the console?
Again Google to the rescue. The first hit of googling with "java logging turning off console" will solve your problem (and gives you better insight in how the logging capabilities are setup).
Joined: Jul 29, 2012
Do you have the SCJD study guide?
By the way, you may find the Denny's DVD source code from Apress's web site.
Try log.log(....) and see if the log prints out on the console.
You may not need LogFileHandler.
Thanks again for the advice. Hi Dennis, I know I dont need logging for the SCJD but its been something I have been meaning to master for a while now so I think this is a good time. I will probably switch it off before submission anyway.
Roel, come on man, I get up at 6am each morning now to work on this assignment before I go to work. I spent quite a while looking for the info I requested. I found solutions here and there and was afraid my code was a pick and mix of things that didnt make sense. Thats why I posted my code with my question. I understand that people can abuse these forums but I am not one of them. I do appreciate your help and am very grateful to have you help me out. Even by you posting "java logging turning off console" has helped me because sometimes half the battle is knowing what to google.
Yes Himai Minh, I do have the study guide and log.log does print to the console. When I master the solution I will update this thread so others can use it too if they wish.
Glen Iris wrote:its been something I have been meaning to master for a while now so I think this is a good time.
I don't think you want to master JUL (java util logging), because it's (like you already discovered) a very hard to use API, not very intuitive (and as far as I know hardly used in real development). Learning (and getting familiar with) the concepts of logging (parent loggers, different handlers,...) is a good thing, because you have the same (or similar) ones with the logging frameworks (commons-logging, log4j,...) but these ones you can't use for the assignment (because these are not part of the SDK).
Glen Iris wrote:Roel, come on man, I get up at 6am each morning now to work on this assignment before I go to work. I spent quite a while looking for the info I requested.
Getting up early, not my cup of tea (I'm not an early-bird at all but a sometimes very late-night bird). If the answer to a question can be found in the javadoc of the class itself, I get a bit suspicious of laziness (and then I have to give the poste a little encouragement ) But other questions you post show indeed that you are putting in effort and not just being lazy and abusing the forum.
Glen Iris wrote:Even by you posting "java logging turning off console" has helped me because sometimes half the battle is knowing what to google.
So true! Sometimes I spent more than half an hour just trying to find the best search query on google