Last active
October 2, 2015 09:37
-
-
Save pinalbhatt/3175f18b6d8024110e69 to your computer and use it in GitHub Desktop.
AngularJS Logger Factory
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
*/ | |
(function () { | |
'use strict'; | |
angular.module('PBDesk.Logger', ['PBDesk.Toastr']) | |
.factory('Logger', logger); | |
logger.$inject = ['$log', 'Toastr']; | |
function logger($log, toastr) { | |
var service = { | |
showToasts: true, | |
error: error, | |
info: info, | |
success: success, | |
warning: warning, | |
// straight to console; bypass toastr | |
log: $log.log | |
}; | |
return service; | |
///////////////////// | |
function error(message, data, title) { | |
$log.error('Error: ' + message, data); | |
if (service.showToasts) { | |
toastr.error(message, title); | |
} | |
} | |
function info(message, data, title) { | |
$log.info('Info: ' + message, data); | |
if (service.showToasts) { | |
toastr.info(message, title); | |
} | |
} | |
function success(message, data, title) { | |
$log.info('Success: ' + message, data); | |
if (service.showToasts) { | |
toastr.success(message, title); | |
} | |
} | |
function warning(message, data, title) { | |
$log.warn('Warning: ' + message, data); | |
if (service.showToasts) { | |
toastr.warning(message, title); | |
} | |
} | |
} | |
})(); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(function () { | |
'use strict'; | |
angular | |
.module('PBDesk.Logger') | |
.controller('LoggerTestController', LoggerTestController); | |
LoggerTestController.$inject = ['$scope', 'Logger']; | |
function LoggerTestController($scope, Logger) { | |
$scope.title = 'Toastr'; | |
$scope.pop = function () { | |
Logger.info('msg', 'ttl'); | |
} | |
} | |
})(); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
*/ | |
(function () { | |
'use strict'; | |
angular.module('PBDesk.Logger', []) | |
.factory('Logger', logger); | |
logger.$inject = ['$log']; | |
function logger($log) { | |
var service = { | |
showToasts: false, | |
error: error, | |
info: info, | |
success: success, | |
warning: warning, | |
// straight to console; bypass toastr | |
log: $log.log | |
}; | |
return service; | |
///////////////////// | |
function error(message, data, title) { | |
$log.error('Error: ' + message, data); | |
} | |
function info(message, data, title) { | |
$log.info('Info: ' + message, data); | |
} | |
function success(message, data, title) { | |
$log.info('Success: ' + message, data); | |
} | |
function warning(message, data, title) { | |
$log.warn('Warning: ' + message, data); | |
} | |
} | |
})(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment