项目作者: SAshwinAchu10

项目描述 :
Event, Logs Tracer
高级语言: TypeScript
项目地址: git://github.com/SAshwinAchu10/data-tracer.git
创建时间: 2020-02-18T13:22:36Z
项目社区:https://github.com/SAshwinAchu10/data-tracer

开源协议:

下载


Data Tracer

N|Solid

Installation

  1. $ npm i data-tracer
Import
  1. import { Audit, DataTracer } from 'data-tracer';
Instantiate Tracer

Mongoose

  1. Audit.addTracer('mongoose', { connectionString: 'mongodb://localhost:27017/db', appName: 'Apple-Rest' });

Mongo Aggregation Query

  1. import { Audit } from 'data-tracer';
  2. app.get('/audits', async (req: any, res: any) => {
  3. let query: any = req.query;
  4. if (query['page'] == undefined) query['page'] = 1;
  5. if (query['limit'] == undefined) query['limit'] = 10;
  6. let q: any =
  7. query['q'] == undefined
  8. ? [{}]
  9. : [
  10. { when: { $regex: `${query['q']}`, $options: 'i' } },
  11. { what: { $regex: `${query['q']}`, $options: 'i' } },
  12. { type: { $regex: `${query['q']}`, $options: 'i' } },
  13. { where: { $regex: `${query['q']}`, $options: 'i' } },
  14. { why: { $regex: `${query['q']}`, $options: 'i' } },
  15. ];
  16. return Audit.aggregate([
  17. {
  18. $facet: {
  19. audits: [
  20. {
  21. $match: {
  22. type: { $in: JSON.parse(query['type']) },
  23. createdAt: {
  24. $gte: new Date(query['startDate']),
  25. $lte: new Date(query['endDate']),
  26. },
  27. $or: JSON.parse(JSON.stringify(q)),
  28. },
  29. },
  30. { $limit: parseInt(query['limit']) },
  31. { $skip: (query['page'] - 1) * query['limit'] },
  32. ],
  33. apps: [
  34. {
  35. $group: {
  36. _id: null,
  37. apps: { $addToSet: "$appName" }
  38. }
  39. }, { "$unset": ["_id"] }
  40. ]
  41. },
  42. },
  43. ]).then((result: any) => res.json({ data: result }));
  44. });

MySQL

  1. Audit.addTracer('mysql', { host: 'localhost', user: 'root', 'password': 'root', database: 'myDB' });
Instantiate Mail Alerts (Optional)
  1. DataTracer.configureAlert({
  2. 'apiKey': 'abcdefghijklmnopqrstuvwxyz',
  3. 'provider': 'sendgrid',
  4. 'subject': `Error from ${APP_NAME}`,
  5. 'from': 'achu10@live.in',
  6. 'mailTo': 'achu10@live.in',
  7. 'type': ['SEVERE'] // Severity types to trigger email
  8. });
Sample usage
Definition
  1. Audit.logEvent(
  2. type,
  3. what,
  4. subject,
  5. status,
  6. who,
  7. where,
  8. why,
  9. is,
  10. meta
  11. );
Example
  1. Audit.logEvent(
  2. 'INFO',
  3. 'Ping',
  4. 'api was triggered',
  5. 'Successful',
  6. undefined,
  7. 'app.js',
  8. 'to Check Server status',
  9. 'Event',
  10. {
  11. 'key1': value,
  12. 'key2': [
  13. {
  14. 'key21': 'value21'
  15. }
  16. ]
  17. }
  18. )

Examples

Screenshot

N|Solid

Roadmap [WIP]

  • Local file logging
  • Dashboard UI
  • QL for filtering Audit Events, Logs
  • Plugins like console, authorization etc.
  • ELK Integration
  • Monitoring
  • Tracing
  • etc…