Improved logging and added user logging.

This commit is contained in:
Martin Edenhofer 2013-08-03 01:23:01 +02:00
parent 4eaaf7195c
commit 4b80614646
5 changed files with 420 additions and 233 deletions

View file

@ -10,7 +10,7 @@ class App.Controller extends Spine.Controller
super
# generate controllerId
@controllerId = 'controller-' + new Date().getTime() + '-' + Math.floor( Math.random() * 99999 )
@controllerId = 'controller-' + new Date().getTime() + '-' + Math.floor( Math.random() * 999999 )
# apply to release controller on dom remove
@el.on('remove', @releaseController)

View file

@ -43,7 +43,6 @@ class Index extends App.ControllerContent
e.preventDefault()
id = $(e.target).parents('[data-id]').data('id')
type = $(e.target).data('type')
console.log 'ID', id, type
if type is 'uninstall'
httpType = 'DELETE'

View file

@ -36,5 +36,10 @@ class _Singleton
@_log( module, level, args )
_log: ( module, level, args ) ->
if level is 'error'
console.error "App.#{module}(#{level})", args
else if level is 'debug'
console.debug "App.#{module}(#{level})", args
else
console.log "App.#{module}(#{level})", args

View file

@ -0,0 +1,179 @@
class App.Track
_instance = undefined
@init: ->
_instance ?= new _trackSingleton
@log: ( area, level, args ) ->
if _instance == undefined
_instance ?= new _trackSingleton
_instance.log( area, level, args )
@send: ->
if _instance == undefined
_instance ?= new _trackSingleton
_instance.send()
@_all: ->
if _instance == undefined
_instance ?= new _trackSingleton
_instance._all()
class _trackSingleton
constructor: ->
@trackId = 'track-' + new Date().getTime() + '-' + Math.floor( Math.random() * 99999 )
@browser = App.Browser.detection()
@data = []
@url = 'https://portal.znuny.com/api/ui'
@log( 'start', 'notice', {} )
App.Interval.set @send, 60000
# log clicks
$(document).bind(
'click'
(e) =>
w = window.screen.width
h = window.screen.height
aTag = $(e.target)
if !aTag.attr('href')
newTag = $(e.target).parents('a')
if newTag[0]
aTag = newTag
info =
level: 'notice'
href: aTag.attr('href')
title: aTag.attr('title')
text: aTag.text()
clickX: e.pageX
clickY: e.pageY
screenX: w
screenY: h
@log( 'click', 'notice', info )
)
# log ajax calls
$(document).bind( 'ajaxError', ( e, request, settings, exception ) =>
if status
@log(
'ajax.error',
'error',
{
type: settings.type
dataType: settings.dataType
url: settings.url
data: settings.data
status: request.status
responseText: request.responseText
}
)
)
$(document).bind( 'ajaxComplete', ( e, request, settings ) =>
length = @url.length
if settings.url.substr(0,length) isnt @url
@log(
'ajax.send',
'notice',
{
type: settings.type
dataType: settings.dataType
url: settings.url
data: settings.data
status: request.status
# responseText: request.responseText
}
)
)
$(window).bind(
'beforeunload'
=>
@log( 'end', 'notice', {} )
@send()
)
log: ( area, level, args ) ->
info =
time: Math.round( new Date().getTime() / 1000 )
area: area
level: level
location: window.location.href
data: args
@data.push info
send: =>
return if _.isEmpty @data
newData = _.clone( @data )
@data = []
newDataNew = []
for item in newData
try
itemNew = _.clone( item )
JSON.stringify(item)
# add browser info
for item, value of @browser
itemNew[item] = value
newDataNew.push itemNew
catch e
# nothing
App.Com.ajax(
type: 'POST'
url: @url
data: JSON.stringify(
track_id: @trackId
log: newDataNew
)
crossDomain: true
# success: (data, status, xhr) =>
# @data = []
# console.log('done')
error: =>
# queue all data
for item in newDataNew
@data.push item
)
_all: ->
@data
`
window.onerror = function(errorMsg, url, lineNumber) {
console.error(errorMsg + " - in " + url + ", line " + lineNumber);
};
(function() {
var console = window.console
if (!console) return
function intercept(method){
var original = console[method]
console[method] = function(){
//alert('new m' + method)
App.Track.log(
'console.' + method,
method,
arguments
)
// do sneaky stuff
if (original.apply){
// Do this for normal browsers
original.apply(console, arguments)
}
else{
// Do this for IE
var message = Array.prototype.slice.apply(arguments).join(' ')
original(message)
}
}
}
var methods = ['log', 'warn', 'error']
for (var i = 0; i < methods.length; i++)
intercept(methods[i])
}).call(this);
`

View file

@ -1812,6 +1812,10 @@ Translation.create_if_not_exists( :locale => 'de', :source => "Discard your unsa
Translation.create_if_not_exists( :locale => 'de', :source => "Copy to clipboard: Ctrl+C, Enter", :target => "In die Zwischenablage kopieren: Strg+C, Return" )
Translation.create_if_not_exists( :locale => 'de', :source => "Copy to clipboard", :target => "In die Zwischenablage kopieren" )
Translation.create_if_not_exists( :locale => 'de', :source => "Send to clients", :target => "An Clients senden" )
Translation.create_if_not_exists( :locale => 'de', :source => "Feedback about our new Interface", :target => "Feedback übers neue Design!" )
Translation.create_if_not_exists( :locale => 'de', :source => "What ideas do you have?", :target => "Welche Ideen haben Sie?" )
Translation.create_if_not_exists( :locale => 'de', :source => "Attach Screenshot of page", :target => "Screenshot dieser Seite anhängen" )
Translation.create_if_not_exists( :locale => 'de', :source => "Thanks for your Feedback!", :target => "Vielen Dank für Ihre Feedback!" )
#Translation.create_if_not_exists( :locale => 'de', :source => "", :target => "" )
# install all packages in auto_install