Based on the Comment/Query of one of our Magic Subscriber “Kimjim” (http://middlewaremagic.com/weblogic/?p=1473#comment-4594) , We are going to see how we can edit the WebServer Logging like displaying the Client IP Adddress in the access Log of a Server by adding (Extended Loging Formats c-ip) and changing the various attribute of Logging in one go.
This script also demonstrates how we should use the edit() , activate() and startEdit() kind of functions inside the WLST Script if we are migrating our WLST Scripts from WebLogic 8.1 because in WebLogic 8.1 the change control (Lock & Edit) feature was not available in the Admin Console.
Step1). Write the following WLST Script somewhere in your file system:
connect('weblogic','weblogic1','t3://localhost:7001') domainConfig() managedServers=cmo.getServers() print 'Found ' + `len(managedServers)` + ' managed servers' for managedServer in managedServers: try: edit() startEdit() serverName = managedServer.getName() print 'tt==================='+serverName+'====================' cd('/Servers/'+serverName+'/WebServer/'+serverName+'/WebServerLog/'+serverName) cmo.setLogTimeInGMT(false) cmo.setLogFileFormat('common') cmo.setELFFields('c-ip date time time-taken bytes cs-method cs-uri sc-status') activate() print ' ' print ' ' except java.lang.Exception, ex: print 'Exception on Changing the Log Attributes: ' + ex.toString()
Step2). Now we need to set the CLASSPATH and PATH environment variables using setWLSEnv.sh or setDomainEnv.sh script.
Step3). Run the WLST Script java WebLogic.WLST changeLogFormats.py
java weblogic.WLST changeLogFormats.py Initializing WebLogic Scripting Tool (WLST) ... Welcome to WebLogic Server Administration Scripting Shell Type help() for help on available commands Connecting to t3://localhost:7001 with userid weblogic ... Successfully connected to Admin Server 'AdminServer' that belongs to domain 'base_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. Location changed to serverRuntime tree. This is a read-only tree with DomainMBean as the root. For more help, use help(domainConfig) Found 2 managed servers Location changed to edit tree. This is a writable tree with DomainMBean as the root. To make changes you will need to start an edit session via startEdit(). For more help, use help(edit) Starting an edit session ... Started edit session, please be sure to save and activate your changes once you are done. ===================AdminServer==================== Activating all your changes, this may take a while ... The edit lock associated with this edit session is released once the activation is completed. Activation completed Already in Edit Tree Starting an edit session ... Started edit session, please be sure to save and activate your changes once you are done. ===================MS1==================== Activating all your changes, this may take a while ... The edit lock associated with this edit session is released once the activation is completed. Activation completed