Manually rotate WebLogic Server Logfiles

Posted by Dirk Nachbar on Tuesday, October 24, 2017 with No comments
From time to time you have the requirement to rotate the WebLogic Server Logfiles manually on the fly without stopping the WebLogic Managed Servers or AdminServer, for example while you perform some load tests in order to have fresh WebLogic Server Logfiles.

Here is a small Python Script, which rotates the WebLogic Server Logfiles for a list of given Managed Servers and AdminServer.

You will need:
  • = Python Script which rotates the Logfiles
  • = Property File for the required connect data to the Admin Server of your WebLogic Domain
The Python Script will read the Property File (parameter -props) in order to get the necessary data for the connect to the Admin Server of your WebLogic Server Domain and will loop through your provided list of Servers (parameter -servers) and force a rotating of the logfiles. The list of Servers (parameter -servers) can accept multiple Servers delimited by ":".

# Align the values for your settings

# ============================================================
# Script:
# Author: Dirk Nachbar, https/
# Purpose: Rotates the WebLogic Server Logfiles for a list
#          of given Servers, either AdminServer or Managed Servers
# ============================================================

# Imports 
import sys
from import File
from import FileOutputStream
from import FileInputStream


def helpUsage():
    print 'Usage: -help'
    print '          [-servers] list of Servers, delimited by :'
    print '          [-props] properties file for connect to AdminServer'
    print 'E.g.: -servers DEMOMS1:DEMOMS2 -props /home/oracle/'

def connectAdmin():

for i in range(len(sys.argv)):
    if sys.argv[i] == "-help":
    elif sys.argv[i] == "-servers":
        if i+1 < len(sys.argv):
            servers_list = sys.argv[i+1]
    elif sys.argv[i] == "-props":
        if i+1 < len(sys.argv):
            configfile = sys.argv[i+1]

if len(servers_list)==0 or len(configfile)==0:
    print 'Missing required arguments (-servers, -props)'
    print ''

propInputStream = FileInputStream(configfile)
configProps = Properties()




for server in servers:
    print '================================================'
    print 'Current Server: ' +server
    print 'Rotating Logfile for Server: ' +server
    print '================================================'

Create the 2 above given files on your Server hosting the Oracle WebLogic Domain, align the file with your settings, connect to your Server with the Oracle Software User and execute the script as following:

oracle@server> $ORACLE_HOME/oracle_common/common/bin/ -props -servers DEMOMS1:DEMOMS2
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 "DemoAdminServer" that belongs to domain "demo_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 domainRuntime tree. This is a read-only tree 
with DomainMBean as the root MBean. 
For more help, use help('domainRuntime')

Current Server: DEMOMS1
Rotating Logfile for Server: DEMOMS1
Current Server: DEMOMS2
Rotating Logfile for Server: DEMOMS2

Happy rotating of WebLogic Server Logfiles . . .