Templates & the Builder Pattern
Leveraging templates and the builder pattern for consistent, maintainable Triton logging across Apex and LWC.
Why Templates Matter
Apex β Set & Reuse a Template
// Early in the transaction (e.g., controller entry, batch start)
Triton.instance.setTemplate(
Triton.makeBuilder()
.category(TritonTypes.Category.Apex)
.level(TritonTypes.Level.DEBUG)
.type(TritonTypes.Type.Backend)
.area(TritonTypes.Area.OpportunityManagement) // agreed taxonomy
);
// Later: clone and specialize
Triton.instance.log(
Triton.instance.fromTemplate()
.level(TritonTypes.Level.INFO)
.summary('Opportunity sync started')
.details('seed=nightly, source=ERP')
);LWC β Component-Scoped Template
Real-World Example: Customer Service Portal
Template Benefits
Consistency
Maintainability
Reduced Errors
Performance
Template Override Pattern
Best Practices
Do's
Don'ts
Template Scoping
Method-Level Templates
Component-Level Templates
Advanced Template Patterns
Conditional Template Properties
Template Inheritance
Last updated