]> git.proxmox.com Git - sencha-touch.git/blob - src/src/log/writer/Remote.js
import Sencha Touch 2.4.2 source
[sencha-touch.git] / src / src / log / writer / Remote.js
1 //<feature logger>
2 Ext.define('Ext.log.writer.Remote', {
3 extend: 'Ext.log.writer.Writer',
4
5 requires: [
6 'Ext.Ajax'
7 ],
8
9 config: {
10 batchSendDelay: 100,
11 onFailureRetryDelay: 500,
12 url: ''
13 },
14
15 isSending: false,
16
17 sendingTimer: null,
18
19 constructor: function() {
20 this.queue = [];
21
22 this.send = Ext.Function.bind(this.send, this);
23
24 return this.callParent(arguments);
25 },
26
27 doWrite: function(event) {
28 var queue = this.queue;
29 queue.push(event.message);
30
31 if (!this.isSending && this.sendingTimer === null) {
32 this.sendingTimer = setTimeout(this.send, this.getBatchSendDelay());
33 }
34 },
35
36 send: function() {
37 var queue = this.queue,
38 messages = queue.slice();
39
40 queue.length = 0;
41
42 this.sendingTimer = null;
43
44 if (messages.length > 0) {
45 this.doSend(messages);
46 }
47 },
48
49 doSend: function(messages) {
50 var me = this;
51
52 me.isSending = true;
53
54 Ext.Ajax.request({
55 url: me.getUrl(),
56 method: 'POST',
57 params: {
58 messages: messages.join("\n")
59 },
60 success: function(){
61 me.isSending = false;
62 me.send();
63 },
64 failure: function() {
65 setTimeout(function() {
66 me.doSend(messages);
67 }, me.getOnFailureRetryDelay());
68 },
69 scope: me
70 });
71 }
72 });
73 //</feature>