summaryrefslogtreecommitdiff
path: root/www/lib/filelogger
diff options
context:
space:
mode:
Diffstat (limited to 'www/lib/filelogger')
-rw-r--r--www/lib/filelogger/.bower.json10
-rw-r--r--www/lib/filelogger/README.md85
-rw-r--r--www/lib/filelogger/bower.json2
-rw-r--r--www/lib/filelogger/dist/filelogger.js45
-rw-r--r--www/lib/filelogger/dist/filelogger.min.js2
-rw-r--r--www/lib/filelogger/package.json2
6 files changed, 118 insertions, 28 deletions
diff --git a/www/lib/filelogger/.bower.json b/www/lib/filelogger/.bower.json
index c063767b..2f6314c0 100644
--- a/www/lib/filelogger/.bower.json
+++ b/www/lib/filelogger/.bower.json
@@ -1,6 +1,6 @@
{
"name": "filelogger",
- "version": "1.1.0",
+ "version": "1.2.0",
"homepage": "https://github.com/pbakondy/filelogger",
"authors": [
"Peter Bakondy <pbakondy@gmail.com>"
@@ -27,14 +27,14 @@
"file logger"
],
"license": "MIT",
- "_release": "1.1.0",
+ "_release": "1.2.0",
"_resolution": {
"type": "version",
- "tag": "v1.1.0",
- "commit": "4b5f765cf1737a51cc29bcaeca035d72eb6e8272"
+ "tag": "v1.2.0",
+ "commit": "34d8cc57c16c842ec757cc078e9385286b2ff1c4"
},
"_source": "git://github.com/pbakondy/filelogger.git",
- "_target": "~1.1.0",
+ "_target": "~1.2.0",
"_originalSource": "filelogger",
"_direct": true
}
diff --git a/www/lib/filelogger/README.md b/www/lib/filelogger/README.md
index 1d6c6456..b1e3c20f 100644
--- a/www/lib/filelogger/README.md
+++ b/www/lib/filelogger/README.md
@@ -12,10 +12,16 @@ When you run your application in browser with „ionic serve” the Logger uses
## Dependencies
- [ngCordova](http://ngcordova.com/) ( required version v0.1.14-alpha )
-- [org.apache.cordova.file](https://github.com/apache/cordova-plugin-file)
+- [cordova-plugin-file](https://github.com/apache/cordova-plugin-file)
## Installation
+Add cordova plugin:
+
+```bash
+$ cordova plugin add cordova-plugin-file
+```
+
Install manually, or from bower:
```bash
@@ -35,30 +41,30 @@ Comment: you don't have to use the complete ngCordova package. I suggest to crea
## Usage
-### $fileLogger.log()
+### $fileLogger.log(level, ...message)
General logger method. The first parameter is the log level (debug, info, warn, error). The following parameters are the message parts.
You can put here any javascript type (string, number, boolean, object, array).
In the logfile every item starts with the current UTC timestamp, followed by the log level and the message.
-### $fileLogger.debug()
+### $fileLogger.debug(...message)
Wrapper for $fileLogger.log('debug', ...)
-### $fileLogger.info()
+### $fileLogger.info(...message)
Wrapper for $fileLogger.log('info', ...)
-### $fileLogger.warn()
+### $fileLogger.warn(...message)
Wrapper for $fileLogger.log('warn', ...)
-### $fileLogger.error()
+### $fileLogger.error(...message)
Wrapper for $fileLogger.log('error', ...)
-### $fileLogger.setStorageFilename()
+### $fileLogger.setStorageFilename(filename)
You can set the local filename (default messages.log). It requests one parameter, the filename (type string).
@@ -70,13 +76,49 @@ You can read the whole logfile from the filestore. This method returns a promise
You can delete the logfile from the filestore. This method returns a promise.
+### $fileLogger.checkFile()
+Get storage file data. This method returns an object.
+
+```js
+// response on iOS
+{
+ "name": "myLog.txt",
+ "localURL": "cdvfile://localhost/library-nosync/myLog.txt",
+ "type": null,
+ "lastModified": 1435668606000,
+ "lastModifiedDate": 1435668606000,
+ "size": 450,
+ "start": 0,
+ "end": 450
+}
+
+// response on Android
+{
+ "name": "myLog.txt",
+ "localURL": "cdvfile://localhost/files/myLog.txt",
+ "type": "text/plain",
+ "lastModified": 1435669292000,
+ "lastModifiedDate": 1435669292000,
+ "size": 450,
+ "start": 0,
+ "end": 450
+}
+
+// response in Browser
+{
+ "name": "myLog.txt",
+ "localURL": "localStorage://localhost/myLog.txt",
+ "type": "text/plain",
+ "size": 450
+}
+```
### Example use
```js
angular.module('starter', ['ionic', 'fileLogger'])
- .controller('mainCtrl', ['$scope', '$fileLogger', function($scope, $fileLogger) {
+ .controller('mainCtrl', ['$scope', '$fileLogger', '$timeout', function($scope, $fileLogger, $timeout) {
function testing() {
@@ -96,14 +138,25 @@ angular.module('starter', ['ionic', 'fileLogger'])
$fileLogger.log('info', 'message', 123, [1, 2, 3], { a: 1, b: '2' });
- $fileLogger.getLogfile().then(function(l) {
- console.log('Logfile content');
- console.log(l);
- });
-
- $fileLogger.deleteLogfile().then(function() {
- console.log('Logfile deleted');
- });
+ $timeout(function(){
+ $fileLogger.getLogfile().then(function(l) {
+ console.log('Logfile content');
+ console.log(l);
+ });
+ }, 1000);
+
+ $timeout(function(){
+ $fileLogger.checkFile().then(function(d) {
+ console.log('Logfile data');
+ console.log(JSON.stringify(d));
+ });
+ }, 2000);
+
+ $timeout(function(){
+ $fileLogger.deleteLogfile().then(function() {
+ console.log('Logfile deleted');
+ });
+ }, 3000);
}
diff --git a/www/lib/filelogger/bower.json b/www/lib/filelogger/bower.json
index d6a109bd..fb4b8fe2 100644
--- a/www/lib/filelogger/bower.json
+++ b/www/lib/filelogger/bower.json
@@ -1,6 +1,6 @@
{
"name": "filelogger",
- "version": "1.1.0",
+ "version": "1.2.0",
"homepage": "https://github.com/pbakondy/filelogger",
"authors": [
"Peter Bakondy <pbakondy@gmail.com>"
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;t<n.length;t++)r.push(angular.isArray(n[t])?JSON.stringify(n[t]):angular.isObject(n[t])?JSON.stringify(n[t]):n[t]);if(l()){if(n.unshift(o),angular.isObject(console)&&angular.isFunction(console.log))switch(e){case"DEBUG":angular.isFunction(console.debug)?console.debug.apply(console,n):console.log.apply(console,n);break;case"INFO":angular.isFunction(console.debug)?console.info.apply(console,n):console.log.apply(console,n);break;case"WARN":angular.isFunction(console.debug)?console.warn.apply(console,n):console.log.apply(console,n);break;case"ERROR":angular.isFunction(console.debug)?console.error.apply(console,n):console.log.apply(console,n);break;default:console.log.apply(console,n)}}else console.log(r.join(" "));v.push({message:r.join(" ")+"\n"}),y||a()}function a(){if(!v.length)return void(y=!1);y=!0;var e=v.shift();i(e.message).then(function(){r(function(){a()})},function(){r(function(){a()})})}function i(r){var t=e.defer();return l()?(o.localStorage[m]||(o.localStorage[m]=""),o.localStorage[m]+=r,t.resolve()):n.checkFile(cordova.file.dataDirectory,m).then(function(){n.writeExistingFile(cordova.file.dataDirectory,m,r).then(function(){t.resolve()},function(e){t.reject(e)})},function(){n.writeFile(cordova.file.dataDirectory,m,r,!0).then(function(){t.resolve()},function(e){t.reject(e)})}),t.promise}function c(){var r=e.defer();return l()?r.resolve(o.localStorage[m]):n.readAsText(cordova.file.dataDirectory,m).then(function(e){r.resolve(e)},function(e){r.reject(e)}),r.promise}function s(){var r=e.defer();return l()?(o.localStorage.removeItem(m),r.resolve()):n.removeFile(cordova.file.dataDirectory,m).then(function(e){r.resolve(e)},function(e){r.reject(e)}),r.promise}function u(e){return angular.isString(e)&&e.length>0?(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;c<r.length;c++)if(angular.isArray(r[c])){o="[Array]";try{o=JSON.stringify(r[c])}catch(i){}t.push(o)}else if(angular.isObject(r[c])){o="[Object]";try{o=JSON.stringify(r[c])}catch(i){}t.push(o)}else t.push(r[c]);if(l()){if(r.unshift(n),angular.isObject(console)&&angular.isFunction(console.log))switch(e){case"DEBUG":angular.isFunction(console.debug)?console.debug.apply(console,r):console.log.apply(console,r);break;case"INFO":angular.isFunction(console.debug)?console.info.apply(console,r):console.log.apply(console,r);break;case"WARN":angular.isFunction(console.debug)?console.warn.apply(console,r):console.log.apply(console,r);break;case"ERROR":angular.isFunction(console.debug)?console.error.apply(console,r):console.log.apply(console,r);break;default:console.log.apply(console,r)}}else console.log(t.join(" "));v.push({message:t.join(" ")+"\n"}),h||a()}function a(){if(!v.length)return void(h=!1);h=!0;var e=v.shift();c(e.message).then(function(){r(function(){a()})},function(){r(function(){a()})})}function c(r){var t=e.defer();return l()?(o.localStorage[F]||(o.localStorage[F]=""),o.localStorage[F]+=r,t.resolve()):n.checkFile(cordova.file.dataDirectory,F).then(function(){n.writeExistingFile(cordova.file.dataDirectory,F,r).then(function(){t.resolve()},function(e){t.reject(e)})},function(){n.writeFile(cordova.file.dataDirectory,F,r,!0).then(function(){t.resolve()},function(e){t.reject(e)})}),t.promise}function i(){var r=e.defer();return l()?r.resolve(o.localStorage[F]):n.readAsText(cordova.file.dataDirectory,F).then(function(e){r.resolve(e)},function(e){r.reject(e)}),r.promise}function s(){var r=e.defer();return l()?(o.localStorage.removeItem(F),r.resolve()):n.removeFile(cordova.file.dataDirectory,F).then(function(e){r.resolve(e)},function(e){r.reject(e)}),r.promise}function u(e){return angular.isString(e)&&e.length>0?(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}}])}();
diff --git a/www/lib/filelogger/package.json b/www/lib/filelogger/package.json
index 0f1619a0..165d6598 100644
--- a/www/lib/filelogger/package.json
+++ b/www/lib/filelogger/package.json
@@ -2,7 +2,7 @@
"name": "filelogger",
"private": false,
"main": "dist/filelogger",
- "version": "1.1.0",
+ "version": "1.2.0",
"repository": {
"url": "git://github.com/pbakondy/filelogger.git"
},