Templates can be customized further by providing a TemplateOpts
object instead of a string:
const myTemplate = {
template: "%#name% -",
utc: true,
hours: 24
} satisfies TemplateOpts;
template
: The Prefix Template string
utc
: Whether to use UTC (true
) or local timezone (false
) with this template. Defaults tofalse
hours
: Whether to use12
or24
hour notation with this template. Defaults to24
.
Note: When using a TemplateOpts
object in Log Level options as an override the default values will be taken from the Logger's default template!
The templating system uses variables surronded by %
characters.
Optionally #
characters may be used before and after the variable name to indicate padding direction (%#left%
. %#centered#%
, %right#%
). Some numerical values may support left-aligned padding by adding leading zeroes such as %#hour%
(example: 06
).
When used in Log Level Prefix Templates the %Name%
variable is available to print the name of the Log Level in the Prefix. Padding in all directions is supported, additionaly the name can be transformed to all lowercase (%name%
) or all uppercase (%NAME%
) letters.
Time is determined when the template is used. The following variables are available:
Variable | Description | Padding/Capitalization |
---|---|---|
"%year%" |
Current year | %#year% padded to 4 digits |
"%month%" |
Current month as number | %#month% padded to 2 digits |
"%date%" |
Current day of month as number | "%#date%" paddded to 2 digits |
"%hour%" |
Current hour Aliases:
|
"%#hour%" padded to 2 digits |
"%min%" |
Current minute Aliases:
|
"%#min%" padded to 2 digits |
"%sec%" |
Current second Aliases:
|
"%#sec%" padded to 2 digits |
"%ms%" |
Current millisecond Aliases:
|
%#ms% padded to 3 digits |
"%day%" |
Current weekday as string such as "Wed" |
|
"%month_short%" |
Current month as string such as "Dec" |
|
"%month_long%" |
Current month as string such as "December" Aliases:
|
|
"%date_ord%": |
Current day of the month as string such as "25th" |
|
"%iso%" |
Current iso date as string such as "2024-12-25" Aliases:
|
|
"%iso_full%" |
Full ISO string such as "2024-12-25T18:06:12.889Z" Aliases:
|
|
"%time%" |
Alias of"%#hour%:%#min%:%#sec" |
|
"%ampm%" |
Current day period (i.e."am" or "pm" ).Can be capitalized by using "%AMPM%" |