Friday, April 05, 2013

Switching Back to Regular Listener Log Format

Did you ever miss the older listener log file format and want to turn off the ADR-style log introduced in 11g? Well, it's really very simple.


Oracle introduced the Automatic Diagnostic Repository (ADR) with Oracle 11g Release 1. This introduced some type of streamlining of various log and trace files generated by different Oracle components such as the database, listener, ASM, etc. this is why you didn't find the alert log in the usual location specified by the familiar background_dump_dest initialization parameter but in a directory specified by a diferent parameter - ADR_BASE. Similarly listener logs now go in this format:
Remember, this is in the XML format; not the usual listener.log. The idea was to present the information in the listener log in a consistent, machine readable format instead of the usually cryptic inconsistent older listener log format. Here is an example of the new format:
<msg  time='2013-03-31T13:17:22.633-04:00' org_id='oracle' comp_id='tnslsnr'
  type='UNKNOWN' level='16' host_id='oradba2'
  host_addr='' version='1'
  <txt>31-MAR-2013 13:17:22 * service_update * D112D2 * 0</txt>
<msg> time='2013-03-31T13:17:25.317-04:00' org_id='oracle' comp_id='tnslsnr'
 type='UNKNOWN' level='16' host_id='oradba2'
 <txt>WARNING: Subscription for node down event still pending </txt>
Being in XML format, many tools now can be made to read the files unambiguously since the data is now enclosed within meaningful tags. Additionally the listener log files (the XML format) is now rotated. After reaching a certain threshold value the file is renamed to log_1.xml and a new log.xml is created - somewhat akin to the archived log concept in the case of redo log files.
While it proved useful for new tools, there was also the presence of myriads of tools that read the older log format perfectly. So Oracle didn't stop the practice of writing to the old format log. The old format log was still called listener.log but the directory it is created in is different - $ADR_BASE/tnslsnr/Hostname/listener/trace. Unfortunately there is no archiving scheme for this file so this simply kept growing.
In the pre-11g days you could temporarily redirect the log to a different location and archive the old one by setting the following parameter in listener.ora:
log_directory = tempLocation
However, in Oracle 11g R1 and beyond, this will not work; you can't set the location of the log_directory.


So, what's the solution? Simple. Just set the following parameter in listener.ora:
diag_adr_enabled_listener = off
This will disable the ADR style logging for the listener. Now, suppose you want to set the directory to /tmp and log file name to listener_0405.log, add the following into listener.ora (assuming the name of the listener is "listener"; otherwise make the necessary change below):
log_file_listener = listener_0405.log
log_directory_listener = /tmp
That's it. the ADR style logging will be permanently be gone and you will be reunited with your highly missed pre-11g style logging. You can confirm it:
LSNRCTL> status
Connecting to (ADDRESS=(PROTOCOL=tcp)(HOST=)(PORT=1521))
Alias                     listener
Version                   TNSLSNR for Linux: Version - Production
Start Date                26-NOV-2012 16:50:58
Uptime                    129 days 15 hr. 33 min. 31 sec
Trace Level               off
Security                  ON: Local OS Authentication
SNMP                      OFF
Listener Parameter File   /opt/oracle/product/11.2.0/grid/network/admin/listener.ora
Listener Log File         /tmp/listener_0405.log
Listening Endpoints Summary...

Services Summary...

Service "+ASM" has 1 instance(s).

... output truncated ...
Happy logging.

P.S. By the way, you can also change the values by issuing set commands from LSNRCTL command prompt:
LSNRCTL> set log_file '/tmp'
However, if you have heeded my advice earlier, you might have set admin_restrictions to ON; so can't use the set command. Instead, you would put the value in listener.ora and reload the listener for the desired effect.


Anonymous said...

Hi Arup

I think that in addition to the *.xml log Oracle also logs usual listener.log in the trace directory. At least this is what I see on most 11.2 installs.

Arup Nanda said...

@Timur - yes, it does; and I have mentioned it in the blog too. However this log simply keeps growing. In pre-11g days you could temporarily change the log_file name or directory to create a new one and archive the old one. In 11g, you can't change the file name or the directory unless you set this special parameter.

Anonymous said...

Hi Arup

The log-rotation I'm doing for 11g R2 is no different than with previous versions.

Just do this:
mv /listener.log

The only difference in 11gR2 was to determine where this logfile is. Since

lsnrctl STATUS

will give you the default logfile (which is the log.xml in 11gR2) just grep for this line, and replace "alert/log.xml" witch "trace/listener.log"

So something like this (untested, don't have my script here):

lsnrctl status | grep "Listener Log File" | awk '{print $4}' | sed 's/alert\/log.xml/trace\/listener.log/

This can be done for all listeners (TRACE and normal).

Arup Nanda said...

@Anonymous I think you missed the spirit of this post. You are not doing a log rotation; you are pausing and restarting at a new location. The entries between your log_status off and log_status on will be on no listener log file.

A true log rotation simply starts a new logfile. In pre-11g days we used to do that by using:

LSNRCTL> set log_file_listener

With ADR enabled in 11g, you will get this error:

LSNRCTL> set log_file mylog.xml
TNS-01251: Cannot set trace/log directory under ADR
LSNRCTL> set log_directory /tmp
TNS-01251: Cannot set trace/log directory under ADR

This is where disabling ADR helps, and what this post describes.

Hope this helps.

Tara Tyler said...

This is cool!
I like your post,visit my homepage here:
best memory foam mattress 2013