Monday, March 18, 2013

How to List Current Message Levels of All Loggers Using WLST?

In our Fusion application deployed in WebLogic Server, it has generated too many messages. Therefore, we would like to disable most of them. However, before we do that, we also want to check out what current message levels of loggers are.

In this article, we will show you how to:
  • Redirect WLST print messages to an output file
  • List current message levels of all loggers associated with a managed server (i.e., "MS_1")
    • With the getLogLevel command

Redirect WLST print Statement


If you try to redirect WLST output to a log file using the following WLST command. 

wls:/fod_domain/serverConfig> redirect('./logs/wlst.log', 'false')

It won't work.  Instead , you should follow the instructions below[1] to redirect WLST's print statement to a file:

from java.io import File
from java.io import FileOutputStream
f = File("/scratch/aime1/tmp/wlst.log")
fos = FileOutputStream(f)
theInterpreter.setOut(fos)
print "start the script"

How to List Current Message Levels of All Loggers?


To get the current message level, you can use getLogLevel command. Note that you must be connected to WebLogic Server before you use the configuration commands.

From below, find the full list of commands that achieved the task:

$cd $MW_HOME/wlserver/common/bin
$./wlst.sh


Initializing WebLogic Scripting Tool (WLST) ...
Welcome to WebLogic Server Administration Scripting Shell
Type help() for help on available commands

wls:/offline> connect ('weblogic','weblogic1','t3://localhost:7001')
Connecting to t3://localhost:7001 with userid weblogic ...
Successfully connected to Admin Server "AdminServer" that belongs to domain "fod_domain".

Warning: An insecure protocol was used to connect to the
server. To ensure on-the-wire security, the SSL port or
Admin port should be used instead.

wls:/fod_domain/serverConfig> from java.io import File
wls:/fod_domain/serverConfig> from java.io import FileOutputStream
wls:/fod_domain/serverConfig> f = File("/scratch/aime1/tmp/wlst.log")
wls:/fod_domain/serverConfig> fos = FileOutputStream(f)
wls:/fod_domain/serverConfig> theInterpreter.setOut(fos)
print "start the script"
listLoggers(target='MS_1')

Note that we typed CTRL-D to exit from WLST at the end.

The Output

Here is the output from the getLogLevel command (note that it lists messages levels of all loggers associated with a server named MS_1):

wls:/fod_domain/serverConfig> start the script
wls:/fod_domain/serverConfig> Location changed to domainRuntime tree. This is a read-only tree with DomainMBean as the root.
For more help, use help('domainRuntime')
-------------------------+-----------------
Logger                   | Level
-------------------------+-----------------
<root>                   | NOTIFICATION:1
Security                 | <Inherited>
com                      | <Inherited>
com.oracle.coherence     | TRACE:16
...

References

2 comments:

Blogger said...

DreamHost is one of the best hosting provider for any hosting plans you need.

Prasad Shenwai said...

Worked perfectly! The post is well written and helped a lot, many thanks!