Adding Python logging module to WLST

When developing a WLST script i was looking for a standard way to implement logging for that script. Since any recent version of Python contains the logging module, i was somehow surprised that this module was not available in WLST. I found some nice workarounds using the log4j classes but still prefer the Pythonic way. Weblogic server 10.3.6.0 still contains version 2.2.1 of Python wherein the logging module is not by default available. I found a compatible version of the logging module here at red-dove.com, but failed miserably adding the module to the environment variable PYTHONPATH. After copying the logging folder from the downloaded tarball to a folder /u01/app/pymodules i added the directory to PYTHONPATH. Paths in this environment variable are normally reflected in sys.path but this seems not the case in WLST.

[wlsadmin@pvm0001 medrec]$ export PYTHONPATH=$PYTHONPATH:/u01/app/python
[wlsadmin@pvm0001 medrec]$ java weblogic.WLST

Initializing WebLogic Scripting Tool (WLST) ...

Welcome to WebLogic Server Administration Scripting Shell

Type help() for help on available commands

wls:/offline> print sys.path
['/u01/app/Oracle/Middleware/wlserver_10.3/server/lib/weblogic.jar/Lib', '__classpath__', '/u01/app/Oracle/Middleware/wlserver_10.3/server/lib/weblogic.jar', '/u01/app/Oracle/Middleware/wlserver_10.3/common/wlst/modules/jython-modules.jar/Lib', '/u01/app/Oracle/Middleware/wlserver_10.3/common/wlst', '/u01/app/Oracle/Middleware/wlserver_10.3/common/wlst/lib', '/u01/app/Oracle/Middleware/wlserver_10.3/common/wlst/modules', '.']
wls:/offline> import logging
Traceback (innermost last):
  File "<console>", line 1, in ?
ImportError: no module named logging
wls:/offline>


What can be made up from the output of sys.path is that there is a location for additional modules in ${WL_HOME}/common/wlst/modules. When copying the logging folder from the tarball to this location you can use the PYTHON logging module in WLST.

[wlsadmin@pvm0001 medrec]$ java weblogic.WLST

Initializing WebLogic Scripting Tool (WLST) ...

Welcome to WebLogic Server Administration Scripting Shell

Type help() for help on available commands

wls:/offline> import logging
wls:/offline> logging.basicConfig()
wls:/offline> log = logging.getLogger("MyFirstLogger")
wls:/offline> log.setLevel(logging.DEBUG)
wls:/offline> log.info("That does work =:-)")
INFO:MyFirstLogger:That does work =:-)
wls:/offline> 




Comments

QBrowser start script for WLS adopted by QBrowser project

It is always nice to hear that your contribution is appreciated! The QBrowser start script which i recently published in my article "Starting QBrowser for Weblogic on (Oracle) Linux" is adopted by the QBrowser for GlassFish JMS / WebLogic MQ project on sourceforge.net. The script will included in version V2.5.2.8.1 and up.


Comments

Starting QBrowser for Weblogic on (Oracle) Linux

For my personal OSB playground i use a Virtual Machine with Oracle Linux. When recently working on an OSB project with JMS i was looking for a tool enabling me to send messages to a JMS Queue or Topic. After i failed to get Hermes JMS working properly i tried QBrowser light. Although there were no proper unix scripts supplied to start QBrowser, it was quite easy to write one my own based on the batch files. I got QBrowser working after correcting all version numbers of the jar files in the QB_CLASS_PATH to the current version of my installation. Since i did have no intention to validate the version numbers of the jar files for each configuration i have, i made a little script which automatically detects the installed com.bea.core.* jar files, adds them to the QB_CLASS_PATH and starts QBrowser.

Read More...
Comments