It is a common requirement at customers to redirect WebLogic server log and stdout files to a central directory other than the default location under the logs directory of a WebLogic server. The obvious advantages are log files are separated from WebLogic domain configuration files, which leave the domain less likely being corrupted by human errors. This becomes more obvious when an environment have more than one WebLogic domains.
To achieve this, first of all, determine a common root directory structure, under which server log and stdout files are redirected to. For example /u01/app/oracle/logs. In the case of multiple WebLogic domains, a subdirectory for each domain can be created under this common directory. Secondly, log configurations on each WebLogic domain are updated to use this common log directory. These configuration changes can be made either manually from the WebLogic Console and EM Console or using WebLogic WLST scripts.
The manual approach
1) Inside WebLogic Console, update the Log file name property under the Logging > General section of each WebLogic server. Set the Log file name to [COMMON_LOG_DIR]/[DOMAIN_NAME]/[SERVER_NAME].log. For example:
/u01/oracle/logs/iptSOAdomain01/soa_server1.log
2) Inside WebLogic Console, update the Server Start > Arguments section to add the below arguments to overwrite the deafult WebLogic Stdout, Stderr files location.
-Dweblogic.Stdout=[COMMON_LOG_DIR]/[DOMAIN_NAME]/[SERVER_NAME].out
-Dweblogic.Stderr=[COMMON_LOG_DIR]/[DOMAIN_NAME]/[SERVER_NAME]_err.out
For example:
-Dweblogic.Stdout=/u01/app/oracle/logs/iptSOAdomain01/soa_server1.out
-Dweblogic.Stderr=/u01/app/oracle/logs/iptSOAdomain01/soa_server1_err.out
3) In FMW Console, update the Log Files > Log Path property for each of the FMW log handlers to redirect the diagnostics files as needed to the new location
This configuration is made within the EM console of a WebLogic domain. To update this configuration, navigate to /[FMW_HOME]/[DOMAIN_NAME]/[SERVER_NAME] > Log Configuration > Log Files section of each WebLogic server. Update the Log Path of a log handler with the new location for the diagnostic log files as below.
[COMMON_LOG_DIR]/[DOMAIN_NAME]/{weblogic.Name}-diagnostic.log
For example:
/u01/app/oracle/logs/iptSOAdomain01/soa_server1-diagnostic.log
After making the above configuration changes, restart the WebLogic AdminServer and the managed servers on which the configurations were updated so that all WebLogic server logs, stdout, stderr and diagnostics logs information are redirected to the new central location.
The scripting approach
Almost all WebLogic tasks that are performed in WebLogic admin Console or EM console can also be achieved using WebLogic WSLT scripts. Below scripts can be used to make the configuration changes to redirect WebLogic server log file, stdout, stderr and diagnostics files to a different location than the default.
# This script is used to redirect WebLogic log, diagnostic and out files from the default locations to a central custom directory
domain=raw_input(“domain name:”)
adminHost=raw_input(“admin host:”)
adminPort=raw_input(“admin port:”)
adminUser=raw_input(“admin user:”)
adminPassword=raw_input(“admin password:”);
# The new log location
logPath=”/u01/app/oracle/logs/” + domain + “/”
connect(adminUser, adminPassword, “t3://” + adminHost + “:” + adminPort);
domainConfig()
servers = cmo.getServers()
edit()
startEdit()
cd(‘/Log/’ + domain)
cmo.setFileName(logPath + domain + ‘.log’)
save()
for server in servers:
sName = server.getName()
cd(‘/Servers/’ + sName + ‘/Log/’ + sName
cmo.setFileName(logPath + sName + ‘.log’)
cd(‘/Servers/’ + sName + ‘/ServerStart/’ + sName)
cmo.setArguments(cmo.getArguments() + ‘ -Dweblogic.Stdout=’ + logPath + sName + ‘.out’ + ‘ -Dweblogic.Stderr=’ + logPath + sName + ‘_err.out ‘)
configureLogHandler(target=sName, name=’odl-handler’, path=logPath + sName + ‘-diagnostic.log’)
save()
activate()
## End of wlst/python code