We have provided simple and powerful feature that makes your "flex-balancing" more comfortable. You can log any events and data using logger.write
:
/**
* Logger interface
*/
declare interface ILogger {
/**
* Write a message to the log.
*
* Logged messages will be visible in the Raw Logs for
* current Flex Balancer in the Panel
*/
write(message: string): void;
}
declare const logger: ILogger;
Let's see how it works. We should create a simplest Custom type balancer and add logging to its code:
function onRequest(req: IRequest, res: IResponse) {
res.setCNAMERecord('my.sampleanswer.net');
logger.write('it should return: my.sampleanswer.net');
}
In fact it does nothing useful - returns the same answer, but the goal was to test our logging feature.
So let's Publish it and make couple dozens of dig
tests, using any of approaches described in How to test my FlexBalancer? tutorial.
We get some responses and now we need to check our logs. Log in to PerfOps Panel Analytics page, select FlexBalancer and that balancer we have created:
Apply any filters and take a look at raw logs section below:
View meta
brings up a window with detailed information, where we can see our log message!
So, now you can log different events depending on your FlexBalancer logic and needs!
Let's make an error and log it. Mixing of A and CNAME records is not allowed for our responses, so the code below will definitely produce an error:
function onRequest(req: IRequest, res: IResponse) {
try {
res.setARecord('192.168.1.1');
res.setCNAMERecord('do.something.for.test.net');
} catch(error) {
logger.write(error.message); // Here we log our error
}
return; // return answer
}
Let's publish and test this balancer. Dig returns:
And if we look at our raw logs - we will see our 'caught' error message:
Easy and helpful, isnt' it?