EmmanuelOga / hypergraphdb

Automatically exported from code.google.com/p/hypergraphdb
1 stars 0 forks source link

Usage of a logging Framework instead of System.out #94

Closed GoogleCodeExporter closed 9 years ago

GoogleCodeExporter commented 9 years ago
Printing Log-Messages like

System.out.println("checkpoint kbytes:" + ckptConfig.getKBytes());
System.out.println("checkpoint minutes:" + ckptConfig.getMinutes());

directly to stdout seems to be an anti-pattern. Why?

System.out should be used to print the Primary output (results, for example) of 
the program. If you use it like that, you may, for example, pipe the results to 
other programs if you want. If you print diagnostic messages to stdout, you 
will loose this ability.

One could print to stderr, which is a much cooler way, but it still has some 
(maybe unwanted) side effects. Since you try to build HypergraphDB in a 
"framework like" fashion, you force the users of HypergraphDB to accept the 
output to be printed like that - even if their business logic uses stderr for 
other messages. Maybe a hypergraphdb-User wants it's diagnostic output to go to 
a log file, for example.

The optimal way would be to use a logging framework. I would suggest slf4j, it 
is not a logging-Framework itself, but only a facade acting as a compatibility 
layer to other Logging frameworks. Using slf4j, you do not force the users of 
hypergraph to use a logging framework of your choice - instad whey are abel to 
plug nearly all relevant current Logging Framework behind slf4j.

More information can be found at http://www.slf4j.org/

Beste regards,
Benjamin

Original issue reported on code.google.com by google-a...@gehrels.info on 14 Jan 2013 at 3:02

GoogleCodeExporter commented 9 years ago
Hi Benjamin,

HyperGraphDB should not output anything and the printouts that you see 
(checkpoint kbytes etc.) on stdout are basically a bug and I just removed them. 
They slipped into the release because somehow I got used to seeing them, 
learned to ignore them so I didn't pay attention to them anymore. HyperGraphDB 
may only print errors (stack traces) to stderr if there's no way to propagate 
the exception to the caller, but even such cases should be removed as much as 
possible (currently I'm not sure if there are any!). 

That said, sometimes it may be helpful to turn on some tracing of HGDB 
processing. But there's no such thing for now, simply because we've been able 
to get by without it just fine! Also, I'm not a big fan of logging frameworks 
and in particular I've had nasty problems with slf4j in the past because of 
incompatible versions that were independently included by two independent 3d 
party libraries.

Cheers,
Boris

PS Many thanks for your thorough bug reports!! I'll address the pending ones 
shortly...

Original comment by borislav...@gmail.com on 15 Jan 2013 at 3:28