Alot of times I have seen the questions popping up whether to use isDebugEnabled property or not. Arguably most of the times or rather always about performance. Some of the stuff that I feel important about using it follows.
The answer is simple. It is made to be used. However using it has to be with caution.
For instance
If I am using the following line in my code.
1 | log.debug("I am there"); |
Thats an example of a good practise
However I can really blow it out of proportions if I do the following.
1 2 3 4 | // Not good practise if (log.isDebugEnabled()){ log.debug("I am there"); } |
And why exactly is that so. This is because the method debug in the class Category i.e. extended by Logger in the log4j libraries explicitly checks the mode for the logging itself.
Extract from the class org.apache.log4j.Category is below
1 2 3 4 5 6 7 | public void debug(Object message) { if(repository.isDisabled(Level.DEBUG_INT)) return; if(Level.DEBUG.isGreaterOrEqual(this.getEffectiveLevel())) { forcedLog(FQCN, Level.DEBUG, message, null); } } |
Okay so thats the case where we say dont use it. What about the one where we actually do use the isDebugEnabled property.
For instance you have a large parameter going in the debug.
1 2 | // Bad Practise log.debug("XML "+Tree.getXMLText()); |
In such a case it can clearly be said “No dont do it!” If Tree.getXMLText is going to pull out all the hair out of the app then there is no use. As it will be constructed first and if the debug level is not enabled that would be a performance cost.
1 2 3 4 | // Good Practise if (log.isDebugEnabled()){ log.debug("XML "+Tree.getXMLText()); } |
Thus in the example above it would be wiser to use log.isDebugEnabled() just to make sure the mileage or cost stays lesser.
Tags: best practise, Java, log4j, logging, Programming
You can simply add the following to a target.
For the following wsadmin should be in your PATH env.
< exec dir="." executable="wsadmin.bat" logError="true" failonerror="true" output="wsconfig.out" >
< arg line="-lang jython -f ../../createQFactory.py"/ >
< /exec >
All output will be logged to wsconfig.out
Tags: Administrator, ant, HOWTO, IBM, Java, jdbc, jython, Programming, script, scripting, sysadmin, websphere, wsadmin
On my way to my solution store just found this nice to use, old and easy feature.
Possibilities endless, usage typically very easy.
I used the following to generate XML from sqlplus:
select dbms_xmlgen.getxml('select * from user') from dual;
Output:
< ROWSET >
< ROW >
< TNAME >Employee< / TNAME >
< TABTYPE > TABLE < / TABTYPE >
< / ROW >
< / ROWSET >
Tags: DBMS_XMLGEN, HOWTO, Programming, Software, Software Development, sql, tips, utils