Use below snippet. I have added comments for each step.
Update the first two lines - serverName and chainName as per your environment before running this.
serverName = 'server1'
chainName = 'Chain'
#update this variable to true/false to toggle logging on/off
loggingEnabled = 'true'
#Get the server id
serverId = AdminConfig.getid('/Server:%s' %(serverName))
#Get the list of all Web Container transport chains
wcTransportChains = AdminTask.listChains(AdminConfig.list("TransportChannelService", serverId), '[-acceptorFilter WebContainerInboundChannel]').splitlines()
#Iterate the list and find the chain we are interested in
for chain in wcTransportChains:
if chain.startswith(chainName):
#list all transport channles for this chain
transportChannels = AdminConfig.showAttribute(chain, 'transportChannels').split(" ")
#iterate the list and find HTTPInboundChannel to enable NCSA logging
for channel in transportChannels:
if channel.find('HTTPInboundChannel') != -1:
#Enable logging config
print ('\nEnabling NCSA logging for Transport Channel : %s on server : %s\n' %(AdminConfig.showAttribute(channel, 'name'), serverName))
AdminConfig.modify(channel, [['enableLogging', loggingEnabled]])
#end if
#end for
#end if
#end for
#save the changes
AdminConfig.save()