Search This Blog

Friday, September 01, 2017

How to set loggers in SOA/OSB using WLST

How to set loggers in SOA/OSB using WLST
Change the following lines in the script with your variables

## change username , password and AdminServer URL
username ='weblogic'
password = 'Welcome1'
url='t3://localhost:7001'
## Change this String with the list of the loggers you want
loggers_list = ['oracle.as.scheduler', 'oracle.as.scheduler.metedata' ,'oracle.as.ess']
## Change this String with the list of the servers you want to set the loggers
servers_list = ['AdminServer', 'soa_server1']


1. Script For setting runtime logger to TRACE:32


+++ Script For setting runtime logger to TRACE:32  +++



def setRuntimerLogger(serverName,loggerName,loggerLevel):
    Mbean1 = ObjectName('oracle.logging:Location='+serverName +',name='+serverName+',type=LogRuntime')

    mbs.invoke(Mbean1,'setLoggerLevel',[loggerName,loggerLevel], ["java.lang.String","java.lang.String"])


def setPersistentLogger(serverName,loggerName,loggerLevel):
    Mbean2 =  ObjectName("oracle.logging:type=LogConfig,ServerName=" + serverName)

    mbs.invoke(Mbean2,'setLoggerLevel',[loggerName,loggerLevel], ["java.lang.String","java.lang.String"])


def printPersistentlogeer(serverName,loggerName):

    Mbean1 = ObjectName("oracle.logging:type=LogConfig,ServerName=" + serverName)


    l2 =  mbs.invoke(Mbean1,'getLoggerLevel',[loggerName], ["java.lang.String"])
    if l2 == None:
        print serverName +  ' --> Logging Level for : ' + loggerName + ' --> None'
    else:
        print  serverName +  ' --> Logging Level for : ' + loggerName + ' --> ' +l2


def printRuntimelogeer(serverName,loggerName):

    Mbean1 = ObjectName('oracle.logging:Location='+serverName +',name='+serverName+',type=LogRuntime')


    l2 =  mbs.invoke(Mbean1,'getLoggerLevel',[loggerName], ["java.lang.String"])
    if l2 == None:
        print serverName +  ' --> Logging Level for : ' + loggerName + ' --> None'
    else:
        print  serverName +  ' --> Logging Level for : ' + loggerName + ' --> ' +l2


if __name__ == '__main__':
    from wlstModule import *#@UnusedWildImport

print 'Starting the script to set the loggers ....'

# Change these properties as per your environment

username = 'weblogic'
password = 'Welcome1'
url='t3://localhost:7001'


## Change this String with the list of the loggers you want

loggers_list = ['oracle.as.scheduler', 'oracle.as.scheduler.metedata' ,'oracle.as.ess']

## Change this String with the list of the servers you want to set the loggers

servers_list = ['AdminServer', 'soa_server1']

trace_32 = 'TRACE:32'
notification_1 = 'NOTIFICATION:1'

connect(username,password,url)
servers = cmo.getServers()
domainRuntime()

# for setting the runtime loggers

for logeerlist in loggers_list:
    for serverlist in servers_list:
        print 'Setting loggers for ' + serverlist +'  --> ' + logeerlist
        setRuntimerLogger(serverlist,logeerlist,"TRACE:32")
        printRuntimelogeer(serverlist,logeerlist)





print 'End of the script'




+++ Script Ends ++++   


2. Script For setting runtime logger to NOTIFICATION:1 (For disabling the loggers you have set previously) 

+++ Script For setting runtime logger to NOTIFICATION:1 (For disabling the loggers you have set previously)  +++



def setRuntimerLogger(serverName,loggerName,loggerLevel):
    Mbean1 = ObjectName('oracle.logging:Location='+serverName +',name='+serverName+',type=LogRuntime')

    mbs.invoke(Mbean1,'setLoggerLevel',[loggerName,loggerLevel], ["java.lang.String","java.lang.String"])


def setPersistentLogger(serverName,loggerName,loggerLevel):
    Mbean2 =  ObjectName("oracle.logging:type=LogConfig,ServerName=" + serverName)

    mbs.invoke(Mbean2,'setLoggerLevel',[loggerName,loggerLevel], ["java.lang.String","java.lang.String"])


def printPersistentlogeer(serverName,loggerName):

    Mbean1 = ObjectName("oracle.logging:type=LogConfig,ServerName=" + serverName)


    l2 =  mbs.invoke(Mbean1,'getLoggerLevel',[loggerName], ["java.lang.String"])
    if l2 == None:
        print serverName +  ' --> Logging Level for : ' + loggerName + ' --> None'
    else:
        print  serverName +  ' --> Logging Level for : ' + loggerName + ' --> ' +l2


def printRuntimelogeer(serverName,loggerName):

    Mbean1 = ObjectName('oracle.logging:Location='+serverName +',name='+serverName+',type=LogRuntime')


    l2 =  mbs.invoke(Mbean1,'getLoggerLevel',[loggerName], ["java.lang.String"])
    if l2 == None:
        print serverName +  ' --> Logging Level for : ' + loggerName + ' --> None'
    else:
        print  serverName +  ' --> Logging Level for : ' + loggerName + ' --> ' +l2


if __name__ == '__main__':
    from wlstModule import *#@UnusedWildImport

print 'Starting the script to set the loggers ....'

# Change these properties as per your environment

username = 'weblogic'
password = 'Welcome1'
url='t3://localhost:7001'


## Change this String with the list of the loggers you want

loggers_list = ['oracle.as.scheduler', 'oracle.as.scheduler.metedata' ,'oracle.as.ess']

## Change this String with the list of the servers you want to set the loggers

servers_list = ['AdminServer', 'soa_server1']

trace_32 = 'TRACE:32'
notification_1 = 'NOTIFICATION:1'

connect(username,password,url)
servers = cmo.getServers()
domainRuntime()

# for setting the runtime loggers

for logeerlist in loggers_list:
    for serverlist in servers_list:
        print 'Setting loggers for ' + serverlist +'  --> ' + logeerlist
        setRuntimerLogger(serverlist,logeerlist,"NOTIFICATION:1")
        printRuntimelogeer(serverlist,logeerlist)

print 'End of the script'


+++ Script Ends ++++   

3. Script For setting Persistent logger to TRACE:32

+++ Script For setting Persistent logger to TRACE:32  +++

def setRuntimerLogger(serverName,loggerName,loggerLevel):
    Mbean1 = ObjectName('oracle.logging:Location='+serverName +',name='+serverName+',type=LogRuntime')

    mbs.invoke(Mbean1,'setLoggerLevel',[loggerName,loggerLevel], ["java.lang.String","java.lang.String"])


def setPersistentLogger(serverName,loggerName,loggerLevel):
    Mbean2 =  ObjectName("oracle.logging:type=LogConfig,ServerName=" + serverName)

    mbs.invoke(Mbean2,'setLoggerLevel',[loggerName,loggerLevel], ["java.lang.String","java.lang.String"])


def printPersistentlogeer(serverName,loggerName):

    Mbean1 = ObjectName("oracle.logging:type=LogConfig,ServerName=" + serverName)


    l2 =  mbs.invoke(Mbean1,'getLoggerLevel',[loggerName], ["java.lang.String"])
    if l2 == None:
        print serverName +  ' --> Logging Level for : ' + loggerName + ' --> None'
    else:
        print  serverName +  ' --> Logging Level for : ' + loggerName + ' --> ' +l2


def printRuntimelogeer(serverName,loggerName):

    Mbean1 = ObjectName('oracle.logging:Location='+serverName +',name='+serverName+',type=LogRuntime')


    l2 =  mbs.invoke(Mbean1,'getLoggerLevel',[loggerName], ["java.lang.String"])
    if l2 == None:
        print serverName +  ' --> Logging Level for : ' + loggerName + ' --> None'
    else:
        print  serverName +  ' --> Logging Level for : ' + loggerName + ' --> ' +l2


if __name__ == '__main__':
    from wlstModule import *#@UnusedWildImport

print 'Starting the script to set the loggers ....'

# Change these properties as per your environment

username = 'weblogic'
password = 'Welcome1'
url='t3://localhost:7001'


## Change this String with the list of the loggers you want

loggers_list = ['oracle.as.scheduler', 'oracle.as.scheduler.metedata' ,'oracle.as.ess']

## Change this String with the list of the servers you want to set the loggers

servers_list = ['AdminServer', 'soa_server1']

trace_32 = 'TRACE:32'
notification_1 = 'NOTIFICATION:1'

connect(username,password,url)
servers = cmo.getServers()
domainRuntime()

# for setting the runtime loggers

for logeerlist in loggers_list:
    for serverlist in servers_list:
        print 'Setting loggers for ' + serverlist +'  --> ' + logeerlist
        setPersistentLogger(serverlist,logeerlist,"TRACE:32")
        printPersistentlogeer(serverlist,logeerlist)


print 'End of the script'


+++ Script Ends ++++   


4. Script For setting Persistent logger to NOTIFICATION:1 (For disabling the loggers you have set previously) 

+++ Script For setting Persistent logger to NOTIFICATION:1 (For disabling the loggers you have set previously)  +++



def setRuntimerLogger(serverName,loggerName,loggerLevel):
    Mbean1 = ObjectName('oracle.logging:Location='+serverName +',name='+serverName+',type=LogRuntime')

    mbs.invoke(Mbean1,'setLoggerLevel',[loggerName,loggerLevel], ["java.lang.String","java.lang.String"])


def setPersistentLogger(serverName,loggerName,loggerLevel):
    Mbean2 =  ObjectName("oracle.logging:type=LogConfig,ServerName=" + serverName)

    mbs.invoke(Mbean2,'setLoggerLevel',[loggerName,loggerLevel], ["java.lang.String","java.lang.String"])


def printPersistentlogeer(serverName,loggerName):

    Mbean1 = ObjectName("oracle.logging:type=LogConfig,ServerName=" + serverName)


    l2 =  mbs.invoke(Mbean1,'getLoggerLevel',[loggerName], ["java.lang.String"])
    if l2 == None:
        print serverName +  ' --> Logging Level for : ' + loggerName + ' --> None'
    else:
        print  serverName +  ' --> Logging Level for : ' + loggerName + ' --> ' +l2


def printRuntimelogeer(serverName,loggerName):

    Mbean1 = ObjectName('oracle.logging:Location='+serverName +',name='+serverName+',type=LogRuntime')


    l2 =  mbs.invoke(Mbean1,'getLoggerLevel',[loggerName], ["java.lang.String"])
    if l2 == None:
        print serverName +  ' --> Logging Level for : ' + loggerName + ' --> None'
    else:
        print  serverName +  ' --> Logging Level for : ' + loggerName + ' --> ' +l2


if __name__ == '__main__':
    from wlstModule import *#@UnusedWildImport

print 'Starting the script to set the loggers ....'

# Change these properties as per your environment

username = 'weblogic'
password = 'Welcome1'
url='t3://localhost:7001'


## Change this String with the list of the loggers you want

loggers_list = ['oracle.as.scheduler', 'oracle.as.scheduler.metedata' ,'oracle.as.ess']

## Change this String with the list of the servers you want to set the loggers

servers_list = ['AdminServer', 'soa_server1']

trace_32 = 'TRACE:32'
notification_1 = 'NOTIFICATION:1'

connect(username,password,url)
servers = cmo.getServers()
domainRuntime()

# for setting the runtime loggers

for logeerlist in loggers_list:
    for serverlist in servers_list:
        print 'Setting loggers for ' + serverlist +'  --> ' + logeerlist
        setPersistentLogger(serverlist,logeerlist,"NOTIFICATION:1")
        printPersistentlogeer(serverlist,logeerlist)



print 'End of the script'


+++ Script Ends ++++   
   
   

Generic Script contains all four operations

+++ Script Start's ++++
def setRuntimerLogger(serverName,loggerName,loggerLevel):
    Mbean1 = ObjectName('oracle.logging:Location='+serverName +',name='+serverName+',type=LogRuntime')
   
    mbs.invoke(Mbean1,'setLoggerLevel',[loggerName,loggerLevel], ["java.lang.String","java.lang.String"])
def setPersistentLogger(serverName,loggerName,loggerLevel):
    Mbean2 =  ObjectName("oracle.logging:type=LogConfig,ServerName=" + serverName)
    
    mbs.invoke(Mbean2,'setLoggerLevel',[loggerName,loggerLevel], ["java.lang.String","java.lang.String"])
   
def printPersistentlogeer(serverName,loggerName):
   
    Mbean1 = ObjectName("oracle.logging:type=LogConfig,ServerName=" + serverName)
   
   
    l2 =  mbs.invoke(Mbean1,'getLoggerLevel',[loggerName], ["java.lang.String"])
    if l2 == None:
        print serverName +  ' --> Logging Level for : ' + loggerName + ' --> None'
    else:
        print  serverName +  ' --> Logging Level for : ' + loggerName + ' --> ' +l2
   
def printRuntimelogeer(serverName,loggerName):
   
    Mbean1 = ObjectName('oracle.logging:Location='+serverName +',name='+serverName+',type=LogRuntime')
   
   
    l2 =  mbs.invoke(Mbean1,'getLoggerLevel',[loggerName], ["java.lang.String"])
    if l2 == None:
        print serverName +  ' --> Logging Level for : ' + loggerName + ' --> None'
    else:
        print  serverName +  ' --> Logging Level for : ' + loggerName + ' --> ' +l2
   
if __name__ == '__main__':
    from wlstModule import *#@UnusedWildImport
print 'Starting the script to set the loggers ....'
# Change these properties as per your environment
username = 'weblogic'
password = 'Welcome1'
url='t3://localhost:7001'
## Change this String with the list of the loggers you want
loggers_list = ['oracle.as.scheduler', 'oracle.as.scheduler.metedata' ,'oracle.as.ess']
## Change this String with the list of the servers you want to set the loggers
servers_list = ['AdminServer', 'soa_server1']
trace_32 = 'TRACE:32'
notification_1 = 'NOTIFICATION:1'
connect(username,password,url)
servers = cmo.getServers()
domainRuntime()
# for setting the runtime loggers
for logeerlist in loggers_list:
    for serverlist in servers_list:
        print 'Setting loggers for ' + serverlist +'  --> ' + logeerlist
        setRuntimerLogger(serverlist,logeerlist,"TRACE:32")
        printRuntimelogeer(serverlist,logeerlist)
       
"""
# for setting the runtime loggers
for logeerlist in loggers_list:
    for serverlist in servers_list:
        print 'Setting loggers for ' + serverlist +'  --> ' + logeerlist
        setRuntimerLogger(serverlist,logeerlist,"TRACE:32")
        printRuntimelogeer(serverlist,logeerlist)
# for unsetting the runtime loggers you have set in the previos session
for logeerlist in loggers_list:
    for serverlist in servers_list:
        print 'Setting loggers for ' + serverlist +'  --> ' + logeerlist
        setRuntimerLogger(serverlist,logeerlist,"NOTIFICATION:1")
        printRuntimelogeer(serverlist,logeerlist)
# Set Persistent loggers
for logeerlist in loggers_list:
    for serverlist in servers_list:
        print 'Setting loggers for ' + serverlist +'  --> ' + logeerlist
        setPersistentLogger(serverlist,logeerlist,"TRACE:32")
        printPersistentlogeer(serverlist,logeerlist)
       
# for unsetting the previous presistent loggers
for logeerlist in loggers_list:
    for serverlist in servers_list:
        print 'Setting loggers for ' + serverlist +'  --> ' + logeerlist
        setPersistentLogger(serverlist,logeerlist,"NOTIFICATION:1")
        printPersistentlogeer(serverlist,logeerlist)
"""
print 'End of the script'
   
+++ Script End's ++++
   



Tags: Publish
September 02, 2017 at 11:26AM
Open in Evernote

1 comment:

Unknown said...

Hi Ravi, Great post!! Can we connect once over email?

Thanks,
Ramkumar Marneedi