by
184 7
2
4
208k
2
Top 1% !
Popular
Pearl of Wisdom
Specified
Popularity: 7605th place
This snippet is Public
No tags for this snippet yet.
LanguageCoffeeScript
LicenseMIT_X11
SourceGitHub
SourceMyGists

AngularJS / NodeWebkit logger service.

AngularJS / NodeWebkit logger service.: 
logger.coffee
Copy Embed Code
<iframe id="embedFrame" style="width:600px; height:300px;"
src="https://www.snip2code.com/Embed/151114/AngularJS---NodeWebkit-logger-service-?startLine=0"></iframe>
Click on the embed code to copy it into your clipboard Width Height
Leave empty to retrieve all the content Start End
'use strict'; angular.module('vc.messages') .factory "logger", ['$log', 'NwService', ($log, NwService) -> log4js = require('log4js') log4js.configure { appenders: [ { type: 'console' layout: { type: 'pattern' pattern: "%m%n" } category: 'console' }, { type: 'file' absolute: true filename: NwService.dataPath() + '/app.log' category: 'file' maxLogSize: 1024*1024 numBackups: 3 layout: { type: 'pattern' pattern: "[%d %r] [%p] - %m%n" } }, ] levels: { "[all]": "INFO", "console": NwService.isProduction() ? "OFF" : "DEBUG", "file": "ERROR" } } consoleLogger = log4js.getLogger('console') ['Trace','Debug','Info','Warn','Error','Fatal'].forEach (levelString) -> level = log4js.levels.toLevel(levelString) consoleLogger[levelString.toLowerCase()] = () -> return false unless consoleLogger.isLevelEnabled(level) args = Array.prototype.slice.call(arguments) switch levelString when 'Info', 'Warn' $log[levelString.toLowerCase()](args) else args.unshift(level) consoleLogger.log.apply(consoleLogger, args) return { file: log4js.getLogger('file') console: consoleLogger } ]
If you want to be updated about similar snippets, Sign in and follow our Channels

blog comments powered by Disqus