Cloud Log Router
This little guy accepts incoming log events and sends them to another service.
Setup
Install dependencies:
$ npm install
Create an env file:
$ cp example.env .env
Generate an API key:
$ openssl rand -hex 16
569bcb828398cd03b0ce3715eb135fa3
Add that to the API_KEY
in the env file.
Start the service:
$ npm start
Post a log event:
$ curl -i \
-d '{"actor":"Auth0 Tenant","component":"Actions","text":"This is an event that happened","transaction":"12313234534","level":"fatal"}' \
-H "Content-Type: application/json" \
-H "Authorization: Bearer f588536b232da287969b25e0fa5595b8" \
http://localhost:3000/log
You should see output in the application log:
{
actor: 'Auth0 Tenant',
component: 'Actions',
text: 'This is an event that happened',
transaction: '12313234534',
level: 'fatal'
}
To send logs to memory:
- Uncomment the memory
OUTBOUND
var in the env file and adjustMAX_LOGS_IN_MEMORY
as needed - Run processes that generate logs as usual
- Make a
GET
call to the/log
endpoint with an API key to see all the logs in memory. - Make a
GET
call to the/log/{$transaction}
endpoint with an API key to see logs for a specific transaction. - Make a
DELETE
call to the/log
endpoint with an API key to flush all saved logs.
To send logs to Slack:
- Create a Slack app with a WebHook URL.
- Uncomment the Slack lines in the env file and add your URL.
- Restart the application and post a log event like the example above.
To send logs to a Google Sheet:
- Create a Google Service account.
- Generate and download credentials for the service account.
- Copy or move the credentials to a
.google.json
file in the root of the application. - Enable the Sheets API.
- Create a new Google Sheet and share it with the
client_email
address in the credentials. - Uncomment the Google lines in the env file and add your Sheet ID; comment out any other
OUTBOUND
lines. - Restart the application and post a log event like the example above.
- The Google Sheet should be appended with a new row with:
- Date and time (UTC)
- Event type
- Actor + component
- Event message
- Transaction