8i | 9i | 10g | 11g | 12c | 13c | 18c | Misc | PL/SQL | SQL | RAC | WebLogic | Linux

Home » Articles » Web » Here

Set Managed Server HTTP Log Format Using WebLogic Scripting Tool (WLST)

WebLogic Scripting Tool (WLST) provides a command line scripting interface to manage WebLogic Server instances and domains. This article gives an example of creating a node manager reference in an existing domain using WLST. You will need to adjust the values in the properties file and may wish to alter the script to suit your needs.

The easiest way to generate WLST scripts is to use the "Record" functionality in the Administration Console. The WLST in this article was generated in that way, then amended to replace hard-coded values with parameters.

Script

Create a file called "set_ms_http_log_format.py" with the following contents.

#!/usr/bin/python
# Author : Tim Hall
# Save Script as : set_http_log_format.py

import time
import getopt
import sys
import re

# Get location of the properties file.
properties = ''
try:
   opts, args = getopt.getopt(sys.argv[1:],"p:h::",["properies="])
except getopt.GetoptError:
   print 'create_nodemanagr_ref.py -p <path-to-properties-file>'
   sys.exit(2)
for opt, arg in opts:
   if opt == '-h':
      print 'create_nodemanagr_ref.py -p <path-to-properties-file>'
      sys.exit()
   elif opt in ("-p", "--properties"):
      properties = arg
print 'properties=', properties

# Load the properties from the properties file.
from java.io import FileInputStream
 
propInputStream = FileInputStream(properties)
configProps = Properties()
configProps.load(propInputStream)

# Set all variables from values in properties file.
adminUsername=configProps.get("admin.username")
adminPassword=configProps.get("admin.password")
adminURL=configProps.get("admin.url")
msName=configProps.get("ms.name")
logFileFormat=configProps.get("log.file.format")
logFileFields=configProps.get("log.file.fields")

# Display the variable values.
print 'adminUsername=', adminUsername
print 'adminPassword=', adminPassword
print 'adminURL=', adminURL
print 'msName=', msName
print 'logFileFormat=', logFileFormat
print 'logFileFields=', logFileFields

# Connect to the AdminServer.
connect(adminUsername, adminPassword, adminURL)

edit()
startEdit()

# Set the log format and fields.
cd('/Servers/' + msName + '/WebServer/' + msName + '/WebServerLog/' + msName)
cmo.setLogFileFormat(logFileFormat)
cmo.setELFFields(logFileFields)

save()
activate()

disconnect()
exit()

Properties

Create a file called "myDomain-ms-log.properties" with the following contents.

# AdminServer connection details.
admin.username=weblogic
admin.password=Password1
admin.url=t3://ol6.localdomain:7006

# Managed server details.
ms.name=MyServer_2

# Log format details.
log.file.format=extended
log.file.fields=c-ip cs cs-username date time cs-method cs-uri cs-version sc-status bytes cs(X-Forwarded-For)

The standalone "cs" results in an extra "-" character.

Run It

Set the managed server HTTP log format using the following commands.

# Set environment.
export MW_HOME=/u01/app/oracle/middleware
export WLS_HOME=$MW_HOME/wlserver_10.3
export WL_HOME=$WLS_HOME
export JAVA_HOME=/u01/app/oracle/jdk1.7.0_79
export PATH=$JAVA_HOME/bin:$PATH
export DOMAIN_HOME=/u01/app/oracle/config/domains/myDomain

. $DOMAIN_HOME/bin/setDomainEnv.sh

# Create the node manager reference.
java weblogic.WLST set_ms_http_log_format.py -p myDomain-ms-log.properties

For more information see:

Hope this helps. Regards Tim...

Back to the Top.