Skip to content

Commit 5e184ee

Browse files
author
epriestley
committedJun 20, 2012
Improve debug support for notifications
Summary: Add a `notification.debug` setting that shows debug info in the browser. Also improve some logging/error handling stuff and fix a bug with host names. Test Plan: {F13098} Reviewers: jungejason, btrahan, vrana Reviewed By: btrahan CC: aran Maniphest Tasks: T944 Differential Revision: https://secure.phabricator.com/D2810
1 parent addc2c8 commit 5e184ee

File tree

8 files changed

+62
-129
lines changed

8 files changed

+62
-129
lines changed
 

‎conf/default.conf.php

+3
Original file line numberDiff line numberDiff line change
@@ -209,6 +209,9 @@
209209
// PID file to use.
210210
'notification.pidfile' => '/var/run/aphlict.pid',
211211

212+
// Enable this option to get additional debug output in the browser.
213+
'notification.debug' => false,
214+
212215

213216
// -- Email ----------------------------------------------------------------- //
214217

‎src/__celerity_resource_map__.php

+4-99
Original file line numberDiff line numberDiff line change
@@ -49,20 +49,6 @@
4949
'disk' => '/rsrc/image/custom/example_template.png',
5050
'type' => 'png',
5151
),
52-
'/rsrc/image/facebook/icon/fatcow/speedometer.png' =>
53-
array(
54-
'hash' => '3345a7ba5b3c99dbfa3a922a16756815',
55-
'uri' => '/res/3345a7ba/rsrc/image/facebook/icon/fatcow/speedometer.png',
56-
'disk' => '/rsrc/image/facebook/icon/fatcow/speedometer.png',
57-
'type' => 'png',
58-
),
59-
'/rsrc/image/facebook/icon/sandcastle.png' =>
60-
array(
61-
'hash' => '496a1c2e91ccb8332435491a7bbfa67d',
62-
'uri' => '/res/496a1c2e/rsrc/image/facebook/icon/sandcastle.png',
63-
'disk' => '/rsrc/image/facebook/icon/sandcastle.png',
64-
'type' => 'png',
65-
),
6652
'/rsrc/image/grippy_texture.png' =>
6753
array(
6854
'hash' => 'a8945e12ceeaddd5b491a8d81cfa19c1',
@@ -701,69 +687,6 @@
701687
),
702688
'disk' => '/rsrc/css/application/diffusion/diffusion-source.css',
703689
),
704-
'facebook-differential-core-view-css' =>
705-
array(
706-
'uri' => '/res/6053fa4a/rsrc/css/facebook/application/differential/core.css',
707-
'type' => 'css',
708-
'requires' =>
709-
array(
710-
),
711-
'disk' => '/rsrc/css/facebook/application/differential/core.css',
712-
),
713-
'facebook-example-css' =>
714-
array(
715-
'uri' => '/res/6ba49cd8/rsrc/css/facebook/application/example/example.css',
716-
'type' => 'css',
717-
'requires' =>
718-
array(
719-
),
720-
'disk' => '/rsrc/css/facebook/application/example/example.css',
721-
),
722-
'facebook-example-js' =>
723-
array(
724-
'uri' => '/res/31058d06/rsrc/js/facebook/application/example/example.js',
725-
'type' => 'js',
726-
'requires' =>
727-
array(
728-
),
729-
'disk' => '/rsrc/js/facebook/application/example/example.js',
730-
),
731-
'facebook-releeph-branch' =>
732-
array(
733-
'uri' => '/res/6b7eea98/rsrc/css/facebook/application/releeph/releeph-branch.css',
734-
'type' => 'css',
735-
'requires' =>
736-
array(
737-
),
738-
'disk' => '/rsrc/css/facebook/application/releeph/releeph-branch.css',
739-
),
740-
'facebook-releeph-core' =>
741-
array(
742-
'uri' => '/res/c3027f71/rsrc/css/facebook/application/releeph/releeph-core.css',
743-
'type' => 'css',
744-
'requires' =>
745-
array(
746-
),
747-
'disk' => '/rsrc/css/facebook/application/releeph/releeph-core.css',
748-
),
749-
'facebook-releeph-project' =>
750-
array(
751-
'uri' => '/res/497c0c11/rsrc/css/facebook/application/releeph/releeph-project.css',
752-
'type' => 'css',
753-
'requires' =>
754-
array(
755-
),
756-
'disk' => '/rsrc/css/facebook/application/releeph/releeph-project.css',
757-
),
758-
'facebook-releeph-request-typeahead-css' =>
759-
array(
760-
'uri' => '/res/2f4bab97/rsrc/css/facebook/application/releeph/request-typeahead.css',
761-
'type' => 'css',
762-
'requires' =>
763-
array(
764-
),
765-
'disk' => '/rsrc/css/facebook/application/releeph/request-typeahead.css',
766-
),
767690
'files-css' =>
768691
array(
769692
'uri' => '/res/a265a77d/rsrc/css/application/files/files.css',
@@ -856,7 +779,7 @@
856779
),
857780
'javelin-behavior-aphlict-listen' =>
858781
array(
859-
'uri' => '/res/da96a861/rsrc/js/application/aphlict/behavior-aphlict-listen.js',
782+
'uri' => '/res/c716b386/rsrc/js/application/aphlict/behavior-aphlict-listen.js',
860783
'type' => 'js',
861784
'requires' =>
862785
array(
@@ -866,7 +789,8 @@
866789
3 => 'javelin-request',
867790
4 => 'javelin-uri',
868791
5 => 'javelin-dom',
869-
6 => 'phabricator-notification',
792+
6 => 'javelin-json',
793+
7 => 'phabricator-notification',
870794
),
871795
'disk' => '/rsrc/js/application/aphlict/behavior-aphlict-listen.js',
872796
),
@@ -1239,25 +1163,6 @@
12391163
),
12401164
'disk' => '/rsrc/js/application/core/behavior-error-log.js',
12411165
),
1242-
'javelin-behavior-facebook-releeph-request-typeahead' =>
1243-
array(
1244-
'uri' => '/res/585eff76/rsrc/js/facebook/application/releeph/request-typeahead.js',
1245-
'type' => 'js',
1246-
'requires' =>
1247-
array(
1248-
0 => 'javelin-behavior',
1249-
1 => 'javelin-util',
1250-
2 => 'javelin-dom',
1251-
3 => 'javelin-typeahead',
1252-
4 => 'javelin-tokenizer',
1253-
5 => 'javelin-typeahead-preloaded-source',
1254-
6 => 'javelin-typeahead-ondemand-source',
1255-
7 => 'javelin-dom',
1256-
8 => 'javelin-stratcom',
1257-
9 => 'javelin-util',
1258-
),
1259-
'disk' => '/rsrc/js/facebook/application/releeph/request-typeahead.js',
1260-
),
12611166
'javelin-behavior-fancy-datepicker' =>
12621167
array(
12631168
'uri' => '/res/b2d89e4c/rsrc/js/application/core/behavior-fancy-datepicker.js',
@@ -2292,7 +2197,7 @@
22922197
),
22932198
'phabricator-notification-css' =>
22942199
array(
2295-
'uri' => '/res/7452322a/rsrc/css/aphront/notification.css',
2200+
'uri' => '/res/1ed48691/rsrc/css/aphront/notification.css',
22962201
'type' => 'css',
22972202
'requires' =>
22982203
array(

‎src/docs/userguide/notifications.diviner

+3-2
Original file line numberDiff line numberDiff line change
@@ -76,8 +76,9 @@ You can run `aphlict` in the foreground to get output to your console:
7676

7777
phabricator/ $ ./bin/aphlict --foreground
7878

79-
This may help identify and resolve problems.
79+
You can set `notification.debug` in your configuration to get additional
80+
output in your browser.
8081

8182
The server also generates a log, by default in `/var/log/aphlict.log`. You can
8283
change this location by changing `notification.log` in your configuration. The
83-
log may contain information useful in resolving issues.
84+
log may contain information useful in resolving issues.

‎src/view/page/PhabricatorStandardPageView.php

+5-1
Original file line numberDiff line numberDiff line change
@@ -394,16 +394,20 @@ protected function getBody() {
394394
$client_uri = PhabricatorEnv::getEnvConfig('notification.client-uri');
395395
$client_uri = new PhutilURI($client_uri);
396396
if ($client_uri->getDomain() == 'localhost') {
397-
$this_host = new PhutilURI($this->getRequest()->getHost());
397+
$this_host = $this->getRequest()->getHost();
398+
$this_host = new PhutilURI('http://'.$this_host.'/');
398399
$client_uri->setDomain($this_host->getDomain());
399400
}
400401

402+
$enable_debug = PhabricatorEnv::getEnvConfig('notification.debug');
403+
401404
Javelin::initBehavior(
402405
'aphlict-listen',
403406
array(
404407
'id' => $aphlict_object_id,
405408
'server' => $client_uri->getDomain(),
406409
'port' => $client_uri->getPort(),
410+
'debug' => $enable_debug,
407411
'pageObjects' => array_fill_keys($this->pageObjects, true),
408412
));
409413

‎support/aphlict/client/src/Aphlict.as

-1
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,6 @@ package {
3737
this.remotePort = port;
3838

3939
this.connectToServer();
40-
return;
4140
}
4241

4342

‎support/aphlict/server/aphlict_server.js

+25-16
Original file line numberDiff line numberDiff line change
@@ -51,17 +51,25 @@ var querystring = require('querystring');
5151
var fs = require('fs');
5252

5353
// set up log file
54-
var logfile = fs.createWriteStream(config.log,
55-
{ flags: 'a',
56-
encoding: null,
57-
mode: 0666 });
58-
logfile.write('----- ' + (new Date()).toLocaleString() + ' -----\n');
54+
var logfile = fs.createWriteStream(
55+
config.log,
56+
{
57+
flags: 'a',
58+
encoding: null,
59+
mode: 0666
60+
});
5961

6062
function log(str) {
61-
console.log(str);
62-
logfile.write(str + '\n');
63+
console.log(str);
64+
logfile.write(str + '\n');
6365
}
6466

67+
process.on('uncaughtException', function (err) {
68+
log("\n<<< UNCAUGHT EXCEPTION! >>>\n\n" + err);
69+
process.exit(1);
70+
});
71+
72+
log('----- ' + (new Date()).toLocaleString() + ' -----\n');
6573

6674
function getFlashPolicy() {
6775
return [
@@ -75,17 +83,17 @@ function getFlashPolicy() {
7583
}
7684

7785
net.createServer(function(socket) {
78-
socket.on('data', function() {
79-
socket.write(getFlashPolicy() + '\0');
80-
});
86+
socket.write(getFlashPolicy() + '\0');
87+
socket.end();
88+
89+
log('[' + socket.remoteAddress + '] Sent Flash Policy');
8190

8291
socket.on('error', function (e) {
8392
log('Error in policy server: ' + e);
8493
});
8594
}).listen(843);
8695

8796

88-
8997
function write_json(socket, data) {
9098
var serial = JSON.stringify(data);
9199
var length = Buffer.byteLength(serial, 'utf8');
@@ -118,32 +126,33 @@ function generate_id() {
118126

119127
var send_server = net.createServer(function(socket) {
120128
var client_id = generate_id();
129+
var client_name = '[' + socket.remoteAddress + '] [#' + client_id + '] ';
121130

122131
socket.on('connect', function() {
123132
clients[client_id] = socket;
124133
current_connections++;
125-
log(client_id + ': connected\t\t('
134+
log(client_name + 'connected\t\t('
126135
+ current_connections + ' current connections)');
127136
});
128137

129138
socket.on('close', function() {
130139
delete clients[client_id];
131140
current_connections--;
132-
log(client_id + ': closed\t\t('
141+
log(client_name + 'closed\t\t('
133142
+ current_connections + ' current connections)');
134143
});
135144

136145
socket.on('timeout', function() {
137-
log(client_id + ': timed out!');
146+
log(client_name + 'timed out!');
138147
});
139148

140149
socket.on('end', function() {
141-
log(client_id + ': ended the connection');
150+
log(client_name + 'ended the connection');
142151
// node automatically closes half-open connections
143152
});
144153

145154
socket.on('error', function (e) {
146-
log('Uncaught error in send server: ' + e);
155+
log(cliient_name + 'Uncaught error in send server: ' + e);
147156
});
148157
}).listen(config.port);
149158

‎webroot/rsrc/css/aphront/notification.css

+5
Original file line numberDiff line numberDiff line change
@@ -31,3 +31,8 @@
3131
background: #ffffa0;
3232
border: 1px solid #aaaa60;
3333
}
34+
35+
.jx-notification-debug {
36+
background: #ffa0ff;
37+
border: 1px solid #aa60aa;
38+
}

‎webroot/rsrc/js/application/aphlict/behavior-aphlict-listen.js

+17-10
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
* javelin-request
77
* javelin-uri
88
* javelin-dom
9+
* javelin-json
910
* phabricator-notification
1011
*/
1112

@@ -23,17 +24,23 @@ JX.behavior('aphlict-listen', function(config) {
2324
// Respond to a notification from the Aphlict notification server. We send
2425
// a request to Phabricator to get notification details.
2526
function onaphlictmessage(type, message) {
26-
if (!message) {
27-
return;
27+
if (type == 'receive') {
28+
var request = new JX.Request('/notification/individual/', onnotification)
29+
.addData({key: message.key})
30+
.send();
31+
} else if (__DEV__) {
32+
if (config.debug) {
33+
var details = message
34+
? JX.JSON.stringify(message)
35+
: '';
36+
37+
new JX.Notification()
38+
.setContent('(Aphlict) [' + type + '] ' + details)
39+
.setClassName('jx-notification-debug')
40+
.setDuration(0)
41+
.show();
42+
}
2843
}
29-
30-
if (type != 'receive') {
31-
return;
32-
}
33-
34-
var request = new JX.Request('/notification/individual/', onnotification)
35-
.addData({key: message.key})
36-
.send();
3744
}
3845

3946

0 commit comments

Comments
 (0)
Failed to load comments.