Search This Blog

Wednesday, July 26, 2017

Logging configuration for domain and WebLogic server

Why we need Logging?
To understand in a basic level, when we run the WebLogic Servers we don't know what is happening inside the process.  It is kind of black box to us. To know what is happening inside the domain or server side to get more details we have logging mechanism enabled in WebLogic domains.


WebLogic Logging works for multiple hierarchical Subsystem. At the top level it is already enabled and we can use the existing setup. But for some reasons each project will have separate logging needs.

When we can use this?
If there are multiple Testing logging configuration at different levels:
  1. domain level logs - global status 
  2. Server level logs - admin or managed server status
  3. Resource level logs - JDBC, JMS, application status
We can set the common attributes of JMX MBean reset with new values which will work for your project needs.

While creating this snippet we have tried to execute it on WebLogic 11g [10.3.6] and WebLogic 12c.

########################################################################
# Python Script file: logrotate.py
# Author: Pavan Devarakonda
# Date : 25-Jul-2017
########################################################################
loadProperties('demodomain.properties')
# Functions
def editMode():
   edit()
   startEdit()

def saveActivate():
   save()
   activate()
   print '###### Completed configuration of domain logs ##############'

def exitDisconnect():
        disconnect()
        exit()

def connectToAdmin():
    connect(username,password,url)

def domainlog_rotation(domainname,FC,MinSize):
        """
        It will take the three parameters domainpath ,domainname is string values
        and FileCount -  FC and File MinSize - MinSize are integer values these values loaded from properties
        so they need to type cast to integers
        """
        cd('/Log/'+domainname)
        cmo.setRotationType('bySize')
        cmo.setRotateLogOnStartup(true)
        cmo.setFileCount(int(FC))
        cmo.setNumberOfFilesLimited(true)
        cmo.setFileMinSize(int(MinSize))
        cmo.setLogFileRotationDir(domainpath+domainname+'/RotationDir')
        save()

def ServerLogRotation(S,SFC,SMinsize):
        """
        This module will rotate the AdminServer or Managed Server loggger settings
        It takes three params - S as name of the server, SFC - Server FileCount, SMinsize - Server FileMinSize
        """
        print S+ ' server log  setting...'
        cd('/Servers/'+S+'/Log/'+S)
        cmo.setRotationType('bySize')
        cmo.setRotateLogOnStartup(true)
        cmo.setFileCount(int(SFC))
        cmo.setNumberOfFilesLimited(true)
        cmo.setFileMinSize(int(SMinsize))
        cmo.setLogFileRotationDir(domainpath+domainname+'/RotationDir +S')

def printline(): print '#'*50

def main():
        printline(); print 'Starting domain logs Configurations '; printline()
        connectToAdmin()
        editMode()
        domainlog_rotation(domainname,FC,MinSize)
        printline(); print 'Starting Server logs configurations' ; printline()
        cd('/')
        for server_name in ls('Servers',returnMap='true'):
                if server_name == 'AdminServer':
                        ServerLogRotation(server_name,ASFC,ASMinsize)
                else:
                        ServerLogRotation(server_name,MSFC,MSMinsize)
        saveActivate()
        exitDisconnect()

main()

Please double check all indentation blocks.
The properties file used for sample tests is as follows:

#WebLogic console connection parameters
username=weblogic
password=welcome1
url=t3://192.168.33.102:8001
domainname=demo_domain

# Domain logger configurations
FC=4
MinSize=5
domainpath=/u01/oracle/domains/

# ManagedServer logger configurations
MSFC=3
MSMinsize=2

# AdminServer logger configurations
ASFC=5


Sample execution output as follows:
WebLogic Logger enabled and configuration using WLST scrpt execution.

Popular Posts