• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

logging in java

 
Ranch Hand
Posts: 1143
5
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
hello,
i want to know what is logging in java.
i did a google search and i found lots of examples and codes, but still don't know
why to use logging?
when to use logging?
where to use logging?
 
Bartender
Posts: 1558
5
Eclipse IDE Java Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Punit Jain wrote:hello,
i want to know what is logging in java.
i did a google search and i found lots of examples and codes, but still don't know
why to use logging?
when to use logging?
where to use logging?


Logging is, well, keeping a log of what is going on in application. Generally, all real life applications use log.

Why - Logging is basically used to give other user an idea of what is going on. e.g. an application might fail due to database is down etc. Now, if you log everything properly, you can understand to root cause by simply looking at the log. No need to open the code and start debugging

When - I would suggest that you should always do logging. It always helps.

Where - You can choose a single file or multiple files (single file is easier to maintain).

You can use in built logging classes from Java, or some external utility like log4j etc.

I hope this helps.
 
Punit Jain
Ranch Hand
Posts: 1143
5
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thank you for your reply, and yes it helps me allot.
but i have few more questions:
1.> how to use, best way/resource to learn?
you mean that it also helpful in this way:- Suppose i developed a desktop application, and i used logging in that, so all the exceptions or error(if occurred any time during the use of software), will be stored in that single file..isn't it?
 
Anayonkar Shivalkar
Bartender
Posts: 1558
5
Eclipse IDE Java Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
You are welcome.

1.> how to use, best way/resource to learn?


There are various utilities, out of which, the most popular one is log4j. It is very flexible, easy to use and easy to configure. Another is in built logging in Java, which is said to be quite complicated (compared to log4j). I've only used log4j so far.

Suppose i developed a desktop application, and i used logging in that, so all the exceptions or error(if occurred any time during the use of software), will be stored in that single file..isn't it?


Well, no. I hope you do understand that logging doesn't happen automatically. You have to manually put logging statements in the code. e.g. if you are not logging anything during DB failure, there won't be anything(related to DB failure) in the log. I think you got the idea.

Also, there are several logging levels - once you get to understand how logging works, its quite easy and useful.

HIH.
 
Punit Jain
Ranch Hand
Posts: 1143
5
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator


Well, no. I hope you do understand that logging doesn't happen automatically. You have to manually put logging statements in the code. e.g. if you are not logging anything during DB failure, there won't be anything(related to DB failure) in the log. I think you got the idea.


yes i mean by that, if i manually set logging statements then the problems(bugs and errors) for which i have set logging statements will be stored in the file, instead of displaying on the console(when we use e.printStackTrace).
isn't it?
 
Anayonkar Shivalkar
Bartender
Posts: 1558
5
Eclipse IDE Java Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Correct
 
Saloon Keeper
Posts: 7585
176
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Logging libraries such log4j let you control precisely which logging output goes where - one or more files and the console are both possible, and it's also perfectly feasible to have logging output appear in both places.
 
Punit Jain
Ranch Hand
Posts: 1143
5
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
okay...
thank you Anayonkar Shivalkar and Tim Moores for explaining..
 
Anayonkar Shivalkar
Bartender
Posts: 1558
5
Eclipse IDE Java Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
You are welcome.
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
reply
    Bookmark Topic Watch Topic
  • New Topic