Add Debug Logs with the Toolkit Logger to Find and Fix Issues in a Custom Github Action

Colby Fayock
InstructorColby Fayock
Share this video with your friends

Social Share Links

Send Tweet

In this lesson, we'll walk through adding debug logs to a custom Github Action. We'll use the debug method of the Actions Toolkit Core package to add logs and set the ACTIONS_STEP_DEBUG Github Secret to true in order to see the logs output in our workflow logs.

Colby Fayock: [0:00] We're going to start off with a new custom Action that logs a Futurama character quote. Inside, we accept a character input which we use for the API. With that character name, we reach out to the Futurama API and grab the quote.

[0:11] Most of the time, this code probably run smoothly. What if we wanted to debug it in case there's an issue? GitHub provides a way for us to selectively add debug logging.

[0:19] For the logging itself, we can use the debug method from the core toolkit. To be able to use that method, we need to include the core package, which we're already doing.

[0:26] To start, I want to see which character we're grabbing. I can write core.debug, and I'm going to add a message where I'm going to tag it with Futurama so we know it's ours, and then Input Character, which I'm going to set to {character}.

[0:38] If I run the action in Node, I can already see it working with the debug log. Let's add a few more. To start, I can change this console.log to core.debug, and then I'm going to add my Futurama tag.

[0:49] Next, I want to know exactly when the response was successful. I'm going to add core.debug, and then a message where I'm going to say, "Successfully retrieved quote for the character."

[0:57] With that data, I can log the response itself, where I take the data and I stringify it. We'll need the final console.log as is, as we want to actually see that in the logs. Now, if we run our script again, we can see all of our debug output.

[1:10] Before we test this in GitHub, let's make sure that we build. Once our jobs finish running, we can open them up, and we can see that we're not seeing those logs. In order to see the logs, GitHub requires that you set a secret of ACTIONS_STEP_DEBUG to true.

[1:23] Now in GitHub we can head over to Settings, we also want to navigate to Secrets. Here, we can add a New secret. Here, we'll just set the name to ACTIONS_STEP_DEBUG with a value of true.

[1:33] Once we Add our secret, we can re-run our jobs. Once it's finished running, we can open up our step and we can see all of our debug logs.

[1:40] In review, in order to debug our code, we set some logging using the debug method of the core toolkit. We added a few different logs like the Input Character when we're retrieving the quote, that we successfully retrieved the quote and a log of all the data.

[1:54] In order to see this, we also set the ACTIONS_STEP_DEBUG secret to true. Once our job completed, we were able to open up our stats and see all of our debug code.