The SAS Logging Facility in the SAS Language |
Creating Appenders |
You create appenders in your SAS program before you define loggers or before you invoke a log event. The only appender class that you can create is FileRefAppender, which specifies to write messages to a file that is referenced by a fileref.
Although appenders can be created at any time in a SAS program, it is a good programming practice to create a named appender only once. In order to prevent the DATA step from processing the creation of the same appender in each iteration of the implicit loop, you can create an appender in only the first iteration of the implicit loop by using an IF-THEN statement:
if _n_ = 1 then do; rc=log4sas_appender("myAppenderName", "FileRefAppender", "fileref=myfiles"); if rc ne 0 then do msg = sysmsg(); put msg; ABORT; end; end;
When you create an appender, you specify the appender name, the keyword FileRefAppender, and appender options. You use appender options to specify a fileref that references a log file, a conversion pattern to format the message, and the appender message threshold. The appender THRESHOLD argument enables appender-level log event message filtering at the appender level. The filtering occurs after the logging facility processes logger-level message filtering.
The appender name is case sensitive. Be sure to specify the appender name exactly as it is specified in the respective appender syntax.
An appender that is created by using an autocall macro is defined to SAS for the duration of the SAS program. An appender that is created in a DATA step exists only for the duration of the DATA step. After the DATA step or SAS program is complete, appenders are no longer defined to SAS.
For details, see the following language elements that create appenders in the SAS language:
Associating Appenders with Loggers |
After an appender is defined to SAS, you can associate one or more appenders with a logger. All logger language elements have an APPENDER-REF argument whose value must be one or more appender names that are defined to SAS. When a log event is invoked, the message is written to all destinations that are associated with the logger.
For details about the logger APPENDER-REF argument, see the following logger language elements:
Copyright © 2010 by SAS Institute Inc., Cary, NC, USA. All rights reserved.