Skip to content

Commit

Permalink
logcat improvements, helper wrapper functions
Browse files Browse the repository at this point in the history
  • Loading branch information
pbakondy committed Feb 27, 2015
1 parent 98a8daa commit 6a264af
Show file tree
Hide file tree
Showing 6 changed files with 182 additions and 71 deletions.
21 changes: 21 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,22 @@ 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()

Wrapper for $fileLogger.log('debug', ...)

### $fileLogger.info()

Wrapper for $fileLogger.log('info', ...)

### $fileLogger.warn()

Wrapper for $fileLogger.log('warn', ...)

### $fileLogger.error()

Wrapper for $fileLogger.log('error', ...)

### $fileLogger.setStorageFilename()

You can set the local filename (default messages.log). It requests one parameter, the filename (type string).
Expand Down Expand Up @@ -69,6 +85,11 @@ app.controller('mainCtrl', ['$scope', '$fileLogger', function($scope, $fileLogge
$fileLogger.log('warn', 'message');
$fileLogger.log('error', 'message');

$fileLogger.debug('message');
$fileLogger.info('message');
$fileLogger.warn('message');
$fileLogger.error('message');

$fileLogger.log('error', 'error message', { code: 1, meaning: 'general' });

$fileLogger.log('info', 'message', 123, [1, 2, 3], { a: 1, b: '2' });
Expand Down
2 changes: 1 addition & 1 deletion bower.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "filelogger",
"version": "1.0.3",
"version": "1.0.4",
"homepage": "https://github.com/pbakondy/filelogger",
"authors": [
"Peter Bakondy <[email protected]>"
Expand Down
113 changes: 79 additions & 34 deletions dist/filelogger.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,11 @@ angular.module('fileLogger', ['ngCordova'])
var storageFilename = 'messages.log';


function isBrowser() {
return (!$window.cordova && !$window.PhoneGap && !$window.phonegap);
}


function log(level) {
if (angular.isString(level)) {
level = level.toUpperCase();
Expand Down Expand Up @@ -49,41 +54,49 @@ angular.module('fileLogger', ['ngCordova'])
}
}

messages.unshift(timestamp);

if (angular.isObject(console) && angular.isFunction(console.log)) {
switch (level) {
case 'DEBUG':
if (angular.isFunction(console.debug)) {
console.debug.apply(console, messages);
} else {
console.log.apply(console, messages);
}
break;
case 'INFO':
if (angular.isFunction(console.debug)) {
console.info.apply(console, messages);
} else {
console.log.apply(console, messages);
}
break;
case 'WARN':
if (angular.isFunction(console.debug)) {
console.warn.apply(console, messages);
} else {
if (isBrowser()) {
// log to browser console

messages.unshift(timestamp);

if (angular.isObject(console) && angular.isFunction(console.log)) {
switch (level) {
case 'DEBUG':
if (angular.isFunction(console.debug)) {
console.debug.apply(console, messages);
} else {
console.log.apply(console, messages);
}
break;
case 'INFO':
if (angular.isFunction(console.debug)) {
console.info.apply(console, messages);
} else {
console.log.apply(console, messages);
}
break;
case 'WARN':
if (angular.isFunction(console.debug)) {
console.warn.apply(console, messages);
} else {
console.log.apply(console, messages);
}
break;
case 'ERROR':
if (angular.isFunction(console.debug)) {
console.error.apply(console, messages);
} else {
console.log.apply(console, messages);
}
break;
default:
console.log.apply(console, messages);
}
break;
case 'ERROR':
if (angular.isFunction(console.debug)) {
console.error.apply(console, messages);
} else {
console.log.apply(console, messages);
}
break;
default:
console.log.apply(console, messages);
}
}

} else {
// log to logcat
console.log(message.join(' '));
}

queue.push({ message: message.join(' ') + '\n' });
Expand Down Expand Up @@ -201,11 +214,43 @@ angular.module('fileLogger', ['ngCordova'])
}


function debug() {
var args = Array.prototype.slice.call(arguments, 0);
args.unshift('DEBUG');
log.apply(undefined, args);
}


function info() {
var args = Array.prototype.slice.call(arguments, 0);
args.unshift('INFO');
log.apply(undefined, args);
}


function warn() {
var args = Array.prototype.slice.call(arguments, 0);
args.unshift('WARN');
log.apply(undefined, args);
}


function error() {
var args = Array.prototype.slice.call(arguments, 0);
args.unshift('ERROR');
log.apply(undefined, args);
}


return {
log: log,
getLogfile: getLogfile,
deleteLogfile: deleteLogfile,
setStorageFilename: setStorageFilename
setStorageFilename: setStorageFilename,
debug: debug,
info: info,
warn: warn,
error: error
};

}]);
Expand Down
2 changes: 1 addition & 1 deletion dist/filelogger.min.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"name": "filelogger",
"private": false,
"main": "dist/filelogger",
"version": "1.0.3",
"version": "1.0.4",
"repository": {
"url": "git://github.com/pbakondy/filelogger.git"
},
Expand Down
113 changes: 79 additions & 34 deletions src/filelogger.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,11 @@ angular.module('fileLogger', ['ngCordova'])
var storageFilename = 'messages.log';


function isBrowser() {
return (!$window.cordova && !$window.PhoneGap && !$window.phonegap);
}


function log(level) {
if (angular.isString(level)) {
level = level.toUpperCase();
Expand Down Expand Up @@ -43,41 +48,49 @@ angular.module('fileLogger', ['ngCordova'])
}
}

messages.unshift(timestamp);

if (angular.isObject(console) && angular.isFunction(console.log)) {
switch (level) {
case 'DEBUG':
if (angular.isFunction(console.debug)) {
console.debug.apply(console, messages);
} else {
console.log.apply(console, messages);
}
break;
case 'INFO':
if (angular.isFunction(console.debug)) {
console.info.apply(console, messages);
} else {
console.log.apply(console, messages);
}
break;
case 'WARN':
if (angular.isFunction(console.debug)) {
console.warn.apply(console, messages);
} else {
if (isBrowser()) {
// log to browser console

messages.unshift(timestamp);

if (angular.isObject(console) && angular.isFunction(console.log)) {
switch (level) {
case 'DEBUG':
if (angular.isFunction(console.debug)) {
console.debug.apply(console, messages);
} else {
console.log.apply(console, messages);
}
break;
case 'INFO':
if (angular.isFunction(console.debug)) {
console.info.apply(console, messages);
} else {
console.log.apply(console, messages);
}
break;
case 'WARN':
if (angular.isFunction(console.debug)) {
console.warn.apply(console, messages);
} else {
console.log.apply(console, messages);
}
break;
case 'ERROR':
if (angular.isFunction(console.debug)) {
console.error.apply(console, messages);
} else {
console.log.apply(console, messages);
}
break;
default:
console.log.apply(console, messages);
}
break;
case 'ERROR':
if (angular.isFunction(console.debug)) {
console.error.apply(console, messages);
} else {
console.log.apply(console, messages);
}
break;
default:
console.log.apply(console, messages);
}
}

} else {
// log to logcat
console.log(message.join(' '));
}

queue.push({ message: message.join(' ') + '\n' });
Expand Down Expand Up @@ -195,11 +208,43 @@ angular.module('fileLogger', ['ngCordova'])
}


function debug() {
var args = Array.prototype.slice.call(arguments, 0);
args.unshift('DEBUG');
log.apply(undefined, args);
}


function info() {
var args = Array.prototype.slice.call(arguments, 0);
args.unshift('INFO');
log.apply(undefined, args);
}


function warn() {
var args = Array.prototype.slice.call(arguments, 0);
args.unshift('WARN');
log.apply(undefined, args);
}


function error() {
var args = Array.prototype.slice.call(arguments, 0);
args.unshift('ERROR');
log.apply(undefined, args);
}


return {
log: log,
getLogfile: getLogfile,
deleteLogfile: deleteLogfile,
setStorageFilename: setStorageFilename
setStorageFilename: setStorageFilename,
debug: debug,
info: info,
warn: warn,
error: error
};

}]);

0 comments on commit 6a264af

Please sign in to comment.