test.js 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142
  1. var Logan = require('logan-web');
  2. Logan.initConfig({
  3. /* Demo Key */
  4. publicKey:
  5. '-----BEGIN PUBLIC KEY-----\n' +
  6. 'MIGeMA0GCSqGSIb3DQEBAQUAA4GMADCBiAKBgG2m5VVtZ4mHml3FB9foDRpDW7Pw\n' +
  7. 'Foa+1eYN777rNmIdnmezQqHWIRVcnTRVjrgGt2ndP2cYT7MgmWpvr8IjgN0PZ6ng\n' +
  8. 'MmKYGpapMqkxsnS/6Q8UZO4PQNlnsK2hSPoIDeJcHxDvo6Nelg+mRHEpD6K+1FIq\n' +
  9. 'zvdwVPCcgK7UbZElAgMBAAE=\n' +
  10. '-----END PUBLIC KEY-----'
  11. });
  12. function timeFormat2Day(date) {
  13. var Y = date.getFullYear();
  14. var M = date.getMonth() + 1;
  15. var D = date.getDate();
  16. return Y + '-' + (M < 10 ? '0' + M : M) + '-' + (D < 10 ? '0' + D : D);
  17. }
  18. document.getElementById('log').onclick = log;
  19. document.getElementById('logWithEncryption').onclick = logWithEncryption;
  20. document.getElementById('report').onclick = report;
  21. function log() {
  22. Logan.log('Hello World!', 1);
  23. }
  24. function logWithEncryption() {
  25. Logan.logWithEncryption('Hello World!', 2);
  26. }
  27. function report() {
  28. var now = new Date();
  29. var sevenDaysAgo = new Date(+now - 6 * 24 * 3600 * 1000);
  30. Logan.report({
  31. reportUrl: 'https://yourServerAddressToAcceptLogs',
  32. deviceId: 'test-logan-web',
  33. fromDayString: timeFormat2Day(sevenDaysAgo),
  34. toDayString: timeFormat2Day(now),
  35. webSource: 'browser',
  36. environment: navigator.userAgent,
  37. customInfo: JSON.stringify({ userId: 123456, biz: 'Live Better' })
  38. });
  39. }