We use the “Real-time Webtask Logs” to stream logs, and it works great.
But how can we setup something more production friendly, so we can monitor the logs in production efficiently?
We use papertrail - but anything would be better than nothing.
We use the “Real-time Webtask Logs” to stream logs, and it works great.
But how can we setup something more production friendly, so we can monitor the logs in production efficiently?
We use papertrail - but anything would be better than nothing.
Hi @alexab,
The extension is mostly intended for debugging. You would have to set up some external logging if you want something more persistent.
Hope this clarifies things,
Dan
Let us know how it goes!
Ok, so here is a small guide to make this work:
Step 1, create a new log destination at Papertrail. Make sure to choose “Token” authentication.
Step 2, copy the token and create a new Auth0 rule secret
Step 3, add the following code in your rule (or something similar):
function aSimpleRule(user, context, callback) {
let messages = ``;
const crypto = require('crypto');
const randomId = crypto.randomBytes(20).toString('hex');
const customLogger = (message) => {
// Log the message the console + internal buffer
console.log(message);
messages += `${randomId} ${context.request.hostname} | ${message}\n`;
};
// HELPER FUNCTION TO ENABLE LOGGING
const reportLogToPapertrail = () => {
const fetch = require('node-fetch');
fetch('https://logs.collector.solarwinds.com/v1/logs', {
method: 'post',
headers: {
'Content-Type': 'text/plain',
Authorization: `Basic ${configuration.LOG_KEY}`,
},
body: messages,
})
.then((res) => {
console.log(
`Successfully reported messages to Papertrail with status '${res.status}'`
);
return res.text();
})
.then((text) => {
console.log(text);
})
.catch((err) =>
console.log(
`Failed reporting error to Papertrail with '${err.message}' - not good!`
)
);
};
customLogger('some message');
customLogger('another message');
reportLogToPapertrail(); // Make sure that you don't await this
callback(null, user, context)
}
This will send a batch request with all the logs, nicely formatted in papertrail, while the real-time logs still work. Enjoy
This is awesome! Thanks for taking the time to post it here.
This topic was automatically closed 15 days after the last reply. New replies are no longer allowed.