dlog/docs/custom_transforms.md

35 lines
918 B
Markdown
Raw Permalink Normal View History

2022-11-22 15:35:29 +00:00
Custom transforms
=================
## Implementing your own transform
Perhaps the default transformation, `DefaultTransform`, may not be what you want. Maybe you want the module name included in the logged
messages or perhaps don't want the date-and-timestamp included at all. All of this can be up to you if you choose to implement your own
message transform.
2024-04-10 16:04:13 +01:00
You will need to start off with a class that inherits from the `Transform` class and then which overrides the `transform` method as shown below:
2022-11-22 15:35:29 +00:00
```d
import dlog;
2024-04-10 16:05:25 +01:00
public class CustomTransform : Transform
2022-11-22 15:35:29 +00:00
{
2024-04-10 16:04:13 +01:00
public override Message transform(Message message)
2022-11-22 15:35:29 +00:00
{
2024-04-10 16:04:13 +01:00
BasicMessage bmesg = cast(BasicMessage)message;
// Only handle BasicMessage(s) - ones which have `setText(string)`
if(bmesg is null)
{
return message;
}
2022-11-22 15:35:29 +00:00
2024-04-10 16:04:13 +01:00
string transformed;
/* Insert transformation code here */
bmesg.setText(transformed);
2022-11-22 15:35:29 +00:00
2024-04-10 16:04:13 +01:00
return message;
2022-11-22 15:35:29 +00:00
}
}
```