# Set message fields to specific values

To set a field of the message to a specific value, you have to:

  * define the string to include in the message, and
  * select the field where it should be included.
  * You can set the type of the field. Where you can use of templates in `set()` and `groupset()`, you can use type-casting, and the type information is properly promoted. For details, see [Specifying data types in value-pairs](../../../docs/axosyslog-core/chapter-concepts/concepts-value-pairs/specifying-data-types/index.md).




You can set the value of available macros, for example, HOST, MESSAGE, PROGRAM, or any user-defined macros created using parsers (for details, see [parser: Parse and segment structured messages](../../../docs/axosyslog-core/chapter-parsers/index.md) and [db-parser: Process message content with a pattern database (patterndb)](../../../docs/axosyslog-core/chapter-parsers/chapter-patterndb/index.md)). Note that the rewrite operation completely replaces any previous value of that field.

Note Hard macros cannot be modified. For details, see [Hard versus soft macros](../../../docs/axosyslog-core/chapter-manipulating-messages/customizing-message-format/macros-hard-vs-soft/index.md). 

Use the following syntax:

## Declaration
```
       rewrite <name_of_the_rule> {
            set("<string to include>", value(<field name>));
        };
    
```

## Example: Set message fields to a particular value

The following example sets the HOST field of the message to `myhost`.
```
 
       rewrite r_rewrite_set{
            set("myhost", value("HOST"));
        };
    
```

The following example appends the “suffix” string to the MESSAGE field:
```
 
       rewrite r_rewrite_set{
            set("$MESSAGE suffix", value("MESSAGE"));
        };
    
```

For details on rewriting SDATA fields, see [Create custom SDATA fields](../../../docs/axosyslog-core/chapter-manipulating-messages/modifying-messages/custom-sdata-fields/index.md).

You can also use the following options in rewrite rules that use the `set()` operator.
```
 
       rewrite <name_of_the_rule> {
            set("<string to include>", value(<field name>), on-error("fallback-to-string");
        };
    
```

Note The `severity` and `facility` fields can only be set by the `set-severity()` rewrite functions. For more information, see [Set the severity field](../../../docs/axosyslog-core/chapter-manipulating-messages/modifying-messages/rewrite-set-severity/index.md). 

Last modified April 9, 2025: [Rewrite-related formatting fixes and title shortenings (07c928a3)](<https://github.com/axoflow/axosyslog-core-docs/commit/07c928a36247e7d98c8d00726187c3afdbc96875>)