log : Debug Logging Helper
Output debug messages to the trace log during template processing. Useful for debugging data binding and template logic. Does not render any visible content in the PDF.
On this page
Syntax
Parameters
| Parameter | Type | Required | Description |
|---|---|---|---|
message(s) |
String/Expression | Yes | One or more strings or expressions to log (concatenated) |
level |
String | No | Log level: debug, info, warn, error (default: info) |
category |
String | No | Category for filtering log messages (optional) |
Log Levels
| Level | Description | Use Case |
|---|---|---|
debug |
Verbose debugging | Detailed tracing during development |
info |
Informational | General information (default) |
warn |
Warning | Potential issues that don’t stop execution |
error |
Error | Significant problems worth noting |
Examples
Basic Logging
Logging Values
Data:
builder.WithData("model", new {
user = new {
name = "John Doe",
id = 12345
}
});
Log Output:
User: John Doe (ID: 12345)
With Log Level
With Category for Filtering
Logging in Loops
Data:
builder.WithData("model", new {
orders = new[] {
new { orderNumber = "12345", total = 1250.00m },
new { orderNumber = "12346", total = 45.99m },
new { orderNumber = "12347", total = 2100.00m }
}
});
Log Output:
Processing order #12345
High-value order: $1250
Processing order #12346
Processing order #12347
High-value order: $2100
Logging with Expressions
Conditional Debugging
Underlying Implementation
The {{log}} helper compiles to:
<log data-message="{{concatenated expressions}}"
data-level="Verbose|Message|Warning|Error"
data-category="category name" />
The log entry is written to the document’s trace log during databinding and does not produce any visible output in the PDF.
Notes
- Does not render any visible content in the PDF
- Messages are written to the document’s trace log
- Multiple values are automatically concatenated with spaces
- Supports expressions (function calls, property access, etc.)
- Unknown parameters are silently ignored
- Use
WithLogLevel(...)on the builder, orappend-log='true'in the template, to add the log to the document - Collect log output with a
CollectorTraceLogfor unit testing - Category helps filter log messages for specific features
- Log level affects visibility based on trace log configuration
- Useful for debugging complex conditional logic and iterations
Enabling Trace Logging
To see log output, add the log to the end of the document:
await factory.NewDocument()
.WithLayoutFile("template.html")
.WithData("model", model)
.WithLogLevel(PaperworkRequestLogOption.Verbose)
.SaveAsync("output.pdf");
Or collect the entries in code, for example in a unit test:
using Scryber;
using Scryber.Components;
using Scryber.Logging;
using var doc = Document.ParseDocument("template.html");
var collector = new CollectorTraceLog(TraceRecordLevel.Verbose, "Test", autostart: true);
doc.AddTraceLog(collector);
await factory.NewDocument()
.WithLayout(doc)
.WithData("model", model)
.SaveAsync("output.pdf");
foreach (var entry in collector)
{
Console.WriteLine($"[{entry.Level}] {entry.Category}: {entry.Message}");
}
See Logging.