Limit the growth of JVM log files using scripting
There are two ways to perform this task. This topic demonstrates how to use the AdminConfig object to modify the server configuration. Alternatively, we can use the configureJavaProcessLogs Jython script in the AdminServerManagement script library to configure the JVM log settings. The wsadmin tool automatically loads the script when the tool starts. Use the following syntax to configure JVM log settings using the configureJavaProcessLogs script:
AdminServerManagement.configureJavaProcessLogs(nodeName, serverName, processLogRoot, otherAttributeList)
For additional information and argument definitions, see the documentation for the AdminServerMananagment script library.
Tasks
- Start the wsadmin scripting tool.
- Identify the application server of interest.
Determine the configuration ID of the application server of interest and assign it to the server1 variable:
- Use Jacl:
set s1 [$AdminConfig getid /Cell:mycell/Node:mynode/Server:server1/]
- Use Jython:
s1 = AdminConfig.getid('/Cell:mycell/Node:mynode/Server:server1/')
print s1where:
Element Description set Jacl command s1 Variable name $ Jacl operator for substituting a variable name with its value AdminConfig Object representing the WebSphere Application Server configuration getid AdminConfig command Cell Object type mycell Name of the object that will be modified Node Object type mynode Name of the object that will be modified Server Object type server1 Name of the object that will be modified Jython command
Example output:
server1(cells/mycell/nodes/mynode/servers/server1|server.xml#Server_1)
- Identify the stream log of interest.
Determine the stream log of interest and assign it to the log variable. The following example identifies the output stream log:
- Use Jacl:
set log [$AdminConfig showAttribute $s1 outputStreamRedirect]
- Use Jython:
log = AdminConfig.showAttribute(s1, 'outputStreamRedirect')
The following example identifies the error stream log:
- Use Jacl:
set log [$AdminConfig showAttribute $s1 errorStreamRedirect]
- Use Jython:
log = AdminConfig.showAttribute(s1, 'errorStreamRedirect')
Example output:
(cells/mycell/nodes/mynode/servers/server1|server.xml#StreamRedirect_2)
- List the current values of the stream log.
Display the current values of the stream log of interest:
- Use Jacl:
$AdminConfig show $log
- Use Jython:
AdminConfig.show(log)
Example output:
{baseHour 24}
{fileName ${SERVER_LOG_ROOT}/SystemOut.log}
{formatWrites true}
{maxNumberOfBackupFiles 1}
{messageFormatKind BASIC}
{rolloverPeriod 24}
{rolloverSize 1}
{rolloverType SIZE}
{suppressStackTrace false}
{suppressWrites false}- Modify the rotation policy for the stream log.
Set the rotation log file size to two megabytes:
- Use Jacl:
$AdminConfig modify $log {{rolloverSize 2}}
- Use Jython:
AdminConfig.modify(log, [['rolloverSize', 2]])
Set the rotation policy to manage itself. It is based on the age of the file with the rollover algorithm loaded at midnight, and the log file rolling over every 12 hours:
- Use Jacl:
$AdminConfig modify $log {{rolloverType TIME} {rolloverPeriod 12} {baseHour 24}}
- Use Jython:
AdminConfig.modify(log, [['rolloverType', 'TIME'], ['rolloverPeriod', 12], ['baseHour', 24]])
Set the log file to roll over based on both time and size:
- Use Jacl:
$AdminConfig modify $log {{rolloverType BOTH} {rolloverSize 2} {rolloverPeriod 12} {baseHour 24}}
- Use Jython:
AdminConfig.modify(log, [['rolloverType', 'BOTH'], ['rolloverSize', 2], ['rolloverPeriod', 12], ['baseHour', 24]])
- Save the configuration changes.
AdminConfig.save()
- In a network deployment environment only, synchronize the node.
Use the syncActiveNode or syncNode scripts in the AdminNodeManagement script library to propagate the configuration changes to node or nodes.
- Use the syncActiveNodes script to propagate the changes to each node in the cell:
AdminNodeManagement.syncActiveNodes()
- Use the syncNode script to propagate the changes to a specific node:
AdminNodeManagement.syncNode("myNode")
Configure the JVM logs wsadmin AdminConfig Server settings configuration scripts JVM log settings Commands for the AdminConfig object