log.html 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136
  1. <!DOCTYPE html>
  2. <html>
  3. <head>
  4. <meta charset="utf-8">
  5. <meta name="viewport" content="width=device-width, initial-scale=1.0, user-scalable=no, viewport-fit=cover">
  6. <title>Test: Log</title>
  7. <link href="../example/lib/weui.min.css" rel="stylesheet"/>
  8. <link href="../example/lib/demo.css" rel="stylesheet"/>
  9. <script src="../dist/vconsole.min.js"></script>
  10. </head>
  11. <body ontouchstart>
  12. <div class="page">
  13. <a onclick="formattedLog()" href="javascript:;" class="weui_btn weui_btn_default">formattedLog</a>
  14. <a onclick="styledLog()" href="javascript:;" class="weui_btn weui_btn_default">styledLog</a>
  15. <a onclick="normalObject()" href="javascript:;" class="weui_btn weui_btn_default">normalObject</a>
  16. <a onclick="circularObject()" href="javascript:;" class="weui_btn weui_btn_default">circularObject</a>
  17. <a onclick="circularArray()" href="javascript:;" class="weui_btn weui_btn_default">circularArray</a>
  18. <a onclick="largeObject()" href="javascript:;" class="weui_btn weui_btn_default">largeObject</a>
  19. <a onclick="smallArray()" href="javascript:;" class="weui_btn weui_btn_default">smallArray</a>
  20. <a onclick="repeatLog()" href="javascript:;" class="weui_btn weui_btn_default">repeatLog</a>
  21. <a onclick="windowError()" href="javascript:;" class="weui_btn weui_btn_default">window.error</a>
  22. <a onclick="changeTheme()" href="javascript:;" class="weui_btn weui_btn_default">changeTheme</a>
  23. </div>
  24. </body>
  25. </html>
  26. <script>
  27. window.vConsole = new window.VConsole({
  28. maxLogNumber: 1000,
  29. // disableLogScrolling: true,
  30. onReady: function() {
  31. console.log('vConsole is ready.');
  32. },
  33. onClearLog: function() {
  34. console.log('on clearLog');
  35. }
  36. });
  37. function formattedLog() {
  38. console.info('formattedLog() Start');
  39. console.log('[default]', 'This log should be shown in Log tab.');
  40. console.log('[default]', 'Switch to System tab to see next log.');
  41. console.log('[system]', 'This log should be shown in System tab.');
  42. console.log('[foobar]', 'This log should be shown in Log tab.');
  43. console.info('formattedLog() End');
  44. }
  45. function styledLog() {
  46. console.info('styledLog() Start');
  47. console.log('%c red %c blue %c log.', 'color:red', 'color:blue', 'font-weight:bold', 'Use %c format.');
  48. console.info('styledLog() End');
  49. }
  50. function normalObject() {
  51. console.info('normalObject() Start');
  52. console.log('A normal JSON:', {
  53. number: 233,
  54. string: 'Hello world',
  55. boolean: true,
  56. obj: {foo: 'bar'},
  57. array: [8, 7, 6],
  58. func: function(a) { alert('b'); }
  59. });
  60. console.info('normalObject() End');
  61. }
  62. function circularArray() {
  63. console.info('circularArray() Start');
  64. var arr = [];
  65. arr[0] = 'foo';
  66. arr[1] = arr;
  67. console.log('A circular structure array:', arr);
  68. console.info('circularArray() End');
  69. }
  70. function circularObject() {
  71. console.info('circularArray() Start');
  72. var obj = {
  73. foo: 'bar'
  74. };
  75. obj.self = obj;
  76. obj.next = {};
  77. obj.next.next = obj.next;
  78. obj.next.self = obj;
  79. console.log('A circular structure JSON:', obj);
  80. console.info('circularObject() End');
  81. }
  82. function largeObject() {
  83. console.info('largeObject() Start');
  84. var obj = {},
  85. max = 500;
  86. for (var i=1; i<=max; i++) {
  87. obj[ 'key_' + i ] = Math.random();
  88. }
  89. console.log(max + ' keys:', obj);
  90. console.info('largeObject() End');
  91. }
  92. function smallArray() {
  93. console.info('smallArray() Start');
  94. var arr = [0,1,2,3,4,5,6,7,8,9,10,11];
  95. console.log(arr);
  96. console.info('smallArray() End');
  97. }
  98. function repeatLog() {
  99. console.log('repeatLog() Start');
  100. var count = 0;
  101. var timer = setInterval(() => {
  102. count ++;
  103. console.log('repeat', 'foo bar');
  104. if (count >= 100) {
  105. clearInterval(timer);
  106. console.log('repeatLog() End');
  107. }
  108. }, 50);
  109. }
  110. function windowError() {
  111. console.info('windowError() Start');
  112. a.b = 1;
  113. console.info('windowError() End');
  114. }
  115. let theme = 'light';
  116. function changeTheme() {
  117. console.info('changeTheme() Start');
  118. theme = theme === 'light' ? 'dark' : 'light';
  119. window.vConsole.setOption('theme', theme);
  120. console.log('Current Theme:', theme);
  121. console.info('changeTheme() End');
  122. }
  123. </script>