Week 16: Create Your own Logger for Debugging or Verbose Logs

Have you ever wished you had more information in your Custom Function logs? Whether that’s for debugging, reporting, or any other use case you dream up?

While developing better capabilities and dashboards for Custom Functions is 100% in our roadmap, here’s a cool trick that you can do to create a logging facility in any Custom Function.

1. Create an Environment Variable called LOGGER_STATUS

Go into your Workspace Settings > Environment Variables and set its value to false.

Create your own logger for debugging or verbose logs Screen Shot 1

2. Go into your Custom Functions directory and create logger function

Your logger function can do whatever you want it to do. In the example I made, it consoles out the key/value pairs of any object passed to it.

Create your own logger for debugging or verbose logs Screen Shot 2

3. Use your logger in Custom Functions

While in development you’ll see your console statements printed in whichever terminal you’re using, in production (app.8base.com) you’ll find these statements printed in the Functions > FUNCTION_NAME > Logs [Tab] area of your workspace.

Create your own logger for debugging or verbose logs Screen Shot 3

If you have any questions, definitely ask them in the 8base Community!

Happy Developing!

Sebastian