Mercurial > eldonilo > blog
changeset 4:f630f4b90564
Remove the old log system and use console.log instead.
author | Emmanuel Gil Peyrot <linkmauve@linkmauve.fr> |
---|---|
date | Mon, 19 Sep 2011 01:51:12 -0700 |
parents | 2e2a2154efbb |
children | 4d7a67349089 |
files | blog.js index.xhtml server.js |
diffstat | 3 files changed, 9 insertions(+), 48 deletions(-) [+] |
line wrap: on
line diff
--- a/blog.js +++ b/blog.js @@ -28,31 +28,9 @@ if (params.jid) if (params.node) node = params.node; -var logs = document.getElementById('log'); -if (params.debug) - logs.parentNode.hidden = false; - var received = {}; var messages = document.getElementById('messages'); -function log(msg, error) { - var p = document.createElementNS(ns.xhtml, 'p'); - p.appendChild(document.createTextNode(msg)); - - if (!error) - p.setAttributeNS(null, 'class', 'error'); - - logs.appendChild(p); -} - -function rawInput(data) { - log('RECV: ' + data, 1); -} - -function rawOutput(data) { - log('SENT: ' + data, 1); -} - var html = function(name, id) { return received[name][id].html; } @@ -174,7 +152,6 @@ var parsePubSubEvent = function(stanza) var onMessages = function(stanza) { conn.addHandler(onMessages, null, 'message', null, null, null); - log('message'); stanza = xml2json(stanza); var e = parsePubSubEvent(stanza); @@ -188,14 +165,13 @@ var onMessages = function(stanza) { } var onInfo = function(stanza) { - log('info'); + console.log('info'); // TODO! /*var query = stanza.getElementsByTagNameNS(ns.info, 'query')[0]; var x = query.getElementsByTagNameNS(ns.data, 'x')[0]; var form = forms.parse(x);*/ } var onSubscribed = function(stanza) { - log('subscribed'); var type = stanza.getAttribute('type'); if (type !== 'result') { messages.innerHTML = 'Error, impossible to retrieve messages.'; @@ -204,20 +180,15 @@ var onSubscribed = function(stanza) { } function onConnect(status) { - if (status == Strophe.Status.CONNECTING) { - log('Strophe is connecting.'); - } else if (status == Strophe.Status.CONNFAIL) { - log('Strophe failed to connect.'); - } else if (status == Strophe.Status.AUTHENTICATING) { - log('Strophe is authenticating.'); + if (status == Strophe.Status.CONNFAIL) { + console.log('Failed to connect.'); } else if (status == Strophe.Status.DISCONNECTING) { - log('Strophe is disconnecting.'); + console.log('Disconnecting.'); } else if (status == Strophe.Status.DISCONNECTED) { - log('Strophe is disconnected.'); + console.log('Disconnected.'); if (re) conn.connect(jid, password, onConnect); } else if (status == Strophe.Status.CONNECTED) { - log('Strophe is connected.'); conn.addHandler(onMessages, null, 'message', null, null, null); conn.send($pres().tree()); conn.pubsub.subscribe(jid, service, node, undefined, onMessages, onSubscribed); @@ -225,14 +196,11 @@ function onConnect(status) { conn.pubsub.items(jid, service, node, onMessages); conn.pubsub.info(jid, service, node, onInfo); } - } else - log('Strophe is '+status+'.'); + } } window.addEventListener('load', function () { conn = new Strophe.Connection(BOSH_SERVICE); - conn.rawInput = rawInput; - conn.rawOutput = rawOutput; conn.connect(jid, password, onConnect); }, false);
--- a/index.xhtml +++ b/index.xhtml @@ -44,11 +44,6 @@ <section id="messages"/> - <section hidden=""> - <h2>logs</h2> - <div id="log"></div> - </section> - <footer/> <script type="application/ecmascript" src="blog.js"/>
--- a/server.js +++ b/server.js @@ -337,11 +337,6 @@ var home = function(res, title, desc, bo } res.write('\n'); - res.write(' <section hidden="">\n'); - res.write(' <h2>logs</h2>\n'); - res.write(' <div id="log"></div>\n'); - res.write(' </section>\n'); - res.write('\n'); if (!footer) res.write(' <footer/>\n'); @@ -357,10 +352,13 @@ var home = function(res, title, desc, bo } res.write(' </body>\n'); + console.log('It works!'); res.end('</html>\n'); }; http.createServer(function(req, res) { + util.log('Connection from ' + (req.headers['x-forwarded-for'] || req.client.remoteAddress) + ' (' + req.headers['user-agent'] + ') to ' + req.method.toLocaleLowerCase() + ' “' + req.url + '” from ' + req.headers['referer'] + '.'); + var re = new RegExp('^' + config.webRoot); req.url = req.url.replace(re, ''); var ext = req.url.substring(req.url.lastIndexOf('.')+1);