Using the Tcl Log package with Jacl to control debug output.

The Tcl log package can be used with Jacl to control the generation of debug statements in standard output.  The log package is part of tcllib distro at sourceforge.

http://sourceforge.net/project/showfiles.php?group_id=12883 

Jacl supports Tcl 8.0 or lower so the only component of the log package that can be use safely is ::log.   It's a single Tcl script that can be downloaded from:

www.websphereconsultants.com/WSAdmin/docs/log/log.zip


The log package is documented at:   http://aspn.activestate.com/ASPN/docs/ActiveTcl/8.4/tcllib/log/log.html

Example    -   Using the log package with Jacl.

The log package needs to be loaded into the Jacl namespace.  Use auto_mkindex to generate the tclIndex file and modify the TCLLIBPATH variable to include the log package directory location. 

The procedures must be clean i.e have no syntax errors or auto_mkindex will error out.  Use the nagelfar syntax checker  to scan the directory.  Nagelfar requires Tcl/Tk so download the free Active State distro from  Active State if required.

In this example the  procedure library is located at C:\home\patrick\eclipse\WASAdminSBV\WSAdmin\WAS6.1\JACL\proclib and the log package is located at C:\home\patrick\eclipse\WASAdminSBV\WSAdmin\WAS6.1\JACL\proclib\log 

Write a two line script auto_mkindex.tcl with the required auto_mkindex commands.

auto_mkindex proclib *.tcl
auto_mkindex proclib/log *.tcl

Execute the tcl script. 

C:\Tcl\bin>cd C:\home\patrick\eclipse\WASAdminSBV\WSAdmin\WAS6.1\JACL
C:\home\patrick\eclipse\WASAdminSBV\WSAdmin\WAS6.1\JACL>C:\Tcl\bin\tclsh.exe  autoMkIndex.tcl

Check the tclindex file in C:\home\patrick\eclipse\WASAdminSBV\WSAdmin\WAS6.1\JACL\proclib\log

type C:\home\patrick\eclipse\WASAdminSBV\WSAdmin\WAS6.1\JACL\proclib\log\tclIndex

# Tcl autoload index file, version 2.0
# This file is generated by the "auto_mkindex" command
# and sourced to set up indexing information for one or
# more commands.  Typically each line is a command that
# sets an element in the auto_index array, where the
# element name is the name of a command and the value is
# a script that loads the command.

set auto_index(::log::levels) [list source [file join $dir log.tcl]]
set auto_index(::log::lv2longform) [list source [file join $dir log.tcl]]
set auto_index(::log::lv2color) [list source [file join $dir log.tcl]]
set auto_index(::log::lv2priority) [list source [file join $dir log.tcl]]
set auto_index(::log::lv2cmd) [list source [file join $dir log.tcl]]
set auto_index(::log::lv2channel) [list source [file join $dir log.tcl]]
set auto_index(::log::lvCompare) [list source [file join $dir log.tcl]]
set auto_index(::log::lvSuppress) [list source [file join $dir log.tcl]]
set auto_index(::log::lvSuppressLE) [list source [file join $dir log.tcl]]
set auto_index(::log::lvIsSuppressed) [list source [file join $dir log.tcl]]
set auto_index(::log::lvCmd) [list source [file join $dir log.tcl]]
set auto_index(::log::lvCmdForall) [list source [file join $dir log.tcl]]
set auto_index(::log::lvChannel) [list source [file join $dir log.tcl]]
set auto_index(::log::lvChannelForall) [list source [file join $dir log.tcl]]
set auto_index(::log::lvColor) [list source [file join $dir log.tcl]]
set auto_index(::log::lvColorForall) [list source [file join $dir log.tcl]]
set auto_index(::log::logarray) [list source [file join $dir log.tcl]]
set auto_index(::log::loghex) [list source [file join $dir log.tcl]]
set auto_index(::log::log) [list source [file join $dir log.tcl]]
set auto_index(::log::logMsg) [list source [file join $dir log.tcl]]
set auto_index(::log::logError) [list source [file join $dir log.tcl]]
set auto_index(::log::Puts) [list source [file join $dir log.tcl]]

Create a script restartAll.tcl with debug statements.  Toggle debug output for all levels below emergency with "::log::lvSuppressLE emergency 0" and "::log::lvSuppressLE emergency 1".  Any debug statements in restartAll.tcl and ::restartAll::restartAll will be activated when debug is toggled on. 

#switch on
::log::lvSuppressLE emergency 0
#switch off
#::log::lvSuppressLE emergency 1
::log::lvColor debug red

::log::log debug           "print out environment array"
::log::logarray debug      env
::log::log debug           "**** end ****"

if { [ catch { ::restartAll::restartAll } r  ] == 0 } {

    putsLog "servers started successfully"

} else {

  return -code error $r

}

Execute wsadmin setting the TCLLIBPATH variable to the procedure library and log path locations.

@echo off

setlocal

set wsadminDir=C:\IBM\WASND61\AppServer\bin
::## TCLLIBPATH directories should be separated by spaces.
set TCLLIBPATH="TCLLIBPATH=C:\\home\\patrick\\eclipse\\WASAdminSBV\\WSAdmin\\WAS6.1\\JACL\\proclib C:/home/patrick/eclipse/WASAdminSBV/WSAdmin/WAS6.1/JACL/proclib/log"
set scriptFile="C:\home\patrick\eclipse\WASAdminSBV\WSAdmin\WAS6.1\JACL\restartAll.tcl"

set host="yourHost"
set port="8879"
set user="yourUserid"
set password="yourPassword"

echo " "
echo "tcllib = %TCLLIBPATH%"
echo " "

call %wsadminDir%\wsadmin_default.bat -user %user% -password %password% -lang jacl -javaoption -D%TCLLIBPATH% -host %host% -port %port% -f %scriptFile%

endlocal

Check the output from the script.  The env array is printed only when debug is switched on.

...................................................................
...................................................................
debug     env(java.specification.name)                 = Java Platform API Specification
debug     env(java.specification.vendor)               = Sun Microsystems Inc.
debug     env(java.specification.version)              = 1.5
debug     env(java.util.logging.configureByServer)     = true
debug     env(java.util.logging.manager)               = com.ibm.ws.bootstrap.WsLogManager
debug     env(java.util.prefs.PreferencesFactory)      = java.util.prefs.WindowsPreferencesFactory
debug     env(java.vendor)                             = IBM Corporation
debug     env(java.vendor.url)                         = http://www.ibm.com/
debug     env(java.version)                            = 1.5.0
debug     env(java.vm.info)                            = J2RE 1.5.0 IBM J9 2.3 Windows XP x86-32 j9vmwi3223-20070426 (JI
T enabled)
J9VM - 20070420_12448_lHdSMR
JIT  - 20070419_1806_r8
GC   - 200704_19
....................................................................
...................................................................
debug     **** end ****