From ec224285320d38b3007fb469c10fffbca1294c10 Mon Sep 17 00:00:00 2001 From: PliablePixels Date: Tue, 30 Jun 2015 19:43:10 -0400 Subject: set 50K limit for logs, separated my modifications for angular-circular-navigations --- www/lib/filelogger/dist/filelogger.js | 45 ++++++++++++++++++++++++++++--- www/lib/filelogger/dist/filelogger.min.js | 2 +- 2 files changed, 42 insertions(+), 5 deletions(-) (limited to 'www/lib/filelogger/dist') diff --git a/www/lib/filelogger/dist/filelogger.js b/www/lib/filelogger/dist/filelogger.js index c266f22a..28852fa8 100644 --- a/www/lib/filelogger/dist/filelogger.js +++ b/www/lib/filelogger/dist/filelogger.js @@ -6,11 +6,13 @@ (function(){ /* global angular, console, cordova */ -// install : cordova plugin add org.apache.cordova.file +// install : cordova plugin add cordova-plugin-file angular.module('fileLogger', ['ngCordova.plugins.file']) - .factory('$fileLogger', ['$q', '$window', '$cordovaFile', '$timeout', function ($q, $window, $cordovaFile, $timeout) { + .factory('$fileLogger', ['$q', '$window', '$cordovaFile', '$timeout', + function ($q, $window, $cordovaFile, $timeout) { + 'use strict'; @@ -41,13 +43,24 @@ angular.module('fileLogger', ['ngCordova.plugins.file']) var messages = Array.prototype.slice.call(arguments, 1); var message = [ timestamp, level ]; + var text; for (var i = 0; i < messages.length; i++ ) { if (angular.isArray(messages[i])) { - message.push(JSON.stringify(messages[i])); + text = '[Array]'; + try { + // avoid "TypeError: Converting circular structure to JSON" + text = JSON.stringify(messages[i]); + } catch(e) {} + message.push(text); } else if (angular.isObject(messages[i])) { - message.push(JSON.stringify(messages[i])); + text = '[Object]'; + try { + // avoid "TypeError: Converting circular structure to JSON" + text = JSON.stringify(messages[i]); + } catch(e) {} + message.push(text); } else { message.push(messages[i]); @@ -230,6 +243,29 @@ angular.module('fileLogger', ['ngCordova.plugins.file']) } + function checkFile() { + var q = $q.defer(); + + if (isBrowser()) { + + q.resolve({ + 'name': storageFilename, + 'localURL': 'localStorage://localhost/' + storageFilename, + 'type': 'text/plain', + 'size': ($window.localStorage[storageFilename] ? $window.localStorage[storageFilename].length : 0) + }); + + } else { + + $cordovaFile.checkFile(cordova.file.dataDirectory, storageFilename).then(function(fileEntry) { + fileEntry.file(q.resolve, q.reject); + }, q.reject); + + } + + return q.promise; + } + function debug() { var args = Array.prototype.slice.call(arguments, 0); args.unshift('DEBUG'); @@ -263,6 +299,7 @@ angular.module('fileLogger', ['ngCordova.plugins.file']) getLogfile: getLogfile, deleteLogfile: deleteLogfile, setStorageFilename: setStorageFilename, + checkFile: checkFile, debug: debug, info: info, warn: warn, diff --git a/www/lib/filelogger/dist/filelogger.min.js b/www/lib/filelogger/dist/filelogger.min.js index 366521a2..b0f555a3 100644 --- a/www/lib/filelogger/dist/filelogger.min.js +++ b/www/lib/filelogger/dist/filelogger.min.js @@ -3,4 +3,4 @@ * Copyright 2015 Peter Bakondy https://github.com/pbakondy * See LICENSE in this repository for license information */ -!function(){angular.module("fileLogger",["ngCordova.plugins.file"]).factory("$fileLogger",["$q","$window","$cordovaFile","$timeout",function(e,o,n,r){"use strict";function l(){return!o.cordova&&!o.PhoneGap&&!o.phonegap}function t(e){angular.isString(e)?(e=e.toUpperCase(),-1===h.indexOf(e)&&(e="INFO")):e="INFO";for(var o=(new Date).toJSON(),n=Array.prototype.slice.call(arguments,1),r=[o,e],t=0;t0?(m=e,!0):!1}function g(){var e=Array.prototype.slice.call(arguments,0);e.unshift("DEBUG"),t.apply(void 0,e)}function f(){var e=Array.prototype.slice.call(arguments,0);e.unshift("INFO"),t.apply(void 0,e)}function p(){var e=Array.prototype.slice.call(arguments,0);e.unshift("WARN"),t.apply(void 0,e)}function d(){var e=Array.prototype.slice.call(arguments,0);e.unshift("ERROR"),t.apply(void 0,e)}var v=[],y=!1,h=["DEBUG","INFO","WARN","ERROR"],m="messages.log";return{log:t,getLogfile:c,deleteLogfile:s,setStorageFilename:u,debug:g,info:f,warn:p,error:d}}])}(); +!function(){angular.module("fileLogger",["ngCordova.plugins.file"]).factory("$fileLogger",["$q","$window","$cordovaFile","$timeout",function(e,o,n,r){"use strict";function l(){return!o.cordova&&!o.PhoneGap&&!o.phonegap}function t(e){angular.isString(e)?(e=e.toUpperCase(),-1===m.indexOf(e)&&(e="INFO")):e="INFO";for(var o,n=(new Date).toJSON(),r=Array.prototype.slice.call(arguments,1),t=[n,e],c=0;c0?(F=e,!0):!1}function f(){var r=e.defer();return l()?r.resolve({name:F,localURL:"localStorage://localhost/"+F,type:"text/plain",size:o.localStorage[F]?o.localStorage[F].length:0}):n.checkFile(cordova.file.dataDirectory,F).then(function(e){e.file(r.resolve,r.reject)},r.reject),r.promise}function g(){var e=Array.prototype.slice.call(arguments,0);e.unshift("DEBUG"),t.apply(void 0,e)}function p(){var e=Array.prototype.slice.call(arguments,0);e.unshift("INFO"),t.apply(void 0,e)}function y(){var e=Array.prototype.slice.call(arguments,0);e.unshift("WARN"),t.apply(void 0,e)}function d(){var e=Array.prototype.slice.call(arguments,0);e.unshift("ERROR"),t.apply(void 0,e)}var v=[],h=!1,m=["DEBUG","INFO","WARN","ERROR"],F="messages.log";return{log:t,getLogfile:i,deleteLogfile:s,setStorageFilename:u,checkFile:f,debug:g,info:p,warn:y,error:d}}])}(); -- cgit v1.2.3