@crowdin/logs-formatter
v2.1.9
Published
Used in Crowdin Apps to output console logs in JSON format
Keywords
Readme
Crowdin Logs Formatter
This module is designed to modify the standard console methods, ensure that the messages are properly formatted for integration with the ELK, and provide middleware for Express to work seamlessly with these methods on the frontend:
const logsFormatter = require('@crowdin/logs-formatter');
logsFormatter.setup();
const app = express();
app.use(express.json({ limit: '50mb' }));
app.use(logsFormatter.expressMiddleware());
app.use(logsFormatter.contextResolverMiddleware());List of console methods to be modified
console.log();
console.debug();
console.info();
console.warn();
console.trace();
console.error();
console.fatal();Use the setContext method to set parameters for user identification. Here's an example
setContext({ project: { id: 1, identifier: 'newproject', organization_id: 200000001, user_id: 12 } })While ELK supports a variety of attributes, note that not all of them are included in the current version of this formatter. Some examples of these attributes are:
"user.id", "user.login", "project.id", "project.identifier", "organization.id", "organization.domain", "client.ip"
"user_agent.original", "http.request.referrer", "url.original", "extra.attributes", "extra.backtrace"