Creating and Using Appenders in a SAS Program

Creating Appenders

You create appenders in your SAS program or in the logging configuration file 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=myfile");
      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 that are created in a DATA step 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 either in the logging configuration file or in a SAS program. 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: