• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Logger

 
John Stark
Ranch Hand
Posts: 185
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,

I am just trying out the Logger and wondering why after setting the level to 'ALL'

any message below 'Info' (Config, Fine, ...) is not printed on the screen.

results in printing all message in the file but still only Severe, Warning and Info appears on the screen. Does anybody know why?

Thanks,

John
 
Roel De Nijs
Sheriff
Posts: 9934
113
AngularJS Chrome Eclipse IDE Hibernate Java jQuery MySQL Database Spring Tomcat Server
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
My guess would be the unintuitive logging api

Try the following code snippet:
 
John Stark
Ranch Hand
Posts: 185
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Still the same
 
Roel De Nijs
Sheriff
Posts: 9934
113
AngularJS Chrome Eclipse IDE Hibernate Java jQuery MySQL Database Spring Tomcat Server
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
That's weird! When I run this little program I don't see any output on the console.


But when I uncomment line 4 the expected message is shown in the console.
 
John Stark
Ranch Hand
Posts: 185
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Yes, this works. So I have to use ConsoleHandler I suppose? Thanks Roel.

John
 
Nam Ha Minh
Ranch Hand
Posts: 502
Eclipse IDE Firefox Browser Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Java's logging is not easy to use. Most developers prefer Log4J I think.
 
Roel De Nijs
Sheriff
Posts: 9934
113
AngularJS Chrome Eclipse IDE Hibernate Java jQuery MySQL Database Spring Tomcat Server
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
John Stark wrote:So I have to use ConsoleHandler I suppose?

Yes, if you want to show output on the console. If you want to write output to a file, you need a FileHandler. You could also use both (and you should even be able to set different levels for each handler). For the assignment and this certification I would suggest using ConsoleHandler, because with a FileHandler you have more issues (where to create file, what if you are in a read-only directory,...) than the ConsoleHandler. And logging is not a must requirement, so I would choose the line of least resistance.

Code snippet to set different levels for each handler:
 
Anayonkar Shivalkar
Bartender
Posts: 1557
5
Eclipse IDE Java Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Nam Ha Minh wrote:Java's logging is not easy to use. Most developers prefer Log4J I think.

Yes, but in OCMJD, candidates are not allowed any third party jars (rather any jars/libraries which are not part of default JDK).

By the way, is logging a must requirement?
 
Roel De Nijs
Sheriff
Posts: 9934
113
AngularJS Chrome Eclipse IDE Hibernate Java jQuery MySQL Database Spring Tomcat Server
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Anayonkar Shivalkar wrote:By the way, is logging a must requirement?

As already mentioned in my previous post, it is not.
 
Roberto Perillo
Bartender
Posts: 2271
3
Eclipse IDE Java Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Roel De Nijs wrote:As already mentioned in my previous post, it is not.


That's why I didn't bother!
 
Nam Ha Minh
Ranch Hand
Posts: 502
Eclipse IDE Firefox Browser Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Anayonkar Shivalkar wrote:
Nam Ha Minh wrote:Java's logging is not easy to use. Most developers prefer Log4J I think.

Yes, but in OCMJD, candidates are not allowed any third party jars (rather any jars/libraries which are not part of default JDK).

By the way, is logging a must requirement?


Ok then. Logging has been added to the exam? I don't know that because I passed the SCJP 4 years ago.
 
Anayonkar Shivalkar
Bartender
Posts: 1557
5
Eclipse IDE Java Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Nam Ha Minh wrote:Logging has been added to the exam?

No. Its just a way of troubleshooting the application. It is only for developer (if application fails, examiner would rather deduct the points instead of going through logs and trying to troubleshoot the application ).
Nam Ha Minh wrote:I don't know that because I passed the SCJP 4 years ago.

Did you mean SCJD? I cleared OCMJD(formerly SCJD) some 6-7 months back and logging was not a must requirement, so I didn't even go for a single bit of logging. All I did was putting print statements during debugging etc. and removing those for final version.
 
John Stark
Ranch Hand
Posts: 185
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Yes, if you want to show output on the console. If you want to write output to a file, you need a FileHandler. You could also use both (and you should even be able to set different levels for each handler). For the assignment and this certification I would suggest using ConsoleHandler, because with a FileHandler you have more issues (where to create file, what if you are in a read-only directory,...) than the ConsoleHandler.

Thanks Roel. Good to know logging is not required for the exam
John
 
Nam Ha Minh
Ranch Hand
Posts: 502
Eclipse IDE Firefox Browser Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Anayonkar Shivalkar wrote:
Did you mean SCJD? I cleared OCMJD(formerly SCJD) some 6-7 months back and logging was not a must requirement, so I didn't even go for a single bit of logging. All I did was putting print statements during debugging etc. and removing those for final version.


Hmm... No, I mean SCJP. I didn't know that you were talking about SCJD.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic