Skip to content

Commit f020ba8

Browse files
authored
Enhance $(padding) template function documentation
Updated the syntax and description for the $(padding) template function in syslog-ng documentation. Added examples for left and right padding with different characters and strings. Signed-off-by: Hofi <hofione@gmail.com>
1 parent d5610fa commit f020ba8

1 file changed

Lines changed: 51 additions & 13 deletions

File tree

doc/_admin-guide/110_Template_and_rewrite/000_Customize_message_format/007_Template_functions_of_syslog-ng.md

Lines changed: 51 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -854,31 +854,69 @@ argument.
854854

855855
## $(padding)
856856

857-
| *Syntax:* | $(padding \<macro\> \<width\> \<prepended-character-or-string\>) |
857+
| *Syntax:* | $(padding \<macro\> \<width\> [\<padding-character-or-string\>]) |
858858

859859
*Description:* This template function returns the value of its first
860-
parameter (a string or macro), prepended with a string. This string is
861-
\<width\> long, and repeats the character or string set in the third
862-
parameter. If you use a single character, it is added \<width\> times.
863-
If you use a string, it is repeated until its length reaches \<width\>.
864-
The default padding character is \' \' (space). For example:
860+
parameter (a string or macro), padded to the specified width. From version 4.12 of
861+
{{ site.product.short_name }}, the padding direction depends on the sign of the \<width\> parameter:
865862

866-
### Example: Using the padding template function
863+
- **Positive width**: Left-padding. The padding is added before (to the left of) the string.
864+
- **Negative width**: Right-padding. The padding is added after (to the right of) the string.
867865

868-
If the value of the ${MESSAGE} macro is mymessage, then the output of
869-
the padding() template function is the following:
866+
The absolute value of \<width\> determines the total length of the output. If the
867+
input string is longer than the specified width, it is returned unchanged (not truncated).
868+
869+
The optional third parameter specifies the padding character or string. If you use a
870+
single character, it is repeated to fill the padding. If you use a string, it is
871+
repeated until the padding reaches the required length. The default padding character
872+
is ` ` (space).
873+
874+
**NOTE:** The width parameter cannot be zero.
875+
{: .notice--info}
876+
877+
### padding usage examples
878+
879+
If the value of the ${MESSAGE} macro is mymessage:
880+
881+
**Left-padding with spaces (default):**
882+
883+
```config
884+
$(padding ${MESSAGE} 15)
885+
```
886+
887+
Output: ` mymessage` (6 spaces + mymessage = 15 characters total)
888+
889+
**Left-padding with a character:**
870890

871891
```config
872-
$(padding ${MESSAGE} 10 X)
892+
$(padding ${MESSAGE} 15 X)
873893
```
874894

875-
Output: XXXXXXXXXXmymessage
895+
Output: `XXXXXXmymessage` (6 X's + mymessage = 15 characters total)
896+
897+
**Left-padding with a string:**
898+
899+
```config
900+
$(padding ${MESSAGE} 16 foo)
901+
```
902+
903+
Output: `foofoofmymessage` (repeats "foo" until reaching 16 characters total)
904+
905+
**Right-padding with spaces:**
906+
907+
```config
908+
$(padding ${MESSAGE} -15)
909+
```
910+
911+
Output: `mymessage ` (mymessage + 6 spaces = 15 characters total)
912+
913+
**Right-padding with a character:**
876914

877915
```config
878-
$(padding ${MESSAGE} 10 foo)
916+
$(padding ${MESSAGE} -15 X)
879917
```
880918

881-
Output: foofoofoofmymessage
919+
Output: `mymessageXXXXXX` (mymessage + 6 X's = 15 characters total)
882920

883921
## $(python)
884922

0 commit comments

Comments
 (0)