WLST

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