From 751fc42f9248e2baf91854c11bd86ddef7d8de4f Mon Sep 17 00:00:00 2001 From: kevinnwang Date: Fri, 7 Sep 2018 15:23:17 +0800 Subject: [PATCH 1/2] fix error that property IDBTransaction.READ_WRITE is proctected --- src/protocols/indexeddb.js | 12 +++++------- 1 file changed, 5 insertions(+), 7 deletions(-) diff --git a/src/protocols/indexeddb.js b/src/protocols/indexeddb.js index 15af3a3..b88dffc 100644 --- a/src/protocols/indexeddb.js +++ b/src/protocols/indexeddb.js @@ -2,6 +2,8 @@ import LoggerInterface from './interface'; import Pool from '../lib/pool'; import * as util from '../lib/util'; +const READ_WRITE = 'readwrite'; + /** * IndexedDB protocol * @class IndexedDBLogger @@ -35,7 +37,7 @@ export default class IndexedDBLogger extends LoggerInterface { } util.debug(this._namespace, level, descriptor, data); - let transaction = IndexedDBLogger.db.transaction(['logs'], IDBTransaction.READ_WRITE || 'readwrite'); + let transaction = IndexedDBLogger.db.transaction(['logs'], READ_WRITE || 'readwrite'); transaction.onerror = event => util.throwError(event.target.error); let store = transaction.objectStore('logs'); @@ -176,7 +178,7 @@ export default class IndexedDBLogger extends LoggerInterface { return IndexedDBLogger._pool.push(() => IndexedDBLogger.keep(daysToMaintain)); } - let store = IndexedDBLogger._getTransactionStore(IDBTransaction.READ_WRITE); + let store = IndexedDBLogger._getTransactionStore(READ_WRITE); if (!store) { return false; } @@ -236,7 +238,7 @@ export default class IndexedDBLogger extends LoggerInterface { static _getTransactionStore(mode) { try { if (IndexedDBLogger.db) { - let transaction = IndexedDBLogger.db.transaction(['logs'], mode || IDBTransaction.READ_WRITE); + let transaction = IndexedDBLogger.db.transaction(['logs'], mode || READ_WRITE); transaction.onerror = event => util.throwError(event.target.error); return transaction.objectStore('logs'); } @@ -255,10 +257,6 @@ export default class IndexedDBLogger extends LoggerInterface { */ static get support() { const support = !!(window.indexedDB && window.IDBTransaction && window.IDBKeyRange); - if (support) { - window.IDBTransaction.READ_WRITE = 'readwrite'; - window.IDBTransaction.READ_ONLY = 'readonly'; - } return support; } } From c26b3ead3c080f9b30acda88159d0893b976d448 Mon Sep 17 00:00:00 2001 From: kevinnwang Date: Fri, 7 Sep 2018 15:24:09 +0800 Subject: [PATCH 2/2] tests should not run if a protocol is not supported by test-runner environment --- dist/logline.js | 12 +++++------- dist/logline.min.js | 2 +- dist/logline.min.js.map | 2 +- package.json | 5 ++++- test/tests.js | 27 ++++++++++++++++----------- 5 files changed, 27 insertions(+), 21 deletions(-) diff --git a/dist/logline.js b/dist/logline.js index 08c88a3..9c2837b 100644 --- a/dist/logline.js +++ b/dist/logline.js @@ -433,6 +433,8 @@ var Pool = function () { return Pool; }(); +var READ_WRITE = 'readwrite'; + /** * IndexedDB protocol * @class IndexedDBLogger @@ -485,7 +487,7 @@ var IndexedDBLogger = function (_LoggerInterface) { } debug(this._namespace, level, descriptor, data); - var transaction = IndexedDBLogger.db.transaction(['logs'], IDBTransaction.READ_WRITE || 'readwrite'); + var transaction = IndexedDBLogger.db.transaction(['logs'], READ_WRITE || 'readwrite'); transaction.onerror = function (event) { return throwError(event.target.error); }; @@ -649,7 +651,7 @@ var IndexedDBLogger = function (_LoggerInterface) { }); } - var store = IndexedDBLogger._getTransactionStore(IDBTransaction.READ_WRITE); + var store = IndexedDBLogger._getTransactionStore(READ_WRITE); if (!store) { return false; } @@ -722,7 +724,7 @@ var IndexedDBLogger = function (_LoggerInterface) { value: function _getTransactionStore(mode) { try { if (IndexedDBLogger.db) { - var transaction = IndexedDBLogger.db.transaction(['logs'], mode || IDBTransaction.READ_WRITE); + var transaction = IndexedDBLogger.db.transaction(['logs'], mode || READ_WRITE); transaction.onerror = function (event) { return throwError(event.target.error); }; @@ -745,10 +747,6 @@ var IndexedDBLogger = function (_LoggerInterface) { key: 'support', get: function get$$1() { var support = !!(window.indexedDB && window.IDBTransaction && window.IDBKeyRange); - if (support) { - window.IDBTransaction.READ_WRITE = 'readwrite'; - window.IDBTransaction.READ_ONLY = 'readonly'; - } return support; } }]); diff --git a/dist/logline.min.js b/dist/logline.min.js index eedd906..c5d14e8 100644 --- a/dist/logline.min.js +++ b/dist/logline.min.js @@ -1,2 +1,2 @@ -!function(e,t){"object"==typeof exports&&"undefined"!=typeof module?module.exports=t():"function"==typeof define&&define.amd?define(t):e.Logline=t()}(this,function(){"use strict";function e(e){return e?d[e]:d}function t(e,t){var o={};"string"==typeof e?o[e]=t:"[object Object]"===Object.prototype.toString.call(e)&&(o=e),s(d,o)}function o(e){g&&console.error("Logline: "+e)}function n(e,t,o,n){g&&_.get().verbose&&window.console[y[t.toUpperCase()]||y.INFO](e+" "+t.toUpperCase()+" "+o,n||"")}function r(e){var t,o={};if("object"!==(void 0===e?"undefined":a(e)))return e;for(t in e)e.hasOwnProperty(t)&&"function"!=typeof e[t]&&(o[t]=r(e[t]));return o}var a="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(e){return typeof e}:function(e){return e&&"function"==typeof Symbol&&e.constructor===Symbol&&e!==Symbol.prototype?"symbol":typeof e},i=function(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")},c=function(){function e(e,t){for(var o=0;on||c.push(i[o]);r(c)}}else{var s=a.openCursor(),l=[];s.onsuccess=function(t){var o=t.target.result;if(o){if(e&&o.value.timen)return o.continue();l.push({time:o.value.time,level:o.value.level,namespace:o.value.namespace,descriptor:o.value.descriptor,data:o.value.data}),o.continue()}else r(l)}}}catch(e){o("failed to get logs, "+e.message)}}},{key:"keep",value:function(e){try{if(t.status!==u(t.__proto__||Object.getPrototypeOf(t),"STATUS",this).INITED)return t._pool.push(function(){return t.keep(e)});var n=t._getTransactionStore(IDBTransaction.READ_WRITE);if(!n)return!1;if(e){var r=Date.now()-24*(e||2)*3600*1e3,a=n.openCursor();a.onsuccess=function(e){var t=e.target.result;t&&t.value.timen||(a[i]={time:a[i][0],namespace:a[i][1],level:a[i][2],descriptor:a[i][3],data:a[i][4]});r(a)}catch(e){o("failed to get, "+e.message),r([])}}},{key:"keep",value:function(e){var n;try{n=e?(window.localStorage.getItem(t._database)?JSON.parse(window.localStorage.getItem(t._database)):[]).filter(function(t){return t.time>=Date.now()-24*(e||2)*3600*1e3}):[],window.localStorage.setItem(t._database,JSON.stringify(n))}catch(e){o("failed to keep, "+e.message)}}},{key:"clean",value:function(){try{delete t.status,window.localStorage.removeItem(t._database)}catch(e){o("failed to clean, "+e.message)}}},{key:"support",get:function(){return"localStorage"in window}}]),t}(v),T=function(e){function t(){var e;i(this,t);for(var o=arguments.length,n=Array(o),r=0;r=0;)if(i=o.rows.item(s),!(e&&i.timen)){a=JSON.parse(JSON.stringify(i));try{a.data=JSON.parse(a.data)}catch(e){}c.push(a)}r(c)},function(e,t){o(t.message)})})}catch(e){o("unable to collect logs from database.")}}},{key:"keep",value:function(e){if(t.status!==u(t.__proto__||Object.getPrototypeOf(t),"STATUS",this).INITED)return t._pool.push(function(){return t.keep(e)});try{t._db.transaction(function(t){e?t.executeSql("DELETE FROM logs WHERE time < ?",[Date.now()-24*(e||2)*3600*1e3],function(){},function(e,t){o(t.message)}):t.executeSql("DELETE FROM logs",[],function(){},function(e,t){o(t.message)})})}catch(e){o("unable to clean logs from database.")}}},{key:"clean",value:function(){if(t.status!==u(t.__proto__||Object.getPrototypeOf(t),"STATUS",this).INITED)return void t._pool.push(function(){return t.clean()});try{t._db.transaction(function(e){e.executeSql("DROP TABLE logs",[],function(){delete t.status},function(e,t){o(t.message)})})}catch(e){o("unable to clean log database.")}}},{key:"support",get:function(){return"openDatabase"in window}}]),t}(v),w=function(){function e(t){if(i(this,e),!(this instanceof e))return new e(t);try{return e._checkProtocol(),new e._protocol(t)}catch(e){return new v(t)}}return c(e,null,[{key:"_initProtocol",value:function(t){e._protocol=t,e._protocol.init(e._database||"logline")}},{key:"_checkProtocol",value:function(){if(!e._protocol){for(var t=Object.keys(e.PROTOCOL),n=void 0;n=e.PROTOCOL[t.shift()];)if(n.support)return void e._initProtocol(n);o("protocols "+t.join(", ").toLowerCase()+" are not supported on this platform")}}},{key:"get",value:function(t,o,n){switch(e._checkProtocol(),arguments.length){case 1:n=t,t=void 0;break;case 2:n=o,o=void 0}e._protocol.get(t,o,n)}},{key:"all",value:function(t){e.get(t)}},{key:"keep",value:function(t){return e._checkProtocol(),e._protocol.keep(t),this}},{key:"clean",value:function(){return e._checkProtocol(),e._protocol.clean(),this}},{key:"using",value:function(t,n){return-1===[m,b,T].indexOf(t)&&o("specialfied protocol "+(t?t+" ":"")+"is not available"),e._protocol?this:(e.database(n||e._database),e._initProtocol(t),this)}},{key:"database",value:function(t){e._database=t}},{key:"config",get:function(){return _}}]),e}();return w.PROTOCOL={INDEXEDDB:m,LOCALSTORAGE:b,WEBSQL:T},w.INTERFACE=Object.freeze(v),w.env={verbose:!0},w}); +!function(e,t){"object"==typeof exports&&"undefined"!=typeof module?module.exports=t():"function"==typeof define&&define.amd?define(t):e.Logline=t()}(this,function(){"use strict";function e(e){return e?d[e]:d}function t(e,t){var o={};"string"==typeof e?o[e]=t:"[object Object]"===Object.prototype.toString.call(e)&&(o=e),s(d,o)}function o(e){_&&console.error("Logline: "+e)}function r(e,t,o,r){_&&g.get().verbose&&window.console[y[t.toUpperCase()]||y.INFO](e+" "+t.toUpperCase()+" "+o,r||"")}function n(e){var t,o={};if("object"!==(void 0===e?"undefined":a(e)))return e;for(t in e)e.hasOwnProperty(t)&&"function"!=typeof e[t]&&(o[t]=n(e[t]));return o}var a="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(e){return typeof e}:function(e){return e&&"function"==typeof Symbol&&e.constructor===Symbol&&e!==Symbol.prototype?"symbol":typeof e},i=function(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")},c=function(){function e(e,t){for(var o=0;or||c.push(i[o]);n(c)}}else{var s=a.openCursor(),l=[];s.onsuccess=function(t){var o=t.target.result;if(o){if(e&&o.value.timer)return o.continue();l.push({time:o.value.time,level:o.value.level,namespace:o.value.namespace,descriptor:o.value.descriptor,data:o.value.data}),o.continue()}else n(l)}}}catch(e){o("failed to get logs, "+e.message)}}},{key:"keep",value:function(e){try{if(t.status!==u(t.__proto__||Object.getPrototypeOf(t),"STATUS",this).INITED)return t._pool.push(function(){return t.keep(e)});var r=t._getTransactionStore("readwrite");if(!r)return!1;if(e){var n=Date.now()-24*(e||2)*3600*1e3,a=r.openCursor();a.onsuccess=function(e){var t=e.target.result;t&&t.value.timer||(a[i]={time:a[i][0],namespace:a[i][1],level:a[i][2],descriptor:a[i][3],data:a[i][4]});n(a)}catch(e){o("failed to get, "+e.message),n([])}}},{key:"keep",value:function(e){var r;try{r=e?(window.localStorage.getItem(t._database)?JSON.parse(window.localStorage.getItem(t._database)):[]).filter(function(t){return t.time>=Date.now()-24*(e||2)*3600*1e3}):[],window.localStorage.setItem(t._database,JSON.stringify(r))}catch(e){o("failed to keep, "+e.message)}}},{key:"clean",value:function(){try{delete t.status,window.localStorage.removeItem(t._database)}catch(e){o("failed to clean, "+e.message)}}},{key:"support",get:function(){return"localStorage"in window}}]),t}(v),S=function(e){function t(){var e;i(this,t);for(var o=arguments.length,r=Array(o),n=0;n=0;)if(i=o.rows.item(s),!(e&&i.timer)){a=JSON.parse(JSON.stringify(i));try{a.data=JSON.parse(a.data)}catch(e){}c.push(a)}n(c)},function(e,t){o(t.message)})})}catch(e){o("unable to collect logs from database.")}}},{key:"keep",value:function(e){if(t.status!==u(t.__proto__||Object.getPrototypeOf(t),"STATUS",this).INITED)return t._pool.push(function(){return t.keep(e)});try{t._db.transaction(function(t){e?t.executeSql("DELETE FROM logs WHERE time < ?",[Date.now()-24*(e||2)*3600*1e3],function(){},function(e,t){o(t.message)}):t.executeSql("DELETE FROM logs",[],function(){},function(e,t){o(t.message)})})}catch(e){o("unable to clean logs from database.")}}},{key:"clean",value:function(){if(t.status!==u(t.__proto__||Object.getPrototypeOf(t),"STATUS",this).INITED)return void t._pool.push(function(){return t.clean()});try{t._db.transaction(function(e){e.executeSql("DROP TABLE logs",[],function(){delete t.status},function(e,t){o(t.message)})})}catch(e){o("unable to clean log database.")}}},{key:"support",get:function(){return"openDatabase"in window}}]),t}(v),T=function(){function e(t){if(i(this,e),!(this instanceof e))return new e(t);try{return e._checkProtocol(),new e._protocol(t)}catch(e){return new v(t)}}return c(e,null,[{key:"_initProtocol",value:function(t){e._protocol=t,e._protocol.init(e._database||"logline")}},{key:"_checkProtocol",value:function(){if(!e._protocol){for(var t=Object.keys(e.PROTOCOL),r=void 0;r=e.PROTOCOL[t.shift()];)if(r.support)return void e._initProtocol(r);o("protocols "+t.join(", ").toLowerCase()+" are not supported on this platform")}}},{key:"get",value:function(t,o,r){switch(e._checkProtocol(),arguments.length){case 1:r=t,t=void 0;break;case 2:r=o,o=void 0}e._protocol.get(t,o,r)}},{key:"all",value:function(t){e.get(t)}},{key:"keep",value:function(t){return e._checkProtocol(),e._protocol.keep(t),this}},{key:"clean",value:function(){return e._checkProtocol(),e._protocol.clean(),this}},{key:"using",value:function(t,r){return-1===[m,b,S].indexOf(t)&&o("specialfied protocol "+(t?t+" ":"")+"is not available"),e._protocol?this:(e.database(r||e._database),e._initProtocol(t),this)}},{key:"database",value:function(t){e._database=t}},{key:"config",get:function(){return g}}]),e}();return T.PROTOCOL={INDEXEDDB:m,LOCALSTORAGE:b,WEBSQL:S},T.INTERFACE=Object.freeze(v),T.env={verbose:!0},T}); //# sourceMappingURL=logline.min.js.map diff --git a/dist/logline.min.js.map b/dist/logline.min.js.map index 8040405..e9b6249 100644 --- a/dist/logline.min.js.map +++ b/dist/logline.min.js.map @@ -1 +1 @@ -{"version":3,"file":"logline.min.js","sources":["../src/lib/config.js","../src/lib/util.js","../src/protocols/interface.js","../src/lib/pool.js","../src/protocols/indexeddb.js","../src/protocols/localstorage.js","../src/protocols/websql.js","../src/logline.js"],"sourcesContent":["const DEFAULT_CONFIG = {\n verbose: true\n};\n\nlet store = Object.assign({}, DEFAULT_CONFIG);\n\nexport function get(key) {\n return key ? store[key] : store;\n}\n\nexport function set(key, value) {\n let changes = {};\n if (typeof key === 'string') {\n changes[key] = value;\n } else if (Object.prototype.toString.call(key) === '[object Object]') {\n changes = key;\n }\n Object.assign(store, changes);\n}\n\nlet config = set;\nconfig.set = set;\nconfig.get = get;\n\nexport default config;\n","import config from './config';\n\nconst HAS_CONSOLE = window.console;\nconst LEVEL_CONSOLE_MAP = {\n INFO: 'log',\n WARN: 'warn',\n ERROR: 'error',\n CRITICAL: 'error'\n};\n\n// throw out Errors, with global prefix 'Logline: ' ahead of err.message\nexport function throwError(errMessage) {\n HAS_CONSOLE && console.error('Logline: ' + errMessage);\n}\n\n// print debug info in develper's console\n// TODO: if WechatFE/vConsole is detected, will not use %c feature, as it is not well supported\nexport function debug(namespace, level, descriptor, data) {\n if (HAS_CONSOLE && config.get().verbose) {\n window.console[LEVEL_CONSOLE_MAP[level.toUpperCase()] || LEVEL_CONSOLE_MAP.INFO](`${namespace} ${level.toUpperCase()} ${descriptor}`, data || '');\n }\n}\n\n// filter any function in a object\nexport function filterFunction(obj) {\n var newObj = {}, i;\n\n if (typeof obj !== 'object') {\n return obj;\n }\n\n for (i in obj) {\n if (obj.hasOwnProperty(i)) {\n if (typeof obj[i] !== 'function') {\n newObj[i] = filterFunction(obj[i]);\n }\n }\n }\n return newObj;\n}\n","import * as util from '../lib/util';\n\n/**\n * Logline Interface\n * @class Interface\n */\nexport default class Interface {\n /**\n * Logline constructor\n * @constructor\n * @param {String} namespace - namespace to use\n */\n constructor(namespace) {\n this._namespace = namespace;\n }\n\n /**\n * add a log record\n * @method _reocrd\n * @private\n * @parma {String} level - log level\n * @param {String} descriptor - to speed up search and improve understanding\n * @param {Mixed} [data] - additional data\n */\n _record(level, descriptor, data) {\n util.throwError('method _record is not implemented.');\n }\n\n /**\n * add a level-info record\n * @method info\n * @param {String} descriptor - to speed up search and improve understanding\n * @param {Mixed} [data] - additional data\n */\n info(...args) {\n this._record('info', ...args);\n }\n\n /**\n * add a level-warn record\n * @method warn\n * @param {String} descriptor - to speed up search and improve understanding\n * @param {Mixed} [data] - additional data\n */\n warn(...args) {\n this._record('warn', ...args);\n }\n\n /**\n * add a level-error record\n * @method error\n * @param {String} descriptor - to speed up search and improve understanding\n * @param {Mixed} [data] - additional data\n */\n error(...args) {\n this._record('error', ...args);\n }\n\n /**\n * add a level-critical record\n * @method critical\n * @param {String} descriptor - to speed up search and improve understanding\n * @param {Mixed} [data] - additional data\n */\n critical(...args) {\n this._record('critical', ...args);\n }\n\n /**\n * initialize protocol\n * @method init\n * @static\n * @param {String} database - database name to use\n */\n static init(database) {\n return true;\n }\n\n /**\n * transform human readable time string, such as '3d', '.3' and '1.2' into Unix timestamp\n * the default relative time is Date.now(), if no second parameter is provided\n * @method transTimeFormat\n * @static\n * @param {String} time - time string to transform\n * @param {Number} [relative] - relative time to compare, default Date.now()\n * @return {Number|NaN} timestamp transformed\n */\n static transTimeFormat(time, relative) {\n // if falsy value or timestamp already, pass it through directly,\n if (!time || /^\\d{13}$/.test(time)) {\n return +time;\n }\n // incase relative time isn't unix timestamp format,\n // neither a falsy value which will turned out to be Date.now()\n if (relative && !/^\\d{13}$/.test(relative)) {\n throw new TypeError('relative time should be standard unix timestamp');\n }\n\n return (relative || Date.now()) - time.replace(/d$/, '') * 24 * 3600 * 1000;\n }\n\n /**\n * get logs in range\n * if from and end is not defined, will fetch full log\n * @method get\n * @static\n * @param {String} from - time from, unix timestamp\n * @param {String} to - time end, unix timestamp\n * @param {Function} readyFn - function to call back with logs as parameter\n */\n static get(from, to, readyFn) {\n util.throwError('method get is not implemented.');\n }\n\n /**\n * clean logs = keep limited logs\n * @method keep\n * @static\n * @param {Number} daysToMaintain - keep logs within days\n */\n static keep(daysToMaintain) {\n util.throwError('method keep is not implemented.');\n }\n\n /**\n * delete log database\n * @method clean\n * @static\n */\n static clean() {\n util.throwError('method clean is not implemented.');\n }\n\n /**\n * protocol status map\n * @prop {Object} STATUS\n */\n static get STATUS() {\n return {\n INITING: 1,\n INITED: 2,\n FAILED: 4\n };\n }\n}\n","/**\n * Pool, for storage of async calling\n * @class Pool\n */\nexport default class Pool {\n /**\n * Pool constructor\n * @constructor\n */\n constructor() {\n this._pool = [];\n }\n\n /**\n * add an procedure\n * @method push\n * @param {Function} handler - procedure handler\n * @param {Object} context - procedure context\n */\n push(handler, context) {\n handler.context = context;\n this._pool.push(handler);\n }\n\n /**\n * consume pool\n * @method consume\n */\n consume() {\n var handler;\n while ((handler = this._pool.shift())) {\n handler.call(handler.context);\n }\n }\n}\n","import LoggerInterface from './interface';\nimport Pool from '../lib/pool';\nimport * as util from '../lib/util';\n\n/**\n * IndexedDB protocol\n * @class IndexedDBLogger\n */\nexport default class IndexedDBLogger extends LoggerInterface {\n /**\n * IndexedDB protocol constructor\n * @constructor\n * @param {String} namespace - namespace to use\n */\n constructor(...args) {\n super(...args);\n }\n\n /**\n * add a log record\n * @method _reocrd\n * @private\n * @parma {String} level - log level\n * @param {String} descriptor - to speed up search and improve understanding\n * @param {Mixed} [data] - additional data\n */\n _record(level, descriptor, data) {\n try {\n if (IndexedDBLogger.status !== LoggerInterface.STATUS.INITED) {\n IndexedDBLogger._pool.push(() => this._record(level, descriptor, data));\n if (IndexedDBLogger.status !== LoggerInterface.STATUS.INITING) {\n IndexedDBLogger.init();\n }\n return;\n }\n\n util.debug(this._namespace, level, descriptor, data);\n let transaction = IndexedDBLogger.db.transaction(['logs'], IDBTransaction.READ_WRITE || 'readwrite');\n transaction.onerror = event => util.throwError(event.target.error);\n\n let store = transaction.objectStore('logs');\n // should not contains any function in data\n // otherwise 'DOMException: Failed to execute 'add' on 'IDBObjectStore': An object could not be cloned.' will be thrown\n let request = store.add({\n time: Date.now(),\n level: level,\n namespace: this._namespace,\n descriptor: descriptor,\n data: util.filterFunction(data)\n });\n\n request.onerror = event => {\n IndexedDBLogger.status = LoggerInterface.STATUS.FAILED;\n util.throwError(event.target.error);\n };\n } catch (e) {\n util.throwError('failed to write, ' + e.message);\n }\n }\n\n /**\n * initialize protocol\n * @method init\n * @static\n * @param {String} database - database name to use\n */\n static init(database) {\n try {\n if (!IndexedDBLogger.support) {\n util.throwError('your platform does not support indexeddb protocol.');\n }\n\n if (IndexedDBLogger.status) {\n return false;\n }\n\n IndexedDBLogger._pool = IndexedDBLogger._pool || new Pool();\n IndexedDBLogger._database = database || 'logline';\n IndexedDBLogger.status = super.STATUS.INITING;\n\n IndexedDBLogger.request = window.indexedDB.open(IndexedDBLogger._database);\n IndexedDBLogger.request.onerror = event => util.throwError('protocol indexeddb is prevented.');\n IndexedDBLogger.request.onsuccess = event => {\n IndexedDBLogger.db = event.target.result;\n IndexedDBLogger.status = super.STATUS.INITED;\n IndexedDBLogger._pool.consume();\n // globally handle db request errors\n IndexedDBLogger.db.onerror = event => util.throwError(event.target.error);\n };\n IndexedDBLogger.request.onupgradeneeded = event => {\n // init dabasebase\n let db = event.target.result, store = db.createObjectStore('logs', { autoIncrement: true });\n store.createIndex('namespace', 'namespace', { unique: false });\n store.createIndex('level', 'level', { unique: false });\n store.createIndex('descriptor', 'descriptor', { unique: false });\n store.createIndex('data', 'data', { unique: false });\n };\n } catch (e) {\n util.throwError('failed init, ' + e.message);\n }\n }\n\n /**\n * get logs in range\n * if from and end is not defined, will fetch full log\n * @method get\n * @static\n * @param {String} [from] - time from, unix time stamp or falsy\n * @param {String} [to] - time end, unix time stamp or falsy\n * @param {Function} readyFn - function to call back with logs as parameter\n */\n static get(from, to, readyFn) {\n try {\n if (IndexedDBLogger.status !== super.STATUS.INITED) {\n return IndexedDBLogger._pool.push(() => IndexedDBLogger.get(from, to, readyFn));\n }\n\n from = LoggerInterface.transTimeFormat(from);\n to = LoggerInterface.transTimeFormat(to);\n\n let store = IndexedDBLogger._getTransactionStore(IDBTransaction.READ_ONLY);\n if (!store) {\n return readyFn([]);\n }\n\n // IDBObjectStore.getAll is a non-standard API\n if (store.getAll) {\n let result, logs = [];\n store.getAll().onsuccess = event => {\n result = event.target.result;\n for (let i = 0; i < result.length; i++) {\n if ((from && result[i].time < from) || (to && result[i].time > to)) {\n continue;\n }\n logs.push(result[i]);\n }\n readyFn(logs);\n };\n } else {\n let request = store.openCursor(), logs = [];\n request.onsuccess = event => {\n var cursor = event.target.result;\n if (cursor) {\n if ((from && cursor.value.time < from) || (to && cursor.value.time > to)) {\n return cursor.continue();\n }\n\n logs.push({\n time: cursor.value.time,\n level: cursor.value.level,\n namespace: cursor.value.namespace,\n descriptor: cursor.value.descriptor,\n data: cursor.value.data\n });\n cursor.continue();\n }\n else {\n readyFn(logs);\n }\n };\n }\n } catch (e) {\n util.throwError('failed to get logs, ' + e.message);\n }\n }\n\n /**\n * clean logs = keep limited logs\n * @method keep\n * @static\n * @param {Number} daysToMaintain - keep logs within days\n */\n static keep(daysToMaintain) {\n try {\n if (IndexedDBLogger.status !== super.STATUS.INITED) {\n return IndexedDBLogger._pool.push(() => IndexedDBLogger.keep(daysToMaintain));\n }\n\n let store = IndexedDBLogger._getTransactionStore(IDBTransaction.READ_WRITE);\n if (!store) {\n return false;\n }\n if (!daysToMaintain) {\n let request = store.clear().onerror = event => util.throwError(event.target.error);\n }\n else {\n let range = (Date.now() - (daysToMaintain || 2) * 24 * 3600 * 1000);\n let request = store.openCursor();\n request.onsuccess = event => {\n let cursor = event.target.result;\n if (cursor && cursor.value.time < range) {\n store.delete(cursor.primaryKey);\n cursor.continue();\n }\n };\n request.onerror = event => util.throwError('unable to locate logs earlier than ' + daysToMaintain + 'd.');\n }\n } catch (e) {\n util.throwError('failed to keep logs, ' + e.message);\n }\n }\n\n /**\n * delete log database\n * @method clean\n * @static\n */\n static clean() {\n try {\n if (IndexedDBLogger.status !== super.STATUS.INITED) {\n return IndexedDBLogger._pool.push(() => IndexedDBLogger.clean());\n }\n\n // database can be removed only after all connections are closed\n IndexedDBLogger.db.close();\n let request = window.indexedDB.deleteDatabase(IndexedDBLogger._database);\n request.onerror = event => util.throwError(event.target.error);\n /* eslint no-unused-vars: \"off\" */\n request.onsuccess = event => {\n delete IndexedDBLogger.status;\n delete IndexedDBLogger.db;\n };\n } catch (e) {\n util.throwError('failed to cleanup logs, ' + e.message);\n }\n }\n\n /**\n * get internal transaction store\n * @method _getTransactionStore\n * @private\n * @static\n * @param {String} mode - transaction mode\n * @return {Object} - internal object store\n */\n static _getTransactionStore(mode) {\n try {\n if (IndexedDBLogger.db) {\n let transaction = IndexedDBLogger.db.transaction(['logs'], mode || IDBTransaction.READ_WRITE);\n transaction.onerror = event => util.throwError(event.target.error);\n return transaction.objectStore('logs');\n }\n else {\n util.throwError('log database is not created or connections are closed, considering init it.');\n }\n } catch (e) {\n util.throwError('failed to generate new transaction, ' + e.message);\n return false;\n }\n }\n\n /**\n * detect support situation\n * @prop {Boolean} support\n */\n static get support() {\n const support = !!(window.indexedDB && window.IDBTransaction && window.IDBKeyRange);\n if (support) {\n window.IDBTransaction.READ_WRITE = 'readwrite';\n window.IDBTransaction.READ_ONLY = 'readonly';\n }\n return support;\n }\n}\n","import LoggerInterface from './interface';\nimport * as util from '../lib/util';\n\n/**\n * Localstorage protocol\n * @class LocalStorageLogger\n */\nexport default class LocalStorageLogger extends LoggerInterface {\n /**\n * Localstorage protocol constructor\n * @constructor\n * @param {String} namespace - namespace to use\n */\n constructor(...args) {\n super(...args);\n }\n\n /**\n * add a log record\n * @method _reocrd\n * @private\n * @parma {String} level - log level\n * @param {String} descriptor - to speed up search and improve understanding\n * @param {Mixed} [data] - additional data\n */\n _record(level, descriptor, data) {\n var logs;\n try {\n logs = window.localStorage.getItem(LocalStorageLogger._database) ? JSON.parse(window.localStorage.getItem(LocalStorageLogger._database)) : [];\n logs.push([\n Date.now(),\n this._namespace,\n level,\n descriptor,\n data\n ]);\n util.debug(this._namespace, level, descriptor, data);\n window.localStorage.setItem(LocalStorageLogger._database, JSON.stringify(logs));\n } catch (e) { util.throwError('failed to write, ' + e.message); }\n }\n\n /**\n * initialize protocol\n * @method init\n * @static\n * @param {String} database - database name to use\n */\n static init(database) {\n try {\n if (!LocalStorageLogger.support) {\n util.throwError('your platform does not support localstorage protocol.');\n }\n LocalStorageLogger._database = database || 'logline';\n if (!window.localStorage.getItem(LocalStorageLogger._database)) {\n window.localStorage.setItem(LocalStorageLogger._database, JSON.stringify([]));\n }\n LocalStorageLogger.status = super.STATUS.INITED;\n } catch (e) {\n util.throwError('failed to init, ' + e.message);\n }\n }\n\n /**\n * get logs in range\n * if from and end is not defined, will fetch full log\n * @method get\n * @static\n * @param {String} from - time from, unix time stamp or falsy\n * @param {String} to - time end, unix time stamp or falsy\n * @param {Function} readyFn - function to call back with logs as parameter\n */\n static get(from, to, readyFn) {\n var logs, i;\n try {\n logs = JSON.parse(window.localStorage.getItem(LocalStorageLogger._database));\n\n from = LoggerInterface.transTimeFormat(from);\n to = LoggerInterface.transTimeFormat(to);\n\n for (i = 0; i < logs.length; i++) {\n if ((from && logs[i][0] < from) || (to && logs[i][0] > to)) {\n continue;\n }\n\n logs[i] = {\n time: logs[i][0],\n namespace: logs[i][1],\n level: logs[i][2],\n descriptor: logs[i][3],\n data: logs[i][4]\n };\n }\n readyFn(logs);\n } catch (e) {\n util.throwError('failed to get, ' + e.message);\n readyFn([]);\n }\n }\n\n /**\n * clean logs = keep limited logs\n * @method keep\n * @static\n * @param {Number} daysToMaintain - keep logs within days\n */\n static keep(daysToMaintain) {\n var logs;\n try {\n logs = !daysToMaintain ? [] : (window.localStorage.getItem(LocalStorageLogger._database) ? JSON.parse(window.localStorage.getItem(LocalStorageLogger._database)) : []).filter(log => {\n return log.time >= (Date.now() - (daysToMaintain || 2) * 24 * 3600 * 1000);\n });\n window.localStorage.setItem(LocalStorageLogger._database, JSON.stringify(logs));\n } catch (e) {\n util.throwError('failed to keep, ' + e.message);\n }\n }\n\n /**\n * delete log database\n * @method clean\n * @static\n */\n static clean() {\n try {\n delete LocalStorageLogger.status;\n window.localStorage.removeItem(LocalStorageLogger._database);\n } catch (e) {\n util.throwError('failed to clean, ' + e.message);\n }\n }\n\n /**\n * detect support situation\n * @prop {Boolean} support\n */\n static get support() {\n return 'localStorage' in window;\n }\n}\n","import LoggerInterface from './interface';\nimport Pool from '../lib/pool';\nimport * as util from '../lib/util';\n\n/**\n * Websql protocol\n * @class WebsqlLogger\n */\nexport default class WebsqlLogger extends LoggerInterface {\n /**\n * Websql logline constructor\n * @constructor\n * @param {String} namespace - namespace to use\n */\n constructor(...args) {\n super(...args);\n }\n\n /**\n * add a log record\n * @method _reocrd\n * @private\n * @parma {String} level - log level\n * @param {String} descriptor - to speed up search and improve understanding\n * @param {Mixed} [data] - additional data\n */\n _record(level, descriptor, data) {\n if (WebsqlLogger.status !== LoggerInterface.STATUS.INITED) {\n WebsqlLogger._pool.push(() => this._record(level, descriptor, data));\n if (WebsqlLogger.status !== LoggerInterface.STATUS.INITING) {\n WebsqlLogger.init();\n }\n return;\n }\n\n try {\n util.debug(this._namespace, level, descriptor, data);\n WebsqlLogger._db.transaction(tx => {\n tx.executeSql(\n 'INSERT INTO logs (time, namespace, level, descriptor, data) VALUES(?, ?, ?, ? ,?)',\n [Date.now(), this._namespace, level, descriptor, (data === undefined || data === '') ? '' : (JSON.stringify(data) || '')],\n () => {/* empty func */},\n (tx, e) => { util.throwError('write error, ' + e.message); }\n );\n });\n } catch (e) { util.throwError('error inserting record, ' + e.message); }\n }\n\n /**\n * initialize protocol\n * @method init\n * @static\n * @param {String} database - database name to use\n */\n static init(database) {\n if (!WebsqlLogger.support) {\n util.throwError(new Error('your platform does not support websql protocol.'));\n }\n\n if (WebsqlLogger.status) {\n return false;\n }\n\n WebsqlLogger._pool = WebsqlLogger._pool || new Pool();\n WebsqlLogger._database = database || 'logline';\n WebsqlLogger.status = super.STATUS.INITING;\n\n try {\n WebsqlLogger._db = window.openDatabase(WebsqlLogger._database, '1.0', 'cats loves logs', 4.85 * 1024 * 1024);\n WebsqlLogger._db.transaction(tx => {\n tx.executeSql(\n 'CREATE TABLE IF NOT EXISTS logs (time, namespace, level, descriptor, data)', [],\n () => {\n WebsqlLogger.status = super.STATUS.INITED;\n WebsqlLogger._pool.consume();\n },\n (tx, e) => {\n WebsqlLogger.status = super.STATUS.FAILED;\n util.throwError('unable to create table, ' + e.message);\n }\n );\n });\n } catch (e) { util.throwError('unable to init log database, ' + e.message); }\n }\n\n /**\n * get logs in range\n * if from and end is not defined, will fetch full log\n * @method get\n * @static\n * @param {String} from - time from, unix time stamp or falsy\n * @param {String} to - time end, unix time stamp or falsy\n * @param {Function} readyFn - function to call back with logs as parameter\n */\n static get(from, to, readyFn) {\n if (WebsqlLogger.status !== super.STATUS.INITED) {\n return WebsqlLogger._pool.push(() => WebsqlLogger.get(from, to, readyFn));\n }\n\n from = LoggerInterface.transTimeFormat(from);\n to = LoggerInterface.transTimeFormat(to);\n\n try {\n WebsqlLogger._db.transaction(function(tx) {\n tx.executeSql(\n 'SELECT * FROM logs ORDER BY time DESC', [],\n (tx, res) => {\n var logs = [], line, index = res.rows.length, item;\n while (--index >= 0) {\n item = res.rows.item(index);\n if ((from && item.time < from) || (to && item.time > to)) {\n continue;\n }\n\n // in some devices, properties are configureable: false, writable: false\n // we need deep copy\n line = JSON.parse(JSON.stringify(item));\n // incase data is an object, not a string\n try { line.data = JSON.parse(line.data); }\n catch (e) {/* leave line.data as it be */}\n logs.push(line);\n }\n readyFn(logs);\n },\n (tx, e) => { util.throwError(e.message); }\n );\n });\n } catch (e) { util.throwError('unable to collect logs from database.'); }\n }\n\n /**\n * clean logs = keep limited logs\n * @method keep\n * @static\n * @param {Number} daysToMaintain - keep logs within days\n */\n static keep(daysToMaintain) {\n if (WebsqlLogger.status !== super.STATUS.INITED) {\n return WebsqlLogger._pool.push(() => WebsqlLogger.keep(daysToMaintain));\n }\n\n try {\n WebsqlLogger._db.transaction(function(tx) {\n if (daysToMaintain) {\n tx.executeSql(\n 'DELETE FROM logs WHERE time < ?',\n [Date.now() - (daysToMaintain || 2) * 24 * 3600 * 1000],\n function() { /* empty func */ },\n function(tx, e) { util.throwError(e.message); }\n );\n }\n else {\n tx.executeSql(\n 'DELETE FROM logs', [],\n () => {/* empty func */},\n (tx, e) => { util.throwError(e.message); }\n );\n }\n });\n } catch (e) { util.throwError('unable to clean logs from database.'); }\n }\n\n /**\n * delete log database\n * @method clean\n * @static\n */\n static clean() {\n if (WebsqlLogger.status !== super.STATUS.INITED) {\n WebsqlLogger._pool.push(() => WebsqlLogger.clean());\n return;\n }\n\n try {\n WebsqlLogger._db.transaction(tx => {\n tx.executeSql(\n 'DROP TABLE logs', [],\n () => {\n delete WebsqlLogger.status;\n },\n (tx, e) => { util.throwError(e.message); }\n );\n });\n } catch (e) { util.throwError('unable to clean log database.'); }\n }\n\n /**\n * detect support situation\n * @prop {Boolean} support\n */\n static get support() {\n return 'openDatabase' in window;\n }\n}\n","import Interface from './protocols/interface';\nimport IndexeddbLogger from './protocols/indexeddb';\nimport LocalstorageLogger from './protocols/localstorage';\nimport WebsqlLogger from './protocols/websql';\nimport * as util from './lib/util';\nimport config from './lib/config';\n\n\nclass Logline {\n /**\n * Logline constructor\n * @constructor\n * @param {String} namespace - namespace to use\n * @return {Object Protocol Instance}\n */\n constructor(namespace) {\n if (!(this instanceof Logline)) {\n return new Logline(namespace);\n }\n try {\n Logline._checkProtocol();\n return new Logline._protocol(namespace);\n } catch (e) {\n return new Interface(namespace);\n }\n }\n\n /**\n * change config\n * @method config\n * @param {String|Object} key - config key, or config object\n * @param {Any} [value] - new config value\n * @return {Void}\n */\n static get config() {\n return config;\n }\n\n /**\n * choose a protocol to initialize\n * @method _initProtocol\n * @private\n * @static\n * @param {Object Protocol Class} protocol - protocol to use, must under Logline.PROTOCOL\n * @return {Object} Logline\n */\n static _initProtocol(protocol) {\n Logline._protocol = protocol;\n Logline._protocol.init(Logline._database || 'logline');\n }\n\n /**\n * check protocol\n * if no protocol is chosen, will try to choose an available one automatically\n * if none of the protocols is available, an error will be thrown\n * @method _checkProtocol\n * @private\n * @static\n */\n static _checkProtocol() {\n if (!Logline._protocol) {\n let protocols = Object.keys(Logline.PROTOCOL), protocol;\n while ((protocol = Logline.PROTOCOL[protocols.shift()])) {\n if (protocol.support) {\n Logline._initProtocol(protocol);\n return;\n }\n }\n\n util.throwError('protocols ' + protocols.join(', ').toLowerCase() + ' are not supported on this platform');\n }\n }\n\n /**\n * get logs in range\n * if from and end is not defined, will fetch full log\n * @method get\n * @static\n * @param {String} [from] - time from\n * @param {String} [to] - time end\n * @param {Function} readyFn - function to call back with logs as parameter\n */\n static get(from, to, readyFn) {\n Logline._checkProtocol();\n\n switch (arguments.length) {\n case 1:\n readyFn = from;\n from = undefined;\n break;\n case 2:\n readyFn = to;\n to = undefined;\n break;\n case 3:\n default:\n break;\n }\n\n Logline._protocol.get(from, to, readyFn);\n }\n\n /**\n * read all logs\n * @method all\n * @static\n * @param {Function} readyFn - function to call back with logs as parameter\n */\n static all(readyFn) {\n Logline.get(readyFn);\n }\n\n /**\n * clean up logs = keep limited logs\n * @method keep\n * @static\n * @param {String} daysToMaintain - specialfy days to keep, support human readable format such as '3d', '.3'\n * @return {Object} Logline\n */\n static keep(daysToMaintain) {\n Logline._checkProtocol();\n Logline._protocol.keep(daysToMaintain);\n return this;\n }\n\n /**\n * delete log database\n * @method clean\n * @static\n * @return {Object} Logline\n */\n static clean() {\n Logline._checkProtocol();\n Logline._protocol.clean();\n return this;\n }\n\n /**\n * choose a protocol\n * @method using\n * @static\n * @param {Object Protocol Class} protocol - wanted protocol, should be on of Logline.PROTOCOL\n * @param {String} [database] - custome database name\n * @return {Object} Logline\n */\n static using(protocol, database) {\n // protocol unavailable is not allowed\n if (-1 === [IndexeddbLogger, LocalstorageLogger, WebsqlLogger].indexOf(protocol)) {\n util.throwError('specialfied protocol ' + (protocol ? (protocol + ' ') : '') + 'is not available');\n }\n\n // once protocol is selected, it shall not be changed during runtime\n if (Logline._protocol) {\n return this;\n }\n\n Logline.database(database || Logline._database);\n Logline._initProtocol(protocol);\n return this;\n }\n\n /**\n * specialfy a custome database name, in case of any conflicts\n * @methd database\n * @static\n * @param {String} name - target database name\n */\n static database(name) {\n Logline._database = name;\n }\n}\n\n// export protocols for modification and mounting\nLogline.PROTOCOL = {\n INDEXEDDB: IndexeddbLogger,\n LOCALSTORAGE: LocalstorageLogger,\n WEBSQL: WebsqlLogger\n};\n\n// export protocol interface for user custom implements\nLogline.INTERFACE = Object.freeze(Interface);\n\n// export Logline env, just like Unix Environment variables\nLogline.env = {\n verbose: true\n};\n\nexport default Logline;\n"],"names":["get","key","store","set","value","changes","Object","prototype","toString","call","throwError","errMessage","console","error","debug","namespace","level","descriptor","data","HAS_CONSOLE","config","verbose","LEVEL_CONSOLE_MAP","toUpperCase","INFO","filterFunction","obj","i","newObj","hasOwnProperty","DEFAULT_CONFIG","babelHelpers.extends","window","Interface","_namespace","args","_record","database","time","relative","test","TypeError","Date","now","replace","from","to","readyFn","daysToMaintain","Pool","_pool","handler","context","push","this","shift","IndexedDBLogger","status","LoggerInterface","STATUS","INITED","_this2","INITING","init","transaction","db","IDBTransaction","READ_WRITE","onerror","util","event","target","objectStore","add","FAILED","e","message","support","_database","babelHelpers.get","request","indexedDB","open","onsuccess","result","consume","onupgradeneeded","createObjectStore","autoIncrement","createIndex","unique","transTimeFormat","_getTransactionStore","READ_ONLY","getAll","logs","length","openCursor","cursor","continue","keep","range","delete","primaryKey","clear","clean","close","deleteDatabase","mode","IDBKeyRange","LocalStorageLogger","localStorage","getItem","JSON","parse","setItem","stringify","filter","log","removeItem","WebsqlLogger","_db","executeSql","undefined","tx","Error","openDatabase","res","line","item","index","rows","Logline","_checkProtocol","_protocol","protocol","protocols","keys","PROTOCOL","_initProtocol","join","toLowerCase","arguments","IndexeddbLogger","LocalstorageLogger","indexOf","name","INTERFACE","freeze","env"],"mappings":"kLAMA,SAAgBA,GAAIC,SACTA,GAAMC,EAAMD,GAAOC,EAG9B,QAAgBC,GAAIF,EAAKG,MACjBC,KACe,iBAARJ,KACCA,GAAOG,EACgC,oBAAxCE,OAAOC,UAAUC,SAASC,KAAKR,OAC5BA,KAEAC,EAAOG,GCNzB,QAAgBK,GAAWC,MACRC,QAAQC,MAAM,YAAcF,GAK/C,QAAgBG,GAAMC,EAAWC,EAAOC,EA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,EAAEC,aAI7C,MAAOD,KAAqB,2EAS1B6C,EAAa/D,SAAWsB,uDAAanB,qBACxBV,MAAMG,KAAK,iBAAMmE,GAAaf,gBAK9BgB,IAAIzD,YAAY,cACtB0D,WACC,qBACA,iBACWF,GAAa/D,QAExB,SAACmE,EAAIjD,KAAwBA,EAAEC,aAGzC,MAAOD,KAAqB,wEAQvB,gBAAkB3C,eAvLS0B,GCApC0E,wBAOUrH,kBACFuC,eAAgB8E,UACX,IAAIA,GAAQrH,gBAGXsH,iBACD,GAAID,GAAQE,UAAUvH,GAC/B,MAAO4D,SACE,IAAI1C,GAAUlB,yDAuBRwH,KACTD,UAAYC,IACZD,UAAUvE,KAAKqE,EAAQtD,WAAa,wDAYvCsD,EAAQE,UAAW,QAChBE,GAAYlI,OAAOmI,KAAKL,EAAQM,UAAWH,SACvCA,EAAWH,EAAQM,SAASF,EAAUjF,aACtCgF,EAAS1D,sBACD8D,cAAcJ,KAKd,aAAeC,EAAUI,KAAK,MAAMC,cAAgB,oEAajEhG,EAAMC,EAAIC,YACTsF,iBAEAS,UAAU9C,YACT,KACSnD,QACH8E,aAEN,KACS7E,QACL6E,KAOLW,UAAUtI,IAAI6C,EAAMC,EAAIC,+BASzBA,KACC/C,IAAI+C,gCAUJC,YACAqF,mBACAC,UAAUlC,KAAKpD,GAChBM,8CAUC+E,mBACAC,UAAU7B,QACXnD,mCAWEiF,EAAUlG,UAEd,KAAO0G,EAAiBC,EAAoBxB,GAAcyB,QAAQV,MACnD,yBAA2BA,EAAYA,EAAW,IAAO,IAAM,oBAI/EH,EAAQE,UACDhF,QAGHjB,SAASA,GAAY+F,EAAQtD,aAC7B6D,cAAcJ,GACfjF,uCASK4F,KACJpE,UAAYoE,uCArIb9H,kBA0IfgH,GAAQM,oBACOK,eACGC,SACNxB,GAIZY,EAAQe,UAAY7I,OAAO8I,OAAOnH,GAGlCmG,EAAQiB,cACK"} \ No newline at end of file +{"version":3,"file":"logline.min.js","sources":["../src/lib/config.js","../src/lib/util.js","../src/protocols/interface.js","../src/lib/pool.js","../src/protocols/indexeddb.js","../src/protocols/localstorage.js","../src/protocols/websql.js","../src/logline.js"],"sourcesContent":["const DEFAULT_CONFIG = {\n verbose: true\n};\n\nlet store = Object.assign({}, DEFAULT_CONFIG);\n\nexport function get(key) {\n return key ? store[key] : store;\n}\n\nexport function set(key, value) {\n let changes = {};\n if (typeof key === 'string') {\n changes[key] = value;\n } else if (Object.prototype.toString.call(key) === '[object Object]') {\n changes = key;\n }\n Object.assign(store, changes);\n}\n\nlet config = set;\nconfig.set = set;\nconfig.get = get;\n\nexport default config;\n","import config from './config';\n\nconst HAS_CONSOLE = window.console;\nconst LEVEL_CONSOLE_MAP = {\n INFO: 'log',\n WARN: 'warn',\n ERROR: 'error',\n CRITICAL: 'error'\n};\n\n// throw out Errors, with global prefix 'Logline: ' ahead of err.message\nexport function throwError(errMessage) {\n HAS_CONSOLE && console.error('Logline: ' + errMessage);\n}\n\n// print debug info in develper's console\n// TODO: if WechatFE/vConsole is detected, will not use %c feature, as it is not well supported\nexport function debug(namespace, level, descriptor, data) {\n if (HAS_CONSOLE && config.get().verbose) {\n window.console[LEVEL_CONSOLE_MAP[level.toUpperCase()] || LEVEL_CONSOLE_MAP.INFO](`${namespace} ${level.toUpperCase()} ${descriptor}`, data || '');\n }\n}\n\n// filter any function in a object\nexport function filterFunction(obj) {\n var newObj = {}, i;\n\n if (typeof obj !== 'object') {\n return obj;\n }\n\n for (i in obj) {\n if (obj.hasOwnProperty(i)) {\n if (typeof obj[i] !== 'function') {\n newObj[i] = filterFunction(obj[i]);\n }\n }\n }\n return newObj;\n}\n","import * as util from '../lib/util';\n\n/**\n * Logline Interface\n * @class Interface\n */\nexport default class Interface {\n /**\n * Logline constructor\n * @constructor\n * @param {String} namespace - namespace to use\n */\n constructor(namespace) {\n this._namespace = namespace;\n }\n\n /**\n * add a log record\n * @method _reocrd\n * @private\n * @parma {String} level - log level\n * @param {String} descriptor - to speed up search and improve understanding\n * @param {Mixed} [data] - additional data\n */\n _record(level, descriptor, data) {\n util.throwError('method _record is not implemented.');\n }\n\n /**\n * add a level-info record\n * @method info\n * @param {String} descriptor - to speed up search and improve understanding\n * @param {Mixed} [data] - additional data\n */\n info(...args) {\n this._record('info', ...args);\n }\n\n /**\n * add a level-warn record\n * @method warn\n * @param {String} descriptor - to speed up search and improve understanding\n * @param {Mixed} [data] - additional data\n */\n warn(...args) {\n this._record('warn', ...args);\n }\n\n /**\n * add a level-error record\n * @method error\n * @param {String} descriptor - to speed up search and improve understanding\n * @param {Mixed} [data] - additional data\n */\n error(...args) {\n this._record('error', ...args);\n }\n\n /**\n * add a level-critical record\n * @method critical\n * @param {String} descriptor - to speed up search and improve understanding\n * @param {Mixed} [data] - additional data\n */\n critical(...args) {\n this._record('critical', ...args);\n }\n\n /**\n * initialize protocol\n * @method init\n * @static\n * @param {String} database - database name to use\n */\n static init(database) {\n return true;\n }\n\n /**\n * transform human readable time string, such as '3d', '.3' and '1.2' into Unix timestamp\n * the default relative time is Date.now(), if no second parameter is provided\n * @method transTimeFormat\n * @static\n * @param {String} time - time string to transform\n * @param {Number} [relative] - relative time to compare, default Date.now()\n * @return {Number|NaN} timestamp transformed\n */\n static transTimeFormat(time, relative) {\n // if falsy value or timestamp already, pass it through directly,\n if (!time || /^\\d{13}$/.test(time)) {\n return +time;\n }\n // incase relative time isn't unix timestamp format,\n // neither a falsy value which will turned out to be Date.now()\n if (relative && !/^\\d{13}$/.test(relative)) {\n throw new TypeError('relative time should be standard unix timestamp');\n }\n\n return (relative || Date.now()) - time.replace(/d$/, '') * 24 * 3600 * 1000;\n }\n\n /**\n * get logs in range\n * if from and end is not defined, will fetch full log\n * @method get\n * @static\n * @param {String} from - time from, unix timestamp\n * @param {String} to - time end, unix timestamp\n * @param {Function} readyFn - function to call back with logs as parameter\n */\n static get(from, to, readyFn) {\n util.throwError('method get is not implemented.');\n }\n\n /**\n * clean logs = keep limited logs\n * @method keep\n * @static\n * @param {Number} daysToMaintain - keep logs within days\n */\n static keep(daysToMaintain) {\n util.throwError('method keep is not implemented.');\n }\n\n /**\n * delete log database\n * @method clean\n * @static\n */\n static clean() {\n util.throwError('method clean is not implemented.');\n }\n\n /**\n * protocol status map\n * @prop {Object} STATUS\n */\n static get STATUS() {\n return {\n INITING: 1,\n INITED: 2,\n FAILED: 4\n };\n }\n}\n","/**\n * Pool, for storage of async calling\n * @class Pool\n */\nexport default class Pool {\n /**\n * Pool constructor\n * @constructor\n */\n constructor() {\n this._pool = [];\n }\n\n /**\n * add an procedure\n * @method push\n * @param {Function} handler - procedure handler\n * @param {Object} context - procedure context\n */\n push(handler, context) {\n handler.context = context;\n this._pool.push(handler);\n }\n\n /**\n * consume pool\n * @method consume\n */\n consume() {\n var handler;\n while ((handler = this._pool.shift())) {\n handler.call(handler.context);\n }\n }\n}\n","import LoggerInterface from './interface';\nimport Pool from '../lib/pool';\nimport * as util from '../lib/util';\n\nconst READ_WRITE = 'readwrite';\n\n/**\n * IndexedDB protocol\n * @class IndexedDBLogger\n */\nexport default class IndexedDBLogger extends LoggerInterface {\n /**\n * IndexedDB protocol constructor\n * @constructor\n * @param {String} namespace - namespace to use\n */\n constructor(...args) {\n super(...args);\n }\n\n /**\n * add a log record\n * @method _reocrd\n * @private\n * @parma {String} level - log level\n * @param {String} descriptor - to speed up search and improve understanding\n * @param {Mixed} [data] - additional data\n */\n _record(level, descriptor, data) {\n try {\n if (IndexedDBLogger.status !== LoggerInterface.STATUS.INITED) {\n IndexedDBLogger._pool.push(() => this._record(level, descriptor, data));\n if (IndexedDBLogger.status !== LoggerInterface.STATUS.INITING) {\n IndexedDBLogger.init();\n }\n return;\n }\n\n util.debug(this._namespace, level, descriptor, data);\n let transaction = IndexedDBLogger.db.transaction(['logs'], READ_WRITE || 'readwrite');\n transaction.onerror = event => util.throwError(event.target.error);\n\n let store = transaction.objectStore('logs');\n // should not contains any function in data\n // otherwise 'DOMException: Failed to execute 'add' on 'IDBObjectStore': An object could not be cloned.' will be thrown\n let request = store.add({\n time: Date.now(),\n level: level,\n namespace: this._namespace,\n descriptor: descriptor,\n data: util.filterFunction(data)\n });\n\n request.onerror = event => {\n IndexedDBLogger.status = LoggerInterface.STATUS.FAILED;\n util.throwError(event.target.error);\n };\n } catch (e) {\n util.throwError('failed to write, ' + e.message);\n }\n }\n\n /**\n * initialize protocol\n * @method init\n * @static\n * @param {String} database - database name to use\n */\n static init(database) {\n try {\n if (!IndexedDBLogger.support) {\n util.throwError('your platform does not support indexeddb protocol.');\n }\n\n if (IndexedDBLogger.status) {\n return false;\n }\n\n IndexedDBLogger._pool = IndexedDBLogger._pool || new Pool();\n IndexedDBLogger._database = database || 'logline';\n IndexedDBLogger.status = super.STATUS.INITING;\n\n IndexedDBLogger.request = window.indexedDB.open(IndexedDBLogger._database);\n IndexedDBLogger.request.onerror = event => util.throwError('protocol indexeddb is prevented.');\n IndexedDBLogger.request.onsuccess = event => {\n IndexedDBLogger.db = event.target.result;\n IndexedDBLogger.status = super.STATUS.INITED;\n IndexedDBLogger._pool.consume();\n // globally handle db request errors\n IndexedDBLogger.db.onerror = event => util.throwError(event.target.error);\n };\n IndexedDBLogger.request.onupgradeneeded = event => {\n // init dabasebase\n let db = event.target.result, store = db.createObjectStore('logs', { autoIncrement: true });\n store.createIndex('namespace', 'namespace', { unique: false });\n store.createIndex('level', 'level', { unique: false });\n store.createIndex('descriptor', 'descriptor', { unique: false });\n store.createIndex('data', 'data', { unique: false });\n };\n } catch (e) {\n util.throwError('failed init, ' + e.message);\n }\n }\n\n /**\n * get logs in range\n * if from and end is not defined, will fetch full log\n * @method get\n * @static\n * @param {String} [from] - time from, unix time stamp or falsy\n * @param {String} [to] - time end, unix time stamp or falsy\n * @param {Function} readyFn - function to call back with logs as parameter\n */\n static get(from, to, readyFn) {\n try {\n if (IndexedDBLogger.status !== super.STATUS.INITED) {\n return IndexedDBLogger._pool.push(() => IndexedDBLogger.get(from, to, readyFn));\n }\n\n from = LoggerInterface.transTimeFormat(from);\n to = LoggerInterface.transTimeFormat(to);\n\n let store = IndexedDBLogger._getTransactionStore(IDBTransaction.READ_ONLY);\n if (!store) {\n return readyFn([]);\n }\n\n // IDBObjectStore.getAll is a non-standard API\n if (store.getAll) {\n let result, logs = [];\n store.getAll().onsuccess = event => {\n result = event.target.result;\n for (let i = 0; i < result.length; i++) {\n if ((from && result[i].time < from) || (to && result[i].time > to)) {\n continue;\n }\n logs.push(result[i]);\n }\n readyFn(logs);\n };\n } else {\n let request = store.openCursor(), logs = [];\n request.onsuccess = event => {\n var cursor = event.target.result;\n if (cursor) {\n if ((from && cursor.value.time < from) || (to && cursor.value.time > to)) {\n return cursor.continue();\n }\n\n logs.push({\n time: cursor.value.time,\n level: cursor.value.level,\n namespace: cursor.value.namespace,\n descriptor: cursor.value.descriptor,\n data: cursor.value.data\n });\n cursor.continue();\n }\n else {\n readyFn(logs);\n }\n };\n }\n } catch (e) {\n util.throwError('failed to get logs, ' + e.message);\n }\n }\n\n /**\n * clean logs = keep limited logs\n * @method keep\n * @static\n * @param {Number} daysToMaintain - keep logs within days\n */\n static keep(daysToMaintain) {\n try {\n if (IndexedDBLogger.status !== super.STATUS.INITED) {\n return IndexedDBLogger._pool.push(() => IndexedDBLogger.keep(daysToMaintain));\n }\n\n let store = IndexedDBLogger._getTransactionStore(READ_WRITE);\n if (!store) {\n return false;\n }\n if (!daysToMaintain) {\n let request = store.clear().onerror = event => util.throwError(event.target.error);\n }\n else {\n let range = (Date.now() - (daysToMaintain || 2) * 24 * 3600 * 1000);\n let request = store.openCursor();\n request.onsuccess = event => {\n let cursor = event.target.result;\n if (cursor && cursor.value.time < range) {\n store.delete(cursor.primaryKey);\n cursor.continue();\n }\n };\n request.onerror = event => util.throwError('unable to locate logs earlier than ' + daysToMaintain + 'd.');\n }\n } catch (e) {\n util.throwError('failed to keep logs, ' + e.message);\n }\n }\n\n /**\n * delete log database\n * @method clean\n * @static\n */\n static clean() {\n try {\n if (IndexedDBLogger.status !== super.STATUS.INITED) {\n return IndexedDBLogger._pool.push(() => IndexedDBLogger.clean());\n }\n\n // database can be removed only after all connections are closed\n IndexedDBLogger.db.close();\n let request = window.indexedDB.deleteDatabase(IndexedDBLogger._database);\n request.onerror = event => util.throwError(event.target.error);\n /* eslint no-unused-vars: \"off\" */\n request.onsuccess = event => {\n delete IndexedDBLogger.status;\n delete IndexedDBLogger.db;\n };\n } catch (e) {\n util.throwError('failed to cleanup logs, ' + e.message);\n }\n }\n\n /**\n * get internal transaction store\n * @method _getTransactionStore\n * @private\n * @static\n * @param {String} mode - transaction mode\n * @return {Object} - internal object store\n */\n static _getTransactionStore(mode) {\n try {\n if (IndexedDBLogger.db) {\n let transaction = IndexedDBLogger.db.transaction(['logs'], mode || READ_WRITE);\n transaction.onerror = event => util.throwError(event.target.error);\n return transaction.objectStore('logs');\n }\n else {\n util.throwError('log database is not created or connections are closed, considering init it.');\n }\n } catch (e) {\n util.throwError('failed to generate new transaction, ' + e.message);\n return false;\n }\n }\n\n /**\n * detect support situation\n * @prop {Boolean} support\n */\n static get support() {\n const support = !!(window.indexedDB && window.IDBTransaction && window.IDBKeyRange);\n return support;\n }\n}\n","import LoggerInterface from './interface';\nimport * as util from '../lib/util';\n\n/**\n * Localstorage protocol\n * @class LocalStorageLogger\n */\nexport default class LocalStorageLogger extends LoggerInterface {\n /**\n * Localstorage protocol constructor\n * @constructor\n * @param {String} namespace - namespace to use\n */\n constructor(...args) {\n super(...args);\n }\n\n /**\n * add a log record\n * @method _reocrd\n * @private\n * @parma {String} level - log level\n * @param {String} descriptor - to speed up search and improve understanding\n * @param {Mixed} [data] - additional data\n */\n _record(level, descriptor, data) {\n var logs;\n try {\n logs = window.localStorage.getItem(LocalStorageLogger._database) ? JSON.parse(window.localStorage.getItem(LocalStorageLogger._database)) : [];\n logs.push([\n Date.now(),\n this._namespace,\n level,\n descriptor,\n data\n ]);\n util.debug(this._namespace, level, descriptor, data);\n window.localStorage.setItem(LocalStorageLogger._database, JSON.stringify(logs));\n } catch (e) { util.throwError('failed to write, ' + e.message); }\n }\n\n /**\n * initialize protocol\n * @method init\n * @static\n * @param {String} database - database name to use\n */\n static init(database) {\n try {\n if (!LocalStorageLogger.support) {\n util.throwError('your platform does not support localstorage protocol.');\n }\n LocalStorageLogger._database = database || 'logline';\n if (!window.localStorage.getItem(LocalStorageLogger._database)) {\n window.localStorage.setItem(LocalStorageLogger._database, JSON.stringify([]));\n }\n LocalStorageLogger.status = super.STATUS.INITED;\n } catch (e) {\n util.throwError('failed to init, ' + e.message);\n }\n }\n\n /**\n * get logs in range\n * if from and end is not defined, will fetch full log\n * @method get\n * @static\n * @param {String} from - time from, unix time stamp or falsy\n * @param {String} to - time end, unix time stamp or falsy\n * @param {Function} readyFn - function to call back with logs as parameter\n */\n static get(from, to, readyFn) {\n var logs, i;\n try {\n logs = JSON.parse(window.localStorage.getItem(LocalStorageLogger._database));\n\n from = LoggerInterface.transTimeFormat(from);\n to = LoggerInterface.transTimeFormat(to);\n\n for (i = 0; i < logs.length; i++) {\n if ((from && logs[i][0] < from) || (to && logs[i][0] > to)) {\n continue;\n }\n\n logs[i] = {\n time: logs[i][0],\n namespace: logs[i][1],\n level: logs[i][2],\n descriptor: logs[i][3],\n data: logs[i][4]\n };\n }\n readyFn(logs);\n } catch (e) {\n util.throwError('failed to get, ' + e.message);\n readyFn([]);\n }\n }\n\n /**\n * clean logs = keep limited logs\n * @method keep\n * @static\n * @param {Number} daysToMaintain - keep logs within days\n */\n static keep(daysToMaintain) {\n var logs;\n try {\n logs = !daysToMaintain ? [] : (window.localStorage.getItem(LocalStorageLogger._database) ? JSON.parse(window.localStorage.getItem(LocalStorageLogger._database)) : []).filter(log => {\n return log.time >= (Date.now() - (daysToMaintain || 2) * 24 * 3600 * 1000);\n });\n window.localStorage.setItem(LocalStorageLogger._database, JSON.stringify(logs));\n } catch (e) {\n util.throwError('failed to keep, ' + e.message);\n }\n }\n\n /**\n * delete log database\n * @method clean\n * @static\n */\n static clean() {\n try {\n delete LocalStorageLogger.status;\n window.localStorage.removeItem(LocalStorageLogger._database);\n } catch (e) {\n util.throwError('failed to clean, ' + e.message);\n }\n }\n\n /**\n * detect support situation\n * @prop {Boolean} support\n */\n static get support() {\n return 'localStorage' in window;\n }\n}\n","import LoggerInterface from './interface';\nimport Pool from '../lib/pool';\nimport * as util from '../lib/util';\n\n/**\n * Websql protocol\n * @class WebsqlLogger\n */\nexport default class WebsqlLogger extends LoggerInterface {\n /**\n * Websql logline constructor\n * @constructor\n * @param {String} namespace - namespace to use\n */\n constructor(...args) {\n super(...args);\n }\n\n /**\n * add a log record\n * @method _reocrd\n * @private\n * @parma {String} level - log level\n * @param {String} descriptor - to speed up search and improve understanding\n * @param {Mixed} [data] - additional data\n */\n _record(level, descriptor, data) {\n if (WebsqlLogger.status !== LoggerInterface.STATUS.INITED) {\n WebsqlLogger._pool.push(() => this._record(level, descriptor, data));\n if (WebsqlLogger.status !== LoggerInterface.STATUS.INITING) {\n WebsqlLogger.init();\n }\n return;\n }\n\n try {\n util.debug(this._namespace, level, descriptor, data);\n WebsqlLogger._db.transaction(tx => {\n tx.executeSql(\n 'INSERT INTO logs (time, namespace, level, descriptor, data) VALUES(?, ?, ?, ? ,?)',\n [Date.now(), this._namespace, level, descriptor, (data === undefined || data === '') ? '' : (JSON.stringify(data) || '')],\n () => {/* empty func */},\n (tx, e) => { util.throwError('write error, ' + e.message); }\n );\n });\n } catch (e) { util.throwError('error inserting record, ' + e.message); }\n }\n\n /**\n * initialize protocol\n * @method init\n * @static\n * @param {String} database - database name to use\n */\n static init(database) {\n if (!WebsqlLogger.support) {\n util.throwError(new Error('your platform does not support websql protocol.'));\n }\n\n if (WebsqlLogger.status) {\n return false;\n }\n\n WebsqlLogger._pool = WebsqlLogger._pool || new Pool();\n WebsqlLogger._database = database || 'logline';\n WebsqlLogger.status = super.STATUS.INITING;\n\n try {\n WebsqlLogger._db = window.openDatabase(WebsqlLogger._database, '1.0', 'cats loves logs', 4.85 * 1024 * 1024);\n WebsqlLogger._db.transaction(tx => {\n tx.executeSql(\n 'CREATE TABLE IF NOT EXISTS logs (time, namespace, level, descriptor, data)', [],\n () => {\n WebsqlLogger.status = super.STATUS.INITED;\n WebsqlLogger._pool.consume();\n },\n (tx, e) => {\n WebsqlLogger.status = super.STATUS.FAILED;\n util.throwError('unable to create table, ' + e.message);\n }\n );\n });\n } catch (e) { util.throwError('unable to init log database, ' + e.message); }\n }\n\n /**\n * get logs in range\n * if from and end is not defined, will fetch full log\n * @method get\n * @static\n * @param {String} from - time from, unix time stamp or falsy\n * @param {String} to - time end, unix time stamp or falsy\n * @param {Function} readyFn - function to call back with logs as parameter\n */\n static get(from, to, readyFn) {\n if (WebsqlLogger.status !== super.STATUS.INITED) {\n return WebsqlLogger._pool.push(() => WebsqlLogger.get(from, to, readyFn));\n }\n\n from = LoggerInterface.transTimeFormat(from);\n to = LoggerInterface.transTimeFormat(to);\n\n try {\n WebsqlLogger._db.transaction(function(tx) {\n tx.executeSql(\n 'SELECT * FROM logs ORDER BY time DESC', [],\n (tx, res) => {\n var logs = [], line, index = res.rows.length, item;\n while (--index >= 0) {\n item = res.rows.item(index);\n if ((from && item.time < from) || (to && item.time > to)) {\n continue;\n }\n\n // in some devices, properties are configureable: false, writable: false\n // we need deep copy\n line = JSON.parse(JSON.stringify(item));\n // incase data is an object, not a string\n try { line.data = JSON.parse(line.data); }\n catch (e) {/* leave line.data as it be */}\n logs.push(line);\n }\n readyFn(logs);\n },\n (tx, e) => { util.throwError(e.message); }\n );\n });\n } catch (e) { util.throwError('unable to collect logs from database.'); }\n }\n\n /**\n * clean logs = keep limited logs\n * @method keep\n * @static\n * @param {Number} daysToMaintain - keep logs within days\n */\n static keep(daysToMaintain) {\n if (WebsqlLogger.status !== super.STATUS.INITED) {\n return WebsqlLogger._pool.push(() => WebsqlLogger.keep(daysToMaintain));\n }\n\n try {\n WebsqlLogger._db.transaction(function(tx) {\n if (daysToMaintain) {\n tx.executeSql(\n 'DELETE FROM logs WHERE time < ?',\n [Date.now() - (daysToMaintain || 2) * 24 * 3600 * 1000],\n function() { /* empty func */ },\n function(tx, e) { util.throwError(e.message); }\n );\n }\n else {\n tx.executeSql(\n 'DELETE FROM logs', [],\n () => {/* empty func */},\n (tx, e) => { util.throwError(e.message); }\n );\n }\n });\n } catch (e) { util.throwError('unable to clean logs from database.'); }\n }\n\n /**\n * delete log database\n * @method clean\n * @static\n */\n static clean() {\n if (WebsqlLogger.status !== super.STATUS.INITED) {\n WebsqlLogger._pool.push(() => WebsqlLogger.clean());\n return;\n }\n\n try {\n WebsqlLogger._db.transaction(tx => {\n tx.executeSql(\n 'DROP TABLE logs', [],\n () => {\n delete WebsqlLogger.status;\n },\n (tx, e) => { util.throwError(e.message); }\n );\n });\n } catch (e) { util.throwError('unable to clean log database.'); }\n }\n\n /**\n * detect support situation\n * @prop {Boolean} support\n */\n static get support() {\n return 'openDatabase' in window;\n }\n}\n","import Interface from './protocols/interface';\nimport IndexeddbLogger from './protocols/indexeddb';\nimport LocalstorageLogger from './protocols/localstorage';\nimport WebsqlLogger from './protocols/websql';\nimport * as util from './lib/util';\nimport config from './lib/config';\n\n\nclass Logline {\n /**\n * Logline constructor\n * @constructor\n * @param {String} namespace - namespace to use\n * @return {Object Protocol Instance}\n */\n constructor(namespace) {\n if (!(this instanceof Logline)) {\n return new Logline(namespace);\n }\n try {\n Logline._checkProtocol();\n return new Logline._protocol(namespace);\n } catch (e) {\n return new Interface(namespace);\n }\n }\n\n /**\n * change config\n * @method config\n * @param {String|Object} key - config key, or config object\n * @param {Any} [value] - new config value\n * @return {Void}\n */\n static get config() {\n return config;\n }\n\n /**\n * choose a protocol to initialize\n * @method _initProtocol\n * @private\n * @static\n * @param {Object Protocol Class} protocol - protocol to use, must under Logline.PROTOCOL\n * @return {Object} Logline\n */\n static _initProtocol(protocol) {\n Logline._protocol = protocol;\n Logline._protocol.init(Logline._database || 'logline');\n }\n\n /**\n * check protocol\n * if no protocol is chosen, will try to choose an available one automatically\n * if none of the protocols is available, an error will be thrown\n * @method _checkProtocol\n * @private\n * @static\n */\n static _checkProtocol() {\n if (!Logline._protocol) {\n let protocols = Object.keys(Logline.PROTOCOL), protocol;\n while ((protocol = Logline.PROTOCOL[protocols.shift()])) {\n if (protocol.support) {\n Logline._initProtocol(protocol);\n return;\n }\n }\n\n util.throwError('protocols ' + protocols.join(', ').toLowerCase() + ' are not supported on this platform');\n }\n }\n\n /**\n * get logs in range\n * if from and end is not defined, will fetch full log\n * @method get\n * @static\n * @param {String} [from] - time from\n * @param {String} [to] - time end\n * @param {Function} readyFn - function to call back with logs as parameter\n */\n static get(from, to, readyFn) {\n Logline._checkProtocol();\n\n switch (arguments.length) {\n case 1:\n readyFn = from;\n from = undefined;\n break;\n case 2:\n readyFn = to;\n to = undefined;\n break;\n case 3:\n default:\n break;\n }\n\n Logline._protocol.get(from, to, readyFn);\n }\n\n /**\n * read all logs\n * @method all\n * @static\n * @param {Function} readyFn - function to call back with logs as parameter\n */\n static all(readyFn) {\n Logline.get(readyFn);\n }\n\n /**\n * clean up logs = keep limited logs\n * @method keep\n * @static\n * @param {String} daysToMaintain - specialfy days to keep, support human readable format such as '3d', '.3'\n * @return {Object} Logline\n */\n static keep(daysToMaintain) {\n Logline._checkProtocol();\n Logline._protocol.keep(daysToMaintain);\n return this;\n }\n\n /**\n * delete log database\n * @method clean\n * @static\n * @return {Object} Logline\n */\n static clean() {\n Logline._checkProtocol();\n Logline._protocol.clean();\n return this;\n }\n\n /**\n * choose a protocol\n * @method using\n * @static\n * @param {Object Protocol Class} protocol - wanted protocol, should be on of Logline.PROTOCOL\n * @param {String} [database] - custome database name\n * @return {Object} Logline\n */\n static using(protocol, database) {\n // protocol unavailable is not allowed\n if (-1 === [IndexeddbLogger, LocalstorageLogger, WebsqlLogger].indexOf(protocol)) {\n util.throwError('specialfied protocol ' + (protocol ? (protocol + ' ') : '') + 'is not available');\n }\n\n // once protocol is selected, it shall not be changed during runtime\n if (Logline._protocol) {\n return this;\n }\n\n Logline.database(database || Logline._database);\n Logline._initProtocol(protocol);\n return this;\n }\n\n /**\n * specialfy a custome database name, in case of any conflicts\n * @methd database\n * @static\n * @param {String} name - target database name\n */\n static database(name) {\n Logline._database = name;\n }\n}\n\n// export protocols for modification and mounting\nLogline.PROTOCOL = {\n INDEXEDDB: IndexeddbLogger,\n LOCALSTORAGE: LocalstorageLogger,\n WEBSQL: WebsqlLogger\n};\n\n// export protocol interface for user custom implements\nLogline.INTERFACE = Object.freeze(Interface);\n\n// export Logline env, just like Unix Environment variables\nLogline.env = {\n verbose: true\n};\n\nexport default Logline;\n"],"names":["get","key","store","set","value","changes","Object","prototype","toString","call","throwError","errMessage","console","error","debug","namespace","level","descriptor","data","HAS_CONSOLE","config","verbose","LEVEL_CONSOLE_MAP","toUpperCase","INFO","filterFunction","obj","i","newObj","hasOwnProperty","DEFAULT_CONFIG","babelHelpers.extends","window","Interface","_namespace","args","_record","database","time","relative","test","TypeError","Date","now","replace","from","to","readyFn","daysToMaintain","Pool","_pool","handler","context","push","this","shift","IndexedDBLogger","status","LoggerInterface","STATUS","INITED","_this2","INITING","init","transaction","db","onerror","util","event","target","objectStore","add","FAILED","e","message","support","_database","babelHelpers.get","request","indexedDB","open","onsuccess","result","consume","onupgradeneeded","createObjectStore","autoIncrement","createIndex","unique","transTimeFormat","_getTransactionStore","IDBTransaction","READ_ONLY","getAll","logs","length","openCursor","cursor","continue","keep","range","delete","primaryKey","clear","clean","close","deleteDatabase","mode","IDBKeyRange","LocalStorageLogger","localStorage","getItem","JSON","parse","setItem","stringify","filter","log","removeItem","WebsqlLogger","_db","executeSql","undefined","tx","Error","openDatabase","res","line","item","index","rows","Logline","_checkProtocol","_protocol","protocol","protocols","keys","PROTOCOL","_initProtocol","join","toLowerCase","arguments","IndexeddbLogger","LocalstorageLogger","indexOf","name","INTERFACE","freeze","env"],"mappings":"kLAMA,SAAgBA,GAAIC,SACTA,GAAMC,EAAMD,GAAOC,EAG9B,QAAgBC,GAAIF,EAAKG,MACjBC,KACe,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,GAGlCkG,EAAQiB,cACK"} \ No newline at end of file diff --git a/package.json b/package.json index 79fa5a9..bbae714 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "logline", - "version": "1.1.1", + "version": "1.1.2", "description": "logs for the frontend", "main": "dist/logline.min.js", "scripts": { @@ -31,6 +31,7 @@ "homepage": "https://github.com/latel/logline#readme", "devDependencies": { "babel-core": "^6.7.7", + "babel-plugin-external-helpers": "^6.22.0", "babel-plugin-transform-object-assign": "^6.22.0", "babel-preset-env": "^1.7.0", "chai": "^3.5.0", @@ -42,11 +43,13 @@ "gulp-compile-handlebars": "^0.6.1", "gulp-rename": "^1.2.2", "html-loader": "^0.4.3", + "install": "^0.12.1", "jsonfile": "^2.4.0", "minimist": "^1.2.0", "mocha": "^2.5.3", "mocha-headless-chrome": "1.7.1", "moment": "^2.13.0", + "npm": "^6.4.1", "rollup": "^0.41.4", "rollup-plugin-babel": "^2.7.1", "rollup-plugin-license": "^0.2.0", diff --git a/test/tests.js b/test/tests.js index 13b970c..7344134 100644 --- a/test/tests.js +++ b/test/tests.js @@ -5,7 +5,8 @@ Logline.config({ }); var readyTimer, repeated, isReady = function(readyFn) { - clearInterval(readyTimer), repeated = 0; + clearInterval(readyTimer); + repeated = 0; readyTimer = setInterval(function() { var ready = 0, i; if (repeated++ > 20) { @@ -58,10 +59,12 @@ describe('Logline', function() { it('should be able to specialfy any available protocols', function(done) { for (var i = 0; i < Object.keys(window.Logline.PROTOCOL).length; i++) { - window.Logline.using(window.Logline.PROTOCOL[Object.keys(window.Logline.PROTOCOL)[i]]); - assert.equal(window.Logline._protocol, window.Logline.PROTOCOL[Object.keys(window.Logline.PROTOCOL)[i]], 'protocol should be properly setted'); - window.Logline.PROTOCOL[Object.keys(window.Logline.PROTOCOL)[i]].clean(); - delete window.Logline._protocol; + if (window.Logline.PROTOCOL[Object.keys(window.Logline.PROTOCOL)[i]].support) { + window.Logline.using(window.Logline.PROTOCOL[Object.keys(window.Logline.PROTOCOL)[i]]); + assert.equal(window.Logline._protocol, window.Logline.PROTOCOL[Object.keys(window.Logline.PROTOCOL)[i]], 'protocol should be properly setted'); + window.Logline.PROTOCOL[Object.keys(window.Logline.PROTOCOL)[i]].clean(); + delete window.Logline._protocol; + } } done(); }); @@ -69,12 +72,14 @@ describe('Logline', function() { it('should be able to create any available protocols instance', function(done) { isReady(function() { for (var i = 0; i < Object.keys(window.Logline.PROTOCOL).length; i++) { - window.Logline.using(window.Logline.PROTOCOL[Object.keys(window.Logline.PROTOCOL)[i]]); - var logger = new window.Logline('a'); - assert.equal(window.Logline._protocol, window.Logline.PROTOCOL[Object.keys(window.Logline.PROTOCOL)[i]], 'protocol should be properly setted'); - assert.instanceOf(logger, window.Logline.PROTOCOL[Object.keys(window.Logline.PROTOCOL)[i]], 'log instance should be correctly created'); - window.Logline.PROTOCOL[Object.keys(window.Logline.PROTOCOL)[i]].clean(); - delete window.Logline._protocol; + if (window.Logline.PROTOCOL[Object.keys(window.Logline.PROTOCOL)[i]].support) { + window.Logline.using(window.Logline.PROTOCOL[Object.keys(window.Logline.PROTOCOL)[i]]); + var logger = new window.Logline('a'); + assert.equal(window.Logline._protocol, window.Logline.PROTOCOL[Object.keys(window.Logline.PROTOCOL)[i]], 'protocol should be properly setted'); + assert.instanceOf(logger, window.Logline.PROTOCOL[Object.keys(window.Logline.PROTOCOL)[i]], 'log instance should be correctly created'); + window.Logline.PROTOCOL[Object.keys(window.Logline.PROTOCOL)[i]].clean(); + delete window.Logline._protocol; + } } done(); });