WLST script for updating the log settings for domains and servers

Peter Lorenzen
11/07-2011

The script has been tested on Weblogic 9.2 MP1 and 10.3.5.

#
# Needed for older Phyton versions
True=1
False=0

###############################################################################
# Logging parameters begin
###############################################################################
loggingEnabled=True

rotationType='bySize'
#rotationType='byTime'
#rotationType='none'

logFileSeverity='Info'

fileMinSize=500

rotationTime='00:00'
fileTimeSpan=24
numberOfFilesLimited=True
fileCount=7
rotateLogOnStartup=False
logFileRotationDir=''
###############################################################################
# Logging parameters end
###############################################################################

def editBegin():
  edit()
  startEdit()

def editEnd():
  save()
  activate(block="true")

def updateLog(logMB,logType):
  print '<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<'
  print '< Update Log setting ('+logMB.getName()+')'
  print '<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<'
  print ''
  if logType == 'ACCESS':
    print ' setLoggingEnabled (' + str(loggingEnabled) + ')'
    logMB.setLoggingEnabled(loggingEnabled)
    fileName='logs/'+logMB.getName()+'_access.log'
  else:
    fileName='logs/'+logMB.getName()+'.log'
  print ' setFileName (' + fileName + ')'
  logMB.setFileName(fileName)
  print ' setRotationType (' + rotationType + ')'
  logMB.setRotationType(rotationType)
  if logType == 'DOMAIN':
    print ' setLogFileSeverity (' + logFileSeverity + ')'
    logMB.setLogFileSeverity(logFileSeverity)
  print ' setFileMinSize (' + str(fileMinSize) + ')'
  logMB.setFileMinSize(fileMinSize)
  print ' setRotationTime (' + str(rotationTime) + ')'
  logMB.setRotationTime(rotationTime)
  print ' setFileTimeSpan (' + str(fileTimeSpan) + ')'
  logMB.setFileTimeSpan(fileTimeSpan)
  print ' setNumberOfFilesLimited (' + str(numberOfFilesLimited) + ')'
  logMB.setNumberOfFilesLimited(numberOfFilesLimited)
  print ' setFileCount (' + str(fileCount) + ')'
  logMB.setFileCount(fileCount)
  print ' setRotateLogOnStartup (' + str(rotateLogOnStartup) + ')'
  logMB.setRotateLogOnStartup(rotateLogOnStartup)
  print ' setLogFileRotationDir (' + logFileRotationDir + ')'
  logMB.setLogFileRotationDir(logFileRotationDir)
  print ''

connect(username='myuser',password='mypasswd',url='t3://127.0.0.1:7001')

domainConfig()

editBegin()
logMB=getMBean('/Log/'+cmo.getName())
updateLog(logMB,logType='DOMAIN')
editEnd()

servers=cmo.getServers()

editBegin()
for server in servers:
  serverName=server.getName()
  logMB=getMBean('/Servers/'+serverName+'/Log/'+serverName)
  updateLog(logMB,logType='SERVER')
  httpLogMB=getMBean('/Servers/'+serverName+'/WebServer/'+serverName+'/WebServerLog/'+serverName)
  updateLog(httpLogMB,logType='ACCESS')

editEnd()
disconnect()
exit()

{ 1 comment… read it below or add one }

eMarcel February 16, 2016 at 11:46

Clean and working script! Thanks for sharing!

Leave a Comment

Previous post:

Next post: