Consider this problem.
You have a channel that has two translator instances in it – let’s say a From HTTP translator instance and a To Translator instance. When logging occurs in either translator component how do you tell which component was logging?
This module can solve this problem. It modifies the built in logging commands in the translator like:
And puts in new versions which put a prefix of the translator type followed by “: ” in front of each log statement. So imagine you had a line that logged “Sent message” within the From HTTP component of a channel then the log would show “HTTP: Sent message” instead of just “Sent message”. If the same log statement happened within a filter translator instance one would see “Filter: Sent message”.
This channel has the code to do this and shows how to use it. You can use the same module in your own channels to solve this problem.
Using the code [top]
- Import the Log Annotate channel from the Builtin: Tools repository
- Experiment with the code to find out how it works
- Then add the module(s) to your Translator project
- Copy the require ‘log.annotate’ statement from the channel and add it at the top of your script
Note: This module modifies the global namespace
How it works [top]
At startup the module inspects the configuration for the channel and figures out the specific translator instance type by comparing its’ translator ID against the ID’s present in the configuration for the channel.
Then each of the builtin logging functions (like
iguanaLogError() etc.) is then replaced by a new version of each function which gives a prefix indicating the type of translator that is logging.
To see the code in action run the channel and click on the included link to bring up the logs for the channel. Take note of the prefixes on the logs which highlighted with red rectangles: