# Set the facility field

It is possible to set the `facility` field with the `set-facility()` rewrite function. When set, the `set-facility()` rewrite function will only rewrite the `${FACILITY}` field in the message to the first parameter value specified in the function.

Note If the parameter value is not a valid parameter value, the function ignores it and sends a debug message, but the application still sends the message. 

FilterX has no `set_facility()` counterpart. See the related [`set_pri()`](../../../docs/axosyslog-core/4.26/filterx/function-reference/index.md#set-pri) function, which sets the combined PRI value (`facility * 8 + severity`), so you cannot set the facility without also setting the severity.

## Declaration

Terminal window
```
    log {
        source { system(); };
        if (program("postfix")) {
          rewrite { set-facility("mail"); };
        };
        destination { file("/var/log/mail.log"); };
        flags(flow-control);
    };
```

## Parameters

The `set-facility()` rewrite function has a single, mandatory parameter that can be defined as follows:

Terminal window
```
    set-facility( "parameter1" );
```

## Accepted values

The `set-facility()` rewrite function accepts the following numeric strings and named values:

Numerical Code | Facility name | Facility  
---|---|---  
0 | kern | kernel messages  
1 | user | user-level messages  
2 | mail | mail system  
3 | daemon | system daemons  
4 | auth | security/authorization messages  
5 | syslog | messages generated internally by syslogd  
6 | lpr | line printer subsystem  
7 | news | network news subsystem  
8 | uucp | UUCP subsystem  
9 | cron | clock daemon  
10 | authpriv | security/authorization messages  
11 | ftp | FTP daemon  
12 | ntp | NTP subsystem  
13 | security | log audit  
14 | console | log alert  
15 | solaris-cron | clock daemon  
16-23 | local0..local7 | locally used facilities (local0-local7)  
  
## Example usage for the set-facility() rewrite function

The following two `set-facility()` examples are equivalent:

Terminal window
```
    rewrite {
      set-facility("security");
      set-facility("13");
      };
```

## Options

The `set-facility()` rewrite rule has the following option.

## condition()

|   
---|---  
Type: | filter expression  
Default: | N/A  
  
_Description:_ Applies the rewrite rule only to the messages that match the specified filter expression. Messages that don’t match the filter pass through the rule unmodified, and continue to the next element of the log path. You can use any filter expression here, and you can reference an existing filter with the `filter()` function. For details, see [Conditional rewrites](../../../docs/axosyslog-core/4.26/chapter-manipulating-messages/modifying-messages/conditional-rewrite/index.md).

Last modified August 10, 2026: [Sync rewrite rule options with the source (d33662b7)](<https://github.com/axoflow/axosyslog-core-docs/commit/d33662b7e6212a930666d724aa0ba2f88d4ba4ae>)