Created
July 20, 2012 08:43
-
-
Save Radagaisus/3149670 to your computer and use it in GitHub Desktop.
Logging
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
| @logs = [] | |
| for msg_type, log_level in ['error', 'warn', 'info', 'debug'] | |
| do (msg_type, log_level) -> | |
| @[msg_type] = (msg = '', data = {}) -> | |
| # Add to logs | |
| @logs.push | |
| type: msg_type | |
| msg: msg | |
| data: data | |
| # Output to console | |
| if @conf.debug isnt false and @conf.debug >= log_level | |
| if not $.browser.msie | |
| console[msg_type] msg, data | |
| else | |
| # Use a console.log wrapper | |
| # https://github.com/cpatik/console.log-wrapper | |
| # Server logging | |
| # Thanks xing - http://devblog.xing.com/frontend/how-to-log-javascript-errors/ | |
| if log_level is 0 | |
| log = new Image() | |
| log.src = "/js/log/errors?description=#{escape(msg)}" + | |
| "&url=#{escape(document.location.href)}&user_agent=#{escape(navigator.userAgent)}" | |
| delete log | |
| # Trigger events | |
| @trigger "app:#{msg_type}", {message: msg, data: data} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment