• 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
  • Tim Cooke
  • Ron McLeod
  • Jeanne Boyarsky
  • Paul Clapham
Sheriffs:
  • Liutauras Vilda
  • Henry Wong
  • Devaka Cooray
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • Al Hobbs
  • Carey Brown
Bartenders:
  • Piet Souris
  • Mikalai Zaikin
  • Himai Minh

Java assert for logging?

 
Ranch Hand
Posts: 64
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Suppose I have this:

I call a logging API from within an assert expression like so:
assert(log("My message")) ;

where the logging API is
boolean log(String message);

Now I can disable logging (by disabling assert) and also selectively enable/disable logging for certain classes by using the assert functionality.

Do you see any problem with this? If there is none, I would like to this method instead of using a "heavy" logging framework.

Thanks
Mani
 
Ranch Hand
Posts: 410
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Which logging API are you using? I don't see a method with that signature in the java.util.logging package.

Either way, I think I would recommend against this just because it isn't what assertions are designed to do. I understand that you want to turn off assertions, but why turn off logging? Logging can be a very useful tool even in the field.

Even if you must turn if off completely, it might be better to do this the 'proper' way: such as passing Level.OFF to the setLevel method in the Java Logging API.
 
reply
    Bookmark Topic Watch Topic
  • New Topic