Webtask

Documentation

HTTP API: Streaming Logs

Access your logs in real time

For customized documentation and ready to run samples, please log in.

The streaming logs endpoint allows you real time access to output generated to stdout and stderr by executing webtask code. This includes output of Node.js's console.log calls. Streaming logs are a useful development time tool. Logs generated by several webtask requests executing within the same webtask container are consolidated into a single stream.

HTTPS GET /api/logs/tenant/{webtask_container}        

The {webtask_container} URL segment identifies the name of the webtask container to get the logs from. The request must be authenticated by specifying the webtask token as the key URL query parameter or with the Authorization HTTP request header.

The long running HTTP response is used to send a stream of bunyan records to the caller. Each record captures output generated by webtask code executing in the {webtask_container} to stdout or stderr.

You can issue a streaming logs request with curl:

curl -N -s https://webtask.it.auth0.com/api/logs/tenant/{webtask_container} -H "Authorization: Bearer {webtask_token}"       

While the streaming logs request is running in one console window, you can issue a webtask request that generates some stdout output from another window, and observe the results:

curl https://webtask.it.auth0.com/api/run/{webtask_container} -H "Authorization: Bearer {webtask_token}" --data-binary 'module.exports = function(cb) { console.log("Received request!"); cb(null, "Hello, world!"); }' 

Since the HTTP response of the streaming logs endpoint contains a series of bunyan records, you can pipe the response through the bunyan tool to get a more human readable output. First, install the bunyan tool:

npm install -g bunyan        

Then re-issue the streaming logs request, this time piping the response throught the tool:

curl -N -s https://webtask.it.auth0.com/api/logs/tenant/{webtask_container} -H "Authorization: Bearer {webtask_token}" | bunyan

The streaming logs request can be customized with the following URL query parameters:

max

Maximum number of messages to return. If not provided, there is no limit.

timeout

Inactivity timeout in milliseconds. If the timeout is exceeded without a message being sent, the server will close the response. If not provided, the server never closes the response.

f.msg

A regular expression to match the text of the log entry against. Only matching messages will be sent. If the value starts with ! only messages that do not match the regular expression are returned. Use !! to escape the starting exclamation mark.

f.{any_property}

Only bunyan records containing {any_property} with the specified value will be returned.

For example, the following request will return up to 100 messages for webtask container that contain the string Hello. If no messages are generated within any 1s interval, the server will close the response:

curl -N -s https://webtask.it.auth0.com/api/logs/tenant/{webtask_container}?f.msg=Hello\&max=100\&timeout=1000 -H "Authorization: Bearer {webtask_token}"
Copy