Keyboard shortcuts

Press or to navigate between chapters

Press S or / to search in the book

Press ? to show this help

Press Esc to hide this help

Template String Formatting Guide

Overview

Logly supports custom format strings with placeholders for complete control over log output.

Built-in Placeholders

  • {time} - Timestamp (RFC3339 format)
  • {time:PATTERN} - Custom time format
  • {level} - Log level name
  • {message} - Log message
  • {module} - Module name
  • {function} - Function name
  • {filename} - Source filename
  • {lineno} - Line number
  • {FIELD} - Any custom field

Time Format Patterns

Supported Patterns

PatternDescriptionExample
YYYY4-digit year2025
YY2-digit year25
MMMMFull month nameOctober
MMMAbbreviated monthOct
MM2-digit month10
ddddFull weekday nameSaturday
dddAbbreviated weekdaySat
DD2-digit day11
HH2-digit hour (24h)13
hh2-digit hour (12h)01
mm2-digit minute45
ss2-digit second32
SSSMilliseconds123
SSSSSSMicroseconds123456
AAM/PMAM
aam/pmam
ZZTimezone (+00:00)+00:00
ZTimezone (+0000)+0000

Examples

Date Only

#![allow(unused)]
fn main() {
SinkConfig {
    format: Some("{time:YYYY-MM-DD} | {level} | {message}".to_string()),
    ..Default::default()
}
// Output: 2025-10-11 | INFO | Message
}

Full DateTime

#![allow(unused)]
fn main() {
SinkConfig {
    format: Some("{time:YYYY-MM-DD HH:mm:ss} [{level}] {message}".to_string()),
    ..Default::default()
}
// Output: 2025-10-11 13:45:32 [INFO] Message
}

With Milliseconds

#![allow(unused)]
fn main() {
SinkConfig {
    format: Some("{time:HH:mm:ss.SSS} | {message}".to_string()),
    ..Default::default()
}
// Output: 13:45:32.123 | Message
}

ISO 8601 Style

#![allow(unused)]
fn main() {
SinkConfig {
    format: Some("{time:YYYY-MM-DDTHH:mm:ss} {level} {message}".to_string()),
    ..Default::default()
}
// Output: 2025-10-11T13:45:32 INFO Message
}

Readable Format

#![allow(unused)]
fn main() {
SinkConfig {
    format: Some("{time:dddd, DD MMMM YYYY at HH:mm:ss} - {level} - {message}".to_string()),
    ..Default::default()
}
// Output: Saturday, 11 October 2025 at 13:45:32 - INFO - Message
}

European Format

#![allow(unused)]
fn main() {
SinkConfig {
    format: Some("{time:DD/MM/YYYY HH:mm} {message}".to_string()),
    ..Default::default()
}
// Output: 11/10/2025 13:45 Message
}

Common Patterns

Simple Console

#![allow(unused)]
fn main() {
format: Some("{time:HH:mm:ss} [{level}] {message}".to_string())
}

Detailed File

#![allow(unused)]
fn main() {
format: Some("{time:YYYY-MM-DD HH:mm:ss.SSS} | {level:8} | {module}:{function} | {message}".to_string())
}

Request Logging

#![allow(unused)]
fn main() {
format: Some("{time:YYYY-MM-DD HH:mm:ss} | {method} {path} | status={status_code} | duration={duration_ms}ms".to_string())
}

Best Practices

  1. Console vs File: Use simpler formats for console, detailed for files
  2. Time Formats:
    • HH:mm:ss for console (quick reference)
    • YYYY-MM-DD HH:mm:ss.SSS for logs (precise timestamps)
    • YYYY-MM-DDTHH:mm:ss for ISO 8601 compatibility
  3. Performance: Simpler formats are faster to process
  4. Consistency: Use consistent formats across your application